import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
+import org.opendaylight.controller.sal.binding.api.rpc.RpcRouter;
import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeGenerator;
import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper;
import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
-import org.opendaylight.controller.sal.binding.spi.RpcContextIdentifier;
-import org.opendaylight.controller.sal.binding.spi.RpcRouter;
+import org.opendaylight.controller.sal.binding.api.rpc.RpcContextIdentifier;
import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
import org.opendaylight.yangtools.concepts.Identifiable;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
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.*;
private final ListenerRegistry<RouteChangeListener<RpcContextIdentifier, InstanceIdentifier<?>>> 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 <T extends RpcService> RoutedRpcRegistration<T> addRoutedRpcImplementation(Class<T> type,
T implementation) throws IllegalStateException {
@Override
public final <T extends RpcService> RpcRegistration<T> addRpcImplementation(Class<T> type, T implementation)
throws IllegalStateException {
+ @SuppressWarnings("unchecked")
RpcRouter<T> potentialRouter = (RpcRouter<T>) rpcRouters.get(type);
if (potentialRouter != null) {
checkState(potentialRouter.getDefaultService() == null,
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<T>(type, implementation, this);
}
+ @SuppressWarnings("unchecked")
@Override
public final <T extends RpcService> T getRpcService(Class<T> 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 <T extends RpcService> RpcRouter<T> getRpcRouter(Class<T> type) {
if (potentialRouter != null) {
return (RpcRouter<T>) potentialRouter;
}
- RpcRouter<T> 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<T>) potentialRouter;
+ }
+ RpcRouter<T> 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 <L extends RouteChangeListener<RpcContextIdentifier, InstanceIdentifier<?>>> ListenerRegistration<L> registerRouteChangeListener(
L listener) {
return (ListenerRegistration<L>) routeChangeListeners.register(listener);