public class ServiceDiscoveryImpl<T> extends java.lang.Object implements ServiceDiscovery<T>
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_REFRESH_PADDING |
| Constructor and Description |
|---|
ServiceDiscoveryImpl(CuratorFramework client,
java.lang.String basePath,
InstanceSerializer<T> serializer,
ServiceInstance<T> thisInstance) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
ServiceInstance<T> |
queryForInstance(java.lang.String name,
java.lang.String id)
Return a service instance POJO
|
java.util.Collection<ServiceInstance<T>> |
queryForInstances(java.lang.String name)
Return all known instances for the given service
|
java.util.Collection<java.lang.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
|
public ServiceDiscoveryImpl(CuratorFramework client, java.lang.String basePath, InstanceSerializer<T> serializer, ServiceInstance<T> thisInstance)
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-registeredpublic void start()
throws java.lang.Exception
start in interface ServiceDiscovery<T>java.lang.Exception - errorspublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOExceptionpublic void registerService(ServiceInstance<T> service) throws java.lang.Exception
registerService in interface ServiceDiscovery<T>service - service to addjava.lang.Exception - errorspublic void unregisterService(ServiceInstance<T> service) throws java.lang.Exception
unregisterService in interface ServiceDiscovery<T>service - the servicejava.lang.Exception - errorspublic ServiceProviderBuilder<T> serviceProviderBuilder()
ServiceProviderBuilder.providerStrategy(com.netflix.curator.x.discovery.ProviderStrategy<T>) is set to RoundRobinStrategy
and ServiceProviderBuilder.refreshPaddingMs(int) is set to 1 second.serviceProviderBuilder in interface ServiceDiscovery<T>public ServiceCacheBuilder<T> serviceCacheBuilder()
serviceCacheBuilder in interface ServiceDiscovery<T>public java.util.Collection<java.lang.String> queryForNames()
throws java.lang.Exception
queryForNames in interface ServiceDiscovery<T>java.lang.Exception - errorspublic java.util.Collection<ServiceInstance<T>> queryForInstances(java.lang.String name) throws java.lang.Exception
queryForInstances in interface ServiceDiscovery<T>name - name of the servicejava.lang.Exception - errorspublic ServiceInstance<T> queryForInstance(java.lang.String name, java.lang.String id) throws java.lang.Exception
queryForInstance in interface ServiceDiscovery<T>name - name of the serviceid - ID of the instancenull if not foundjava.lang.Exception - errors