public class ServiceDiscoveryImpl<T> extends Object implements ServiceDiscovery<T>
| Constructor and Description |
|---|
ServiceDiscoveryImpl(org.apache.curator.framework.CuratorFramework client,
String basePath,
InstanceSerializer<T> serializer,
ServiceInstance<T> thisInstance,
boolean watchInstances) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
protected void |
internalRegisterService(ServiceInstance<T> service) |
ServiceInstance<T> |
queryForInstance(String name,
String id)
Return a service instance POJO
|
Collection<ServiceInstance<T>> |
queryForInstances(String name)
Return all known instances for the given service
|
Collection<String> |
queryForNames()
Return the names of all known services
|
void |
registerService(ServiceInstance<T> service)
Register/re-register/update a service instance
|
ServiceCacheBuilder<T> |
serviceCacheBuilder()
Allocate a new service cache builder.
|
ServiceProviderBuilder<T> |
serviceProviderBuilder()
Allocate a new builder.
|
void |
start()
The discovery must be started before use
|
void |
unregisterService(ServiceInstance<T> service)
Unregister/remove a service instance
|
void |
updateService(ServiceInstance<T> service)
Update a service
|
public ServiceDiscoveryImpl(org.apache.curator.framework.CuratorFramework client,
String basePath,
InstanceSerializer<T> serializer,
ServiceInstance<T> thisInstance,
boolean watchInstances)
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 instancespublic void start()
throws Exception
start in interface ServiceDiscovery<T>Exception - errorspublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic void registerService(ServiceInstance<T> service) throws Exception
registerService in interface ServiceDiscovery<T>service - service to addException - errorspublic void updateService(ServiceInstance<T> service) throws Exception
ServiceDiscoveryupdateService in interface ServiceDiscovery<T>service - service to updateException - errorsprotected void internalRegisterService(ServiceInstance<T> service) throws Exception
Exceptionpublic void unregisterService(ServiceInstance<T> service) throws Exception
unregisterService in interface ServiceDiscovery<T>service - the serviceException - errorspublic ServiceProviderBuilder<T> serviceProviderBuilder()
ServiceProviderBuilder.providerStrategy(org.apache.curator.x.discovery.ProviderStrategy<T>) is set to RoundRobinStrategyserviceProviderBuilder in interface ServiceDiscovery<T>public ServiceCacheBuilder<T> serviceCacheBuilder()
serviceCacheBuilder in interface ServiceDiscovery<T>public Collection<String> queryForNames() throws Exception
queryForNames in interface ServiceDiscovery<T>Exception - errorspublic Collection<ServiceInstance<T>> queryForInstances(String name) throws Exception
queryForInstances in interface ServiceDiscovery<T>name - name of the serviceException - errorspublic ServiceInstance<T> queryForInstance(String name, String id) throws Exception
queryForInstance in interface ServiceDiscovery<T>name - name of the serviceid - ID of the instancenull if not foundException - errorsCopyright © 2011–2016 The Apache Software Foundation. All rights reserved.