Class ServiceCacheImpl<T>
java.lang.Object
org.apache.curator.x.discovery.details.ServiceCacheImpl<T>
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Listenable<ServiceCacheListener>
,PathChildrenCacheListener
,InstanceProvider<T>
,ServiceCache<T>
public class ServiceCacheImpl<T>
extends Object
implements ServiceCache<T>, PathChildrenCacheListener
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(ServiceCacheListener listener) Add the given listener.void
addListener
(ServiceCacheListener listener, Executor executor) Add the given listener.void
childEvent
(CuratorFramework client, PathChildrenCacheEvent event) Called when a change has occurredvoid
close()
Return the current list of instances.void
removeListener
(ServiceCacheListener listener) Remove the given listenervoid
start()
The cache must be started before use
-
Method Details
-
getInstances
Description copied from interface:ServiceCache
Return the current list of instances. NOTE: there is no guarantee of freshness. This is merely the last known list of instances. However, the list is updated via a ZooKeeper watcher so it should be fresh within a window of a second or two.- Specified by:
getInstances
in interfaceInstanceProvider<T>
- Specified by:
getInstances
in interfaceServiceCache<T>
- Returns:
- the list
-
start
Description copied from interface:ServiceCache
The cache must be started before use- Specified by:
start
in interfaceServiceCache<T>
- Throws:
Exception
- errors
-
startImmediate
- Specified by:
startImmediate
in interfaceServiceCache<T>
- Throws:
Exception
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
addListener
Description copied from interface:Listenable
Add the given listener. The listener will be executed in the containing instance's thread.- Specified by:
addListener
in interfaceListenable<T>
- Parameters:
listener
- listener to add
-
addListener
Description copied from interface:Listenable
Add the given listener. The listener will be executed using the given executor- Specified by:
addListener
in interfaceListenable<T>
- Parameters:
listener
- listener to addexecutor
- executor to run listener in
-
removeListener
Description copied from interface:Listenable
Remove the given listener- Specified by:
removeListener
in interfaceListenable<T>
- Parameters:
listener
- listener to remove
-
childEvent
Description copied from interface:PathChildrenCacheListener
Called when a change has occurred- Specified by:
childEvent
in interfacePathChildrenCacheListener
- Parameters:
client
- the clientevent
- describes the change
-