srdo commented on a change in pull request #2996: STORM-3376: Set Server 
callback before opening Netty socket, so we do…
URL: https://github.com/apache/storm/pull/2996#discussion_r281017418
 
 

 ##########
 File path: storm-client/src/jvm/org/apache/storm/messaging/local/Context.java
 ##########
 @@ -37,62 +38,53 @@
 
 public class Context implements IContext {
     private static final Logger LOG = LoggerFactory.getLogger(Context.class);
-    private static ConcurrentHashMap<String, LocalServer> _registry = new 
ConcurrentHashMap<>();
-
-    private static LocalServer getLocalServer(String nodeId, int port) {
-        String key = nodeId + "-" + port;
-        LocalServer ret = _registry.get(key);
-        if (ret == null) {
-            ret = new LocalServer(port);
-            LocalServer tmp = _registry.putIfAbsent(key, ret);
-            if (tmp != null) {
-                ret = tmp;
-            }
+    private final ConcurrentHashMap<String, LocalServer> _registry = new 
ConcurrentHashMap<>();
+
+    private static String getNodeKey(String nodeId, int port) {
+        return nodeId + "-" + port;
+    }
+    
+    private LocalServer createLocalServer(String nodeId, int port, 
IConnectionCallback cb) {
+        String key = getNodeKey(nodeId, port);
+        LocalServer ret = new LocalServer(port, cb);
 
 Review comment:
   Yes. The previous method was used on both the client and server sides to get 
access to the created server. A server would be created both if a server 
registered a port, and if a client requested a port. This required thread 
safety for the reason you mention, so you don't end up with the client and 
server side seeing different LocalServer instances.
   
   This method is only called by the server side, and the client accesses the 
generated server via `_registry.get`. Since we don't have multiple servers 
binding to the same node/port combination, we don't need to worry about 
overlapping calls to this method. Clients won't create servers anymore, but 
instead just buffer messages until the server gets bound by the server side 
thread.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to