java.io.Closeable, java.lang.AutoCloseable, ServiceDiscovery<T>public class ServiceDiscoveryImpl<T> extends java.lang.Object implements ServiceDiscovery<T>
| Constructor | Description |
|---|---|
ServiceDiscoveryImpl(org.apache.curator.framework.CuratorFramework client,
java.lang.String basePath,
InstanceSerializer<T> serializer,
ServiceInstance<T> thisInstance,
boolean watchInstances) |
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
|
protected void |
internalRegisterService(ServiceInstance<T> service) |
|
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
|
void |
updateService(ServiceInstance<T> service) |
Update a service
|
public ServiceDiscoveryImpl(org.apache.curator.framework.CuratorFramework client,
java.lang.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 java.lang.Exception
start in interface ServiceDiscovery<T>java.lang.Exception - errorspublic void close()
throws java.io.IOException
close in interface java.lang.AutoCloseableclose in interface java.io.Closeablejava.io.IOExceptionpublic void registerService(ServiceInstance<T> service) throws java.lang.Exception
registerService in interface ServiceDiscovery<T>service - service to addjava.lang.Exception - errorspublic void updateService(ServiceInstance<T> service) throws java.lang.Exception
ServiceDiscoveryupdateService in interface ServiceDiscovery<T>service - service to updatejava.lang.Exception - errorsprotected void internalRegisterService(ServiceInstance<T> service) throws java.lang.Exception
java.lang.Exceptionpublic 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(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 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 - errorsCopyright © 2011–2018 The Apache Software Foundation. All rights reserved.