From 223b4e47ee742252f0bffcc359f116e0bf2bed9a Mon Sep 17 00:00:00 2001 From: Carpenter Lee Date: Thu, 29 Nov 2018 16:02:27 +0800 Subject: [PATCH] Add verbose log when SimpleHttpCommandCenter chooses port fail --- .../transport/command/SimpleHttpCommandCenter.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/SimpleHttpCommandCenter.java b/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/SimpleHttpCommandCenter.java index 193d844b..76a361aa 100755 --- a/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/SimpleHttpCommandCenter.java +++ b/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/SimpleHttpCommandCenter.java @@ -19,11 +19,11 @@ import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketException; -import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.RejectedExecutionException; @@ -53,7 +53,7 @@ public class SimpleHttpCommandCenter implements CommandCenter { private static final int DEFAULT_PORT = 8719; @SuppressWarnings("rawtypes") - private static final Map handlerMap = new HashMap(); + private static final Map handlerMap = new ConcurrentHashMap(); private ExecutorService executor = Executors.newSingleThreadExecutor( new NamedThreadFactory("sentinel-command-center-executor")); @@ -105,12 +105,14 @@ public class SimpleHttpCommandCenter implements CommandCenter { executor.submit(new ServerThread(serverSocket)); success = true; port = serverSocket.getLocalPort(); + } else { + CommandCenterLog.info("[CommandCenter] chooses port fail, http command center will not work"); } if (!success) { port = PORT_UNINITIALIZED; } - + TransportConfig.setRuntimePort(port); executor.shutdown(); } @@ -119,11 +121,11 @@ public class SimpleHttpCommandCenter implements CommandCenter { new Thread(serverInitTask).start(); } - + /** * Get a server socket from an available port from a base port.
* Increasing on port number will occur when the port has already been used. - * + * * @param basePort base port to start * @return new socket with available port */ @@ -135,7 +137,7 @@ public class SimpleHttpCommandCenter implements CommandCenter { server.setReuseAddress(true); return server; } catch (IOException e) { - tryCount ++; + tryCount++; try { TimeUnit.MILLISECONDS.sleep(30); } catch (InterruptedException e1) {