@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; } }