ServiceCacheImpl(ServiceDiscoveryImpl<T> discovery, String name, ThreadFactory threadFactory) { this(discovery, name, convertThreadFactory(threadFactory)); }
/** * Return a new service cache with the current settings * * @return service cache */ @Override public ServiceCache<T> build() { if (executorService != null) { return new ServiceCacheImpl<T>(discovery, name, executorService); } else { return new ServiceCacheImpl<T>(discovery, name, threadFactory); } }
@Override public void close() throws IOException { super.close(); nodeCache.close(); }
case CHILD_ADDED: case CHILD_UPDATED: { serviceInstance = addInstance(event.getData(), false); notifyListeners = true; break; serviceInstance = instances.remove(instanceIdFromData(event.getData())); notifyListeners = true; break;
@Override public void start() throws Exception { Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Cannot be started more than once"); cache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE); for (ChildData childData : cache.getCurrentData()) { addInstance(childData, true); } discovery.cacheOpened(this); }
private ServiceInstance<T> addInstance(ChildData childData, boolean onlyIfAbsent) throws Exception { String instanceId = instanceIdFromData(childData); ServiceInstance<T> serviceInstance = discovery.getSerializer().deserialize(childData.getData()); if (onlyIfAbsent) { instances.putIfAbsent(instanceId, serviceInstance); } else { instances.put(instanceId, serviceInstance); } cache.clearDataBytes(childData.getPath(), childData.getStat().getVersion()); return serviceInstance; } }
@Override public void start() throws Exception { super.start(); nodeCache.start(true); }
case CHILD_UPDATED: addInstance(event.getData(), false); notifyListeners = true; break; instances.remove(instanceIdFromData(event.getData())); notifyListeners = true; break;
@Override public void start() throws Exception { Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Cannot be started more than once"); cache.start(true); if ( debugStartLatch != null ) { debugStartLatch.countDown(); debugStartLatch = null; } if ( debugStartWaitLatch != null ) { debugStartWaitLatch.await(); debugStartWaitLatch = null; } for ( ChildData childData : cache.getCurrentData() ) { if ( childData.getData() != null ) // else already processed by the cache listener { addInstance(childData, true); } } discovery.cacheOpened(this); }
private void addInstance(ChildData childData, boolean onlyIfAbsent) throws Exception { String instanceId = instanceIdFromData(childData); ServiceInstance<T> serviceInstance = discovery.getSerializer().deserialize(childData.getData()); if ( onlyIfAbsent ) { instances.putIfAbsent(instanceId, serviceInstance); } else { instances.put(instanceId, serviceInstance); } cache.clearDataBytes(childData.getPath(), childData.getStat().getVersion()); } }
ServiceCacheImpl(ServiceDiscoveryImpl<T> discovery, String name, ThreadFactory threadFactory) { this(discovery, name, convertThreadFactory(threadFactory)); }