From a0d2634a1511a85242eb6c90fdd444fc5e6a0ff0 Mon Sep 17 00:00:00 2001 From: Olivier Lafleur Date: Thu, 17 Apr 2014 21:41:34 -0400 Subject: [PATCH] Threadsafe --- ...azyActionHandlerValidatorRegistryImpl.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gwtp-core/gwtp-dispatch-rpc-server-guice/src/main/java/com/gwtplatform/dispatch/rpc/server/guice/actionhandlervalidator/LazyActionHandlerValidatorRegistryImpl.java b/gwtp-core/gwtp-dispatch-rpc-server-guice/src/main/java/com/gwtplatform/dispatch/rpc/server/guice/actionhandlervalidator/LazyActionHandlerValidatorRegistryImpl.java index 5e4c6aa85e..909a4d01c4 100644 --- a/gwtp-core/gwtp-dispatch-rpc-server-guice/src/main/java/com/gwtplatform/dispatch/rpc/server/guice/actionhandlervalidator/LazyActionHandlerValidatorRegistryImpl.java +++ b/gwtp-core/gwtp-dispatch-rpc-server-guice/src/main/java/com/gwtplatform/dispatch/rpc/server/guice/actionhandlervalidator/LazyActionHandlerValidatorRegistryImpl.java @@ -16,7 +16,6 @@ package com.gwtplatform.dispatch.rpc.server.guice.actionhandlervalidator; -import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import javax.inject.Inject; @@ -38,11 +37,12 @@ @Singleton public class LazyActionHandlerValidatorRegistryImpl implements LazyActionHandlerValidatorRegistry { - private final Map>, ActionHandlerValidatorClass, - ? extends Result>> actionHandlerValidatorClasses; - private final Map>, ActionHandlerValidatorInstance> actionHandlerValidatorInstances; + private final ConcurrentHashMap>, ActionHandlerValidatorClass, + ? extends Result>> actionHandlerValidatorClasses; + private final ConcurrentHashMap>, + ActionHandlerValidatorInstance> actionHandlerValidatorInstances; private final Injector injector; - private final Map, ActionValidator> validators; + private final ConcurrentHashMap, ActionValidator> validators; @Inject LazyActionHandlerValidatorRegistryImpl(Injector injector) { @@ -58,7 +58,7 @@ public class LazyActionHandlerValidatorRegistryImpl implements public , R extends Result> void addActionHandlerValidatorClass( Class actionClass, ActionHandlerValidatorClass actionHandlerValidatorClass) { - actionHandlerValidatorClasses.put(actionClass, actionHandlerValidatorClass); + actionHandlerValidatorClasses.putIfAbsent(actionClass, actionHandlerValidatorClass); } @Override @@ -81,14 +81,14 @@ public , R extends Result> ActionHandlerValidatorInstance fi if (actionHandlerValidatorClass != null) { actionHandlerValidatorInstance = createInstance(actionHandlerValidatorClass); if (actionHandlerValidatorInstance != null) { - actionHandlerValidatorInstances.put( + actionHandlerValidatorInstances.putIfAbsent( (Class>) action.getClass(), actionHandlerValidatorInstance); } } } - return (ActionHandlerValidatorInstance) actionHandlerValidatorInstance; + return actionHandlerValidatorInstance; } @Override @@ -129,7 +129,7 @@ private boolean containValidator(ActionValidator actionValidator) { private ActionHandlerValidatorInstance createInstance( ActionHandlerValidatorClass, ? extends Result> actionHandlerValidatorClass) { - ActionHandlerValidatorInstance actionHandlerValidatorInstance = null; + ActionHandlerValidatorInstance actionHandlerValidatorInstance; ActionValidator actionValidator = findActionValidator(actionHandlerValidatorClass.getActionValidatorClass()); if (actionValidator == null) { @@ -139,7 +139,7 @@ private ActionHandlerValidatorInstance createInstance( actionValidator, injector.getInstance(actionHandlerValidatorClass.getActionHandlerClass())); - validators.put(actionValidator.getClass(), actionValidator); + validators.putIfAbsent(actionValidator.getClass(), actionValidator); } else { actionHandlerValidatorInstance = new ActionHandlerValidatorInstance( actionValidator,