Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LazyActionHandlerValidatorRegistryImpl should be threadsafe #475

Merged
merged 1 commit into from
Apr 22, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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