Class ServiceDiscoveryImpl<T>
java.lang.Object
org.apache.curator.x.discovery.details.ServiceDiscoveryImpl<T>
- All Implemented Interfaces:
Closeable,AutoCloseable,ServiceDiscovery<T>
A mechanism to register and query service instances using ZooKeeper
-
Constructor Summary
ConstructorsConstructorDescriptionServiceDiscoveryImpl(CuratorFramework client, String basePath, InstanceSerializer<T> serializer, ServiceInstance<T> thisInstance, boolean watchInstances) ServiceDiscoveryImpl(CuratorFramework client, DiscoveryPathConstructor pathConstructor, InstanceSerializer<T> serializer, ServiceInstance<T> thisInstance, boolean watchInstances) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected voidinternalRegisterService(ServiceInstance<T> service) queryForInstance(String name, String id) Return a service instance POJOqueryForInstances(String name) Return all known instances for the given serviceReturn the names of all known servicesvoidregisterService(ServiceInstance<T> service) Register/re-register/update a service instanceAllocate a new service cache builder.Allocate a new builder.voidstart()The discovery must be started before usevoidunregisterService(ServiceInstance<T> service) Unregister/remove a service instancevoidupdateService(ServiceInstance<T> service) Update a service
-
Constructor Details
-
ServiceDiscoveryImpl
public ServiceDiscoveryImpl(CuratorFramework client, String basePath, InstanceSerializer<T> serializer, ServiceInstance<T> thisInstance, boolean watchInstances) - Parameters:
client- the clientbasePath- base path to store dataserializer- serializer for instances (e.g.JsonInstanceSerializer)thisInstance- instance that represents the service that is running. The instance will get auto-registeredwatchInstances- if true, watches for changes to locally registered instances
-
ServiceDiscoveryImpl
public ServiceDiscoveryImpl(CuratorFramework client, DiscoveryPathConstructor pathConstructor, InstanceSerializer<T> serializer, ServiceInstance<T> thisInstance, boolean watchInstances) - Parameters:
client- the clientpathConstructor- constructor for instance pathsserializer- serializer for instances (e.g.JsonInstanceSerializer)thisInstance- instance that represents the service that is running. The instance will get auto-registeredwatchInstances- if true, watches for changes to locally registered instances
-
-
Method Details
-
start
The discovery must be started before use- Specified by:
startin interfaceServiceDiscovery<T>- Throws:
Exception- errors
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
registerService
Register/re-register/update a service instance- Specified by:
registerServicein interfaceServiceDiscovery<T>- Parameters:
service- service to add- Throws:
Exception- errors
-
updateService
Description copied from interface:ServiceDiscoveryUpdate a service- Specified by:
updateServicein interfaceServiceDiscovery<T>- Parameters:
service- service to update- Throws:
Exception- errors
-
internalRegisterService
- Throws:
Exception
-
unregisterService
Unregister/remove a service instance- Specified by:
unregisterServicein interfaceServiceDiscovery<T>- Parameters:
service- the service- Throws:
Exception- errors
-
serviceProviderBuilder
Allocate a new builder.ServiceProviderBuilder.providerStrategy(org.apache.curator.x.discovery.ProviderStrategy<T>)is set toRoundRobinStrategy- Specified by:
serviceProviderBuilderin interfaceServiceDiscovery<T>- Returns:
- the builder
-
serviceCacheBuilder
Allocate a new service cache builder. The refresh padding is defaulted to 1 second.- Specified by:
serviceCacheBuilderin interfaceServiceDiscovery<T>- Returns:
- new cache builder
-
queryForNames
Return the names of all known services- Specified by:
queryForNamesin interfaceServiceDiscovery<T>- Returns:
- list of service names
- Throws:
Exception- errors
-
queryForInstances
Return all known instances for the given service- Specified by:
queryForInstancesin interfaceServiceDiscovery<T>- Parameters:
name- name of the service- Returns:
- list of instances (or an empty list)
- Throws:
Exception- errors
-
queryForInstance
Return a service instance POJO- Specified by:
queryForInstancein interfaceServiceDiscovery<T>- Parameters:
name- name of the serviceid- ID of the instance- Returns:
- the instance or
nullif not found - Throws:
Exception- errors
-