/** * @param client the client * @param basePath base path to store data * @param serializer serializer for instances (e.g. {@link JsonInstanceSerializer}) * @param serviceDefinitionSerializer serializer for group newestDefinition. * @param thisInstance instance that represents the group that is running. The instance will get auto-registered * @param watchInstances if true, watches for changes to locally registered instances */ public ServiceDiscoveryImpl(CuratorFramework client, String basePath, InstanceSerializer<T> serializer,ServiceDefinitionSerializer<T> serviceDefinitionSerializer, ServiceInstance<T> thisInstance, boolean watchInstances) { this.watchInstances = watchInstances; this.client = Preconditions.checkNotNull(client, "client cannot be null"); this.basePath = Preconditions.checkNotNull(basePath, "basePath cannot be null"); this.serializer = Preconditions.checkNotNull(serializer, "serializer cannot be null"); this.serviceDefinitionSerializer = Preconditions.checkNotNull(serviceDefinitionSerializer,"serviceDefinitionSerializer cannot be null"); if ( thisInstance != null ) { Entry<T> entry = new Entry<T>(thisInstance); entry.cache = makeNodeCache(thisInstance); services.put(thisInstance.getId(), entry); } }
/** * Register/re-register/update a group instance * * @param service group to add * @throws Exception errors */ @Override public void registerService(ServiceInstance<T> service) throws Exception { Entry<T> newEntry = new Entry<T>(service); Entry<T> oldEntry = services.putIfAbsent(service.getId(), newEntry); Entry<T> useEntry = (oldEntry != null) ? oldEntry : newEntry; synchronized(useEntry) { if ( useEntry == newEntry ) // i.e. is new { useEntry.cache = makeNodeCache(service); } internalRegisterService(service); } }
/** * Register/re-register/update a service instance * * @param service service to add * @throws Exception errors */ @Override public void registerService(ServiceInstance<T> service) throws Exception { Entry<T> newEntry = new Entry<T>(service); Entry<T> oldEntry = services.putIfAbsent(service.getId(), newEntry); Entry<T> useEntry = (oldEntry != null) ? oldEntry : newEntry; synchronized(useEntry) { if ( useEntry == newEntry ) // i.e. is new { useEntry.cache = makeNodeCache(service); } internalRegisterService(service); } }
/** * @param client the client * @param basePath base path to store data * @param serializer serializer for instances (e.g. {@link JsonInstanceSerializer}) * @param thisInstance instance that represents the service that is running. The instance will get auto-registered * @param watchInstances if true, watches for changes to locally registered instances */ public ServiceDiscoveryImpl(CuratorFramework client, String basePath, InstanceSerializer<T> serializer, ServiceInstance<T> thisInstance, boolean watchInstances) { this.watchInstances = watchInstances; this.client = Preconditions.checkNotNull(client, "client cannot be null"); this.basePath = Preconditions.checkNotNull(basePath, "basePath cannot be null"); this.serializer = Preconditions.checkNotNull(serializer, "serializer cannot be null"); if ( thisInstance != null ) { Entry<T> entry = new Entry<T>(thisInstance); entry.cache = makeNodeCache(thisInstance); services.put(thisInstance.getId(), entry); } }