public interface CuratorCache extends Closeable, CuratorCacheAccessor
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:
Modifier and Type | Interface and Description |
---|---|
static class |
CuratorCache.Options
cache build options
|
Modifier and Type | Method and Description |
---|---|
static 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 instance
|
static CuratorCacheBuilder |
builder(CuratorFramework client,
String path)
Start a Curator Cache builder
|
void |
close()
Close the cache, stop responding to events, etc.
|
Optional<ChildData> |
get(String path)
Return an entry from storage
|
Listenable<CuratorCacheListener> |
listenable()
Return the listener container so that listeners can be registered to be notified of changes to the cache
|
int |
size()
Return the current number of entries in storage
|
void |
start()
Start the cache.
|
Stream<ChildData> |
stream()
Return a stream over the storage entries.
|
parentPathFilter
static CuratorCache build(CuratorFramework client, String path, CuratorCache.Options... options)
client
- Curator clientpath
- path to cacheoptions
- any optionsstart()
static CuratorCacheBuilder builder(CuratorFramework client, String path)
client
- Curator clientpath
- path to cachestatic CuratorCacheBridgeBuilder bridgeBuilder(CuratorFramework client, String path)
CuratorCache
if
persistent watches are available or TreeCache
otherwise (i.e. if you are using ZooKeeper 3.5.x).client
- Curator clientpath
- path to cachevoid start()
void close()
close
in interface AutoCloseable
close
in interface Closeable
Listenable<CuratorCacheListener> listenable()
Optional<ChildData> get(String path)
get
in interface CuratorCacheAccessor
path
- path to getempty()
int size()
size
in interface CuratorCacheAccessor
Stream<ChildData> stream()
ConcurrentHashMap.entrySet()
stream
in interface CuratorCacheAccessor
Copyright © 2011–2023 The Apache Software Foundation. All rights reserved.