Skip to content

Commit

Permalink
Threadsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
olafleur committed Apr 18, 2014
1 parent edd3d52 commit a0d2634
Showing 1 changed file with 10 additions and 10 deletions.
Expand Up @@ -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;
Expand All @@ -38,11 +37,12 @@
@Singleton
public class LazyActionHandlerValidatorRegistryImpl implements
LazyActionHandlerValidatorRegistry {
private final Map<Class<? extends Action<?>>, ActionHandlerValidatorClass<? extends Action<?>,
? extends Result>> actionHandlerValidatorClasses;
private final Map<Class<? extends Action<?>>, ActionHandlerValidatorInstance> actionHandlerValidatorInstances;
private final ConcurrentHashMap<Class<? extends Action<?>>, ActionHandlerValidatorClass<? extends Action<?>,
? extends Result>> actionHandlerValidatorClasses;
private final ConcurrentHashMap<Class<? extends Action<?>>,
ActionHandlerValidatorInstance> actionHandlerValidatorInstances;
private final Injector injector;
private final Map<Class<? extends ActionValidator>, ActionValidator> validators;
private final ConcurrentHashMap<Class<? extends ActionValidator>, ActionValidator> validators;

@Inject
LazyActionHandlerValidatorRegistryImpl(Injector injector) {
Expand All @@ -58,7 +58,7 @@ public class LazyActionHandlerValidatorRegistryImpl implements
public <A extends Action<R>, R extends Result> void addActionHandlerValidatorClass(
Class<A> actionClass,
ActionHandlerValidatorClass<A, R> actionHandlerValidatorClass) {
actionHandlerValidatorClasses.put(actionClass, actionHandlerValidatorClass);
actionHandlerValidatorClasses.putIfAbsent(actionClass, actionHandlerValidatorClass);
}

@Override
Expand All @@ -81,14 +81,14 @@ public <A extends Action<R>, R extends Result> ActionHandlerValidatorInstance fi
if (actionHandlerValidatorClass != null) {
actionHandlerValidatorInstance = createInstance(actionHandlerValidatorClass);
if (actionHandlerValidatorInstance != null) {
actionHandlerValidatorInstances.put(
actionHandlerValidatorInstances.putIfAbsent(
(Class<? extends Action<?>>) action.getClass(),
actionHandlerValidatorInstance);
}
}
}

return (ActionHandlerValidatorInstance) actionHandlerValidatorInstance;
return actionHandlerValidatorInstance;
}

@Override
Expand Down Expand Up @@ -129,7 +129,7 @@ private boolean containValidator(ActionValidator actionValidator) {
private ActionHandlerValidatorInstance createInstance(
ActionHandlerValidatorClass<? extends Action<?>, ? extends Result> actionHandlerValidatorClass) {

ActionHandlerValidatorInstance actionHandlerValidatorInstance = null;
ActionHandlerValidatorInstance actionHandlerValidatorInstance;
ActionValidator actionValidator = findActionValidator(actionHandlerValidatorClass.getActionValidatorClass());

if (actionValidator == null) {
Expand All @@ -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,
Expand Down

0 comments on commit a0d2634

Please sign in to comment.