Interface CuratorCache
-
- All Superinterfaces:
java.lang.AutoCloseable,java.io.Closeable,CuratorCacheAccessor
- All Known Subinterfaces:
CuratorCacheBridge
public interface CuratorCache extends java.io.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:
- 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
Nested Classes Modifier and Type Interface Description static classCuratorCache.Optionscache build options
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static CuratorCacheBridgeBuilderbridgeBuilder(org.apache.curator.framework.CuratorFramework client, java.lang.String path)Start a Curator Cache Bridge builder.static CuratorCachebuild(org.apache.curator.framework.CuratorFramework client, java.lang.String path, CuratorCache.Options... options)Return a Curator Cache for the given path with the given options using a standard storage instancestatic CuratorCacheBuilderbuilder(org.apache.curator.framework.CuratorFramework client, java.lang.String path)Start a Curator Cache buildervoidclose()Close the cache, stop responding to events, etc.java.util.Optional<ChildData>get(java.lang.String path)Return an entry from storageorg.apache.curator.framework.listen.Listenable<CuratorCacheListener>listenable()Return the listener container so that listeners can be registered to be notified of changes to the cacheintsize()Return the current number of entries in storagevoidstart()Start the cache.java.util.stream.Stream<ChildData>stream()Return a stream over the storage entries.
-
-
-
Method Detail
-
build
static CuratorCache build(org.apache.curator.framework.CuratorFramework client, java.lang.String path, CuratorCache.Options... options)
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
static CuratorCacheBuilder builder(org.apache.curator.framework.CuratorFramework client, java.lang.String path)
Start a Curator Cache builder- Parameters:
client- Curator clientpath- path to cache- Returns:
- builder
-
bridgeBuilder
static CuratorCacheBridgeBuilder bridgeBuilder(org.apache.curator.framework.CuratorFramework client, java.lang.String path)
Start a Curator Cache Bridge builder. A Curator Cache Bridge is a facade that usesCuratorCacheif persistent watches are available orTreeCacheotherwise (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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
listenable
org.apache.curator.framework.listen.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
java.util.Optional<ChildData> get(java.lang.String path)
Return an entry from storage- Specified by:
getin interfaceCuratorCacheAccessor- Parameters:
path- path to get- Returns:
- entry or
empty()
-
size
int size()
Return the current number of entries in storage- Specified by:
sizein interfaceCuratorCacheAccessor- Returns:
- number of entries
-
stream
java.util.stream.Stream<ChildData> 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:
streamin interfaceCuratorCacheAccessor- Returns:
- stream over entries
-
-