public ServiceCache<S> build() { checkNotNull(_cachingPolicy, "cachingPolicy"); if (_cachingPolicy.useMultiThreadedClientPolicy()) { checkNotNull(_serviceFactory, "serviceFactory"); checkArgument((_serviceFactory instanceof MultiThreadedServiceFactory), "Please implement MultiThreadedServiceFactory to construct MultiThreadedClientServiceCache"); return new MultiThreadedClientServiceCache<>((MultiThreadedServiceFactory<S>) _serviceFactory, _metricRegistry); } else { checkNotNull(_serviceFactory, "serviceFactory"); checkNotNull(_metricRegistry, "metricRegistry"); return new SingleThreadedClientServiceCache<>(_cachingPolicy, _serviceFactory, _metricRegistry); } }
@Override public void register(ServiceEndPoint endPoint) { checkNotNull(endPoint); Timer.Context context = _registerTimer.time(); try { doRegister(endPoint); } catch (Exception ex) { LOG.error("Error registering service handle", ex); } finally { context.stop(); } }
destroyService(toDelete); _serviceCounter.dec();
destroyService(toDelete); _serviceCounter.dec();
@Override public void register(ServiceEndPoint endPoint) { checkNotNull(endPoint); Timer.Context context = _registerTimer.time(); try { doRegister(endPoint); } catch (Exception ex) { LOG.error("Error registering service handle", ex); } finally { context.stop(); } }
public ServiceCache<S> build() { checkNotNull(_cachingPolicy, "cachingPolicy"); if (_cachingPolicy.useMultiThreadedClientPolicy()) { checkNotNull(_serviceFactory, "serviceFactory"); checkArgument((_serviceFactory instanceof MultiThreadedServiceFactory), "Please implement MultiThreadedServiceFactory to construct MultiThreadedClientServiceCache"); return new MultiThreadedClientServiceCache<>((MultiThreadedServiceFactory<S>) _serviceFactory, _metricRegistry); } else { checkNotNull(_serviceFactory, "serviceFactory"); checkNotNull(_metricRegistry, "metricRegistry"); return new SingleThreadedClientServiceCache<>(_cachingPolicy, _serviceFactory, _metricRegistry); } }
/** * Given an ServiceEndpoint return a ServiceHandle. * <p/> * If a ServiceHandle does not exist for the given ServiceEndpoint, this method will * synchronously create one and return it. * * @param endPoint The end point to retrieve the instance of service handle for * @return the service handle * @throws IllegalStateException if the cache is closed * @throws NullPointerException if endPoint is null */ @Override public ServiceHandle<S> checkOut(ServiceEndPoint endPoint) throws Exception { checkNotNull(endPoint); checkState(!_isClosed, "cache is closed"); ServiceHandle<S> serviceHandle = _instancesPerEndpoint.get(endPoint); if (serviceHandle == null) { // This is the non-ideal state, as we now have to call a synchronized // method to create the ServiceHandle and update the copy-on-write map. // // Note this can/will happen when new Endpoints are discovered due to the // inherent race conditions in ServicePool and HostDiscovery. return doRegister(endPoint); } // Note we are not checking if the serviceHandle has been flagged for Eviction, as // there are race conditions between checkOut() and ServiceCache.evict(). return serviceHandle; }
/** * Given an ServiceEndpoint return a ServiceHandle. * <p/> * If a ServiceHandle does not exist for the given ServiceEndpoint, this method will * synchronously create one and return it. * * @param endPoint The end point to retrieve the instance of service handle for * @return the service handle * @throws IllegalStateException if the cache is closed * @throws NullPointerException if endPoint is null */ @Override public ServiceHandle<S> checkOut(ServiceEndPoint endPoint) throws Exception { checkNotNull(endPoint); checkState(!_isClosed, "cache is closed"); ServiceHandle<S> serviceHandle = _instancesPerEndpoint.get(endPoint); if (serviceHandle == null) { // This is the non-ideal state, as we now have to call a synchronized // method to create the ServiceHandle and update the copy-on-write map. // // Note this can/will happen when new Endpoints are discovered due to the // inherent race conditions in ServicePool and HostDiscovery. return doRegister(endPoint); } // Note we are not checking if the serviceHandle has been flagged for Eviction, as // there are race conditions between checkOut() and ServiceCache.evict(). return serviceHandle; }