@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;
   }
 }
  @SuppressWarnings("unchecked")
  @Override
  public final <T extends RpcService> T getRpcService(Class<T> type) {

    T potentialProxy = (T) publicProxies.get(type);
    if (potentialProxy != null) {
      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 potentialProxy;
      }
      T proxy = rpcFactory.getDirectProxyFor(type);
      LOG.debug("Created {} as public proxy for {} in {}", proxy, type.getSimpleName(), this);
      publicProxies.put(type, proxy);
      return proxy;
    }
  }