Class ServiceProviderImpl<T>
- java.lang.Object
-
- org.apache.curator.x.discovery.details.ServiceProviderImpl<T>
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,ServiceProvider<T>
public class ServiceProviderImpl<T> extends java.lang.Object implements ServiceProvider<T>
The main interface for Service Discovery. Encapsulates the discovery service for a particular named service along with a provider strategy.
-
-
Constructor Summary
Constructors Constructor Description ServiceProviderImpl(ServiceDiscoveryImpl<T> discovery, java.lang.String serviceName, ProviderStrategy<T> providerStrategy, java.util.concurrent.ThreadFactory threadFactory, java.util.List<InstanceFilter<T>> filters, DownInstancePolicy downInstancePolicy)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the provider.java.util.Collection<ServiceInstance<T>>
getAllInstances()
Return the current available set of instances IMPORTANT: users should not hold on to the instance returned.ServiceInstance<T>
getInstance()
Return an instance for a single use.void
noteError(ServiceInstance<T> instance)
Take note of an error connecting to the given instance.void
start()
The provider must be started before use
-
-
-
Constructor Detail
-
ServiceProviderImpl
public ServiceProviderImpl(ServiceDiscoveryImpl<T> discovery, java.lang.String serviceName, ProviderStrategy<T> providerStrategy, java.util.concurrent.ThreadFactory threadFactory, java.util.List<InstanceFilter<T>> filters, DownInstancePolicy downInstancePolicy)
-
-
Method Detail
-
start
public void start() throws java.lang.Exception
The provider must be started before use- Specified by:
start
in interfaceServiceProvider<T>
- Throws:
java.lang.Exception
- any errors
-
close
public void close() throws java.io.IOException
Close the provider. Note: it's the provider's responsibility to close any caches it manages- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceServiceProvider<T>
- Throws:
java.io.IOException
-
getAllInstances
public java.util.Collection<ServiceInstance<T>> getAllInstances() throws java.lang.Exception
Return the current available set of instances IMPORTANT: users should not hold on to the instance returned. They should always get a fresh list.- Specified by:
getAllInstances
in interfaceServiceProvider<T>
- Returns:
- all known instances
- Throws:
java.lang.Exception
- any errors
-
getInstance
public ServiceInstance<T> getInstance() throws java.lang.Exception
Return an instance for a single use. IMPORTANT: users should not hold on to the instance returned. They should always get a fresh instance.- Specified by:
getInstance
in interfaceServiceProvider<T>
- Returns:
- the instance to use
- Throws:
java.lang.Exception
- any errors
-
noteError
public void noteError(ServiceInstance<T> instance)
Description copied from interface:ServiceProvider
Take note of an error connecting to the given instance. The instance will potentially be marked as "down" depending on theDownInstancePolicy
.- Specified by:
noteError
in interfaceServiceProvider<T>
- Parameters:
instance
- instance that had an error
-
-