X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Fimpl%2FRpcProviderRegistryImpl.java;h=6a17007d22779c81dd9a55d592fc80da73323f6f;hp=bc862886d7abc548efc680d8f029c89a6d98f8d6;hb=178d185be418a9ed491201bd6a0e4d98efa9d820;hpb=557ff60701d97fbff95c345387c0a6db79274e1b diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProviderRegistryImpl.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProviderRegistryImpl.java index bc862886d7..6a17007d22 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProviderRegistryImpl.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProviderRegistryImpl.java @@ -27,6 +27,8 @@ import org.opendaylight.yangtools.concepts.util.ListenerRegistry; import org.opendaylight.yangtools.yang.binding.BaseIdentity; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.RpcService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static com.google.common.base.Preconditions.*; @@ -41,6 +43,19 @@ public class RpcProviderRegistryImpl implements // private final ListenerRegistry>> routeChangeListeners = ListenerRegistry .create(); + private final static Logger LOG = LoggerFactory.getLogger(RpcProviderRegistryImpl.class); + + private final String name; + + public String getName() { + return name; + } + + public RpcProviderRegistryImpl(String name) { + super(); + this.name = name; + } + @Override public final RoutedRpcRegistration addRoutedRpcImplementation(Class type, T implementation) throws IllegalStateException { @@ -50,6 +65,7 @@ public class RpcProviderRegistryImpl implements // @Override public final RpcRegistration addRpcImplementation(Class type, T implementation) throws IllegalStateException { + @SuppressWarnings("unchecked") RpcRouter potentialRouter = (RpcRouter) rpcRouters.get(type); if (potentialRouter != null) { checkState(potentialRouter.getDefaultService() == null, @@ -59,20 +75,35 @@ public class RpcProviderRegistryImpl implements // T publicProxy = getRpcService(type); RpcService currentDelegate = RuntimeCodeHelper.getDelegate(publicProxy); checkState(currentDelegate == null, "Rpc service is already registered"); + LOG.debug("Registering {} as global implementation of {} in {}",implementation,type.getSimpleName(),this); RuntimeCodeHelper.setDelegate(publicProxy, implementation); return new RpcProxyRegistration(type, implementation, this); } + @SuppressWarnings("unchecked") @Override public final T getRpcService(Class type) { - RpcService potentialProxy = publicProxies.get(type); + @SuppressWarnings("unchecked") + T potentialProxy = (T) publicProxies.get(type); if (potentialProxy != null) { - return (T) potentialProxy; + return potentialProxy; + } + synchronized(this) { + /** + * Potential proxy could be instantiated by other thread while we were + * waiting for the lock. + */ + + potentialProxy = (T) publicProxies.get(type); + if (potentialProxy != null) { + return (T) potentialProxy; + } + T proxy = rpcFactory.getDirectProxyFor(type); + LOG.debug("Created {} as public proxy for {} in {}",proxy,type.getSimpleName(),this); + publicProxies.put(type, proxy); + return proxy; } - T proxy = rpcFactory.getDirectProxyFor(type); - publicProxies.put(type, proxy); - return proxy; } private RpcRouter getRpcRouter(Class type) { @@ -80,13 +111,25 @@ public class RpcProviderRegistryImpl implements // if (potentialRouter != null) { return (RpcRouter) potentialRouter; } - RpcRouter router = rpcFactory.getRouterFor(type); - router.registerRouteChangeListener(new RouteChangeForwarder(type)); - RuntimeCodeHelper.setDelegate(getRpcService(type), router.getInvocationProxy()); - rpcRouters.put(type, router); - return router; + synchronized(this) { + /** + * Potential Router could be instantiated by other thread while we were + * waiting for the lock. + */ + potentialRouter = rpcRouters.get(type); + if (potentialRouter != null) { + return (RpcRouter) potentialRouter; + } + RpcRouter router = rpcFactory.getRouterFor(type,name); + router.registerRouteChangeListener(new RouteChangeForwarder(type)); + LOG.debug("Registering router {} as global implementation of {} in {}",router,type.getSimpleName(),this); + RuntimeCodeHelper.setDelegate(getRpcService(type), router.getInvocationProxy()); + rpcRouters.put(type, router); + return router; + } } + @Override public >> ListenerRegistration registerRouteChangeListener( L listener) { return (ListenerRegistration) routeChangeListeners.register(listener);