Interface CuratorCache
- All Superinterfaces:
AutoCloseable
,Closeable
,CuratorCacheAccessor
- All Known Subinterfaces:
CuratorCacheBridge
A utility that attempts to keep the data from a node locally cached. Optionally the entire tree of children below the node can also be cached. Will respond to update/create/delete events, pull down the data, etc. You can register listeners that will get notified when changes occur.
IMPORTANT - Due to how ZooKeeper works you will not get notified of every single event. For example during a network partition the cache will not get events. Imagine the following scenario:
- Pre-network partition the cache contains "/foo" and "/foo/bar"
- A network partition occurs and your Curator client loses connection to the server
- Image another client that isn't partitioned, deletes "/foo/bar" and then a third client re-creates "/foo/bar"
- Your client's partition is fixed. The cache will only see one change - the third client's re-create
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic CuratorCacheBridgeBuilder
bridgeBuilder
(CuratorFramework client, String path) Start a Curator Cache Bridge builder.static CuratorCache
build
(CuratorFramework client, String path, CuratorCache.Options... options) Return a Curator Cache for the given path with the given options using a standard storage instancestatic CuratorCacheBuilder
builder
(CuratorFramework client, String path) Start a Curator Cache buildervoid
close()
Close the cache, stop responding to events, etc.Return an entry from storageReturn the listener container so that listeners can be registered to be notified of changes to the cacheint
size()
Return the current number of entries in storagevoid
start()
Start the cache.stream()
Return a stream over the storage entries.
-
Method Details
-
build
Return a Curator Cache for the given path with the given options using a standard storage instance- Parameters:
client
- Curator clientpath
- path to cacheoptions
- any options- Returns:
- cache (note it must be started via
start()
-
builder
Start a Curator Cache builder- Parameters:
client
- Curator clientpath
- path to cache- Returns:
- builder
-
bridgeBuilder
Start a Curator Cache Bridge builder. A Curator Cache Bridge is a facade that usesCuratorCache
if persistent watches are available orTreeCache
otherwise (i.e. if you are using ZooKeeper 3.5.x).- Parameters:
client
- Curator clientpath
- path to cache- Returns:
- bridge builder
-
start
void start()Start the cache. This will cause a complete refresh from the cache's root node and generate events for all nodes found, etc. -
close
void close()Close the cache, stop responding to events, etc.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
listenable
Listenable<CuratorCacheListener> listenable()Return the listener container so that listeners can be registered to be notified of changes to the cache- Returns:
- listener container
-
get
Return an entry from storage- Specified by:
get
in interfaceCuratorCacheAccessor
- Parameters:
path
- path to get- Returns:
- entry or
empty()
-
size
int size()Return the current number of entries in storage- Specified by:
size
in interfaceCuratorCacheAccessor
- Returns:
- number of entries
-
stream
Return a stream over the storage entries. Note: for a standard storage instance, the stream behaves like a stream returned byConcurrentHashMap.entrySet()
- Specified by:
stream
in interfaceCuratorCacheAccessor
- Returns:
- stream over entries
-