You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@reef.apache.org by "Dongjoon Hyun (JIRA)" <ji...@apache.org> on 2015/10/24 22:41:27 UTC

[jira] [Created] (REEF-871) Simplify registerHandler logic in HandlerContainer

Dongjoon Hyun created REEF-871:
----------------------------------

             Summary: Simplify registerHandler logic in HandlerContainer
                 Key: REEF-871
                 URL: https://issues.apache.org/jira/browse/REEF-871
             Project: REEF
          Issue Type: Improvement
          Components: Wake
            Reporter: Dongjoon Hyun
            Assignee: Dongjoon Hyun
            Priority: Trivial


`HandlerContainer` maintains two ConcurrentHashMap in a redundant way. One is using 'putIfAbsent' and 'replace', and the other is using 'put' and 'replace'. Logically, `HandlerContainer` overwrites the existing mappings with the same key. We can simplify them into one statement to improve readability and maintainability.

*tupleToHandlerMap*
{code}
-
-    final EventHandler<? extends T> prevHandler =
-        this.tupleToHandlerMap.putIfAbsent(tuple, theHandler);
-
-    if (prevHandler != null) {
-      this.tupleToHandlerMap.replace(tuple, theHandler);
-    }
-
+    this.tupleToHandlerMap.put(tuple, theHandler);
{code}

*msgTypeHandlerMap*
{code}
-
-    final EventHandler<RemoteMessage<? extends T>> prevHandler =
-        this.msgTypeToHandlerMap.put(messageType, theHandler);
-
-    if (prevHandler != null) {
-      this.msgTypeToHandlerMap.replace(messageType, theHandler);
-    }
-
+    this.msgTypeToHandlerMap.put(messageType, theHandler);
{code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)