@SuppressWarnings("unchecked") public <T extends RpcService> RpcRouter<T> getRpcRouter(Class<T> type) { RpcRouter<?> potentialRouter = rpcRouters.get(type); if (potentialRouter != null) { return (RpcRouter<T>) potentialRouter; } 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); notifyListenersRoutedCreated(router); return router; } }
@Override protected void removeRegistration() { if (registry != null) { T publicProxy = registry.getRpcService(serviceType); RpcService currentDelegate = RuntimeCodeHelper.getDelegate(publicProxy); if (currentDelegate == getInstance()) { RuntimeCodeHelper.setDelegate(publicProxy, null); } registry = null; } }
@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, "Default service for routed RPC already registered."); return potentialRouter.registerDefaultService(implementation); } 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); notifyGlobalRpcAdded(type); return new RpcProxyRegistration<T>(type, implementation, this); }
@Override public RpcRegistration<T> registerDefaultService(T service) { // TODO Auto-generated method stub RuntimeCodeHelper.setDelegate(invocationProxy, service); return null; }