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/28 00:06:27 UTC
[jira] [Updated] (REEF-871) Replace put with putIfAbsent in
HandlerContainer
[ https://issues.apache.org/jira/browse/REEF-871?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Dongjoon Hyun updated REEF-871:
-------------------------------
Summary: Replace put with putIfAbsent in HandlerContainer (was: Simplify registerHandler logic in HandlerContainer)
> Replace put with putIfAbsent 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)