public class TreeCache extends Object implements Closeable
A utility that attempts to keep all data from all children of a ZK path locally cached. This class will watch the ZK path, respond to update/create/delete events, pull down the data, etc. You can register a listener that will get notified when changes occur.
IMPORTANT - it's not possible to stay transactionally in sync. Users of this class must be prepared for false-positives and false-negatives. Additionally, always use the version number when updating data to avoid overwriting another process' change.
| Modifier and Type | Class and Description |
|---|---|
static class |
TreeCache.Builder |
| Constructor and Description |
|---|
TreeCache(org.apache.curator.framework.CuratorFramework client,
String path)
Create a TreeCache for the given client and path with default options.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close/end the cache.
|
Map<String,ChildData> |
getCurrentChildren(String fullPath)
Return the current set of children at the given path, mapped by child name.
|
ChildData |
getCurrentData(String fullPath)
Return the current data for the given path.
|
org.apache.curator.framework.listen.Listenable<TreeCacheListener> |
getListenable()
Return the cache listenable
|
org.apache.curator.framework.listen.Listenable<org.apache.curator.framework.api.UnhandledErrorListener> |
getUnhandledErrorListenable()
Allows catching unhandled errors in asynchornous operations.
|
static TreeCache.Builder |
newBuilder(org.apache.curator.framework.CuratorFramework client,
String path)
Create a TreeCache builder for the given client and path to configure advanced options.
|
TreeCache |
start()
Start the cache.
|
public TreeCache(org.apache.curator.framework.CuratorFramework client,
String path)
client - the client to use; may be namespacedpath - the path to the root node to watch/explore; this path need not actually exist on
the servernewBuilder(CuratorFramework, String)public static TreeCache.Builder newBuilder(org.apache.curator.framework.CuratorFramework client, String path)
client - the client to use; may be namespacedpath - the path to the root node to watch/explore; this path need not actually exist on
the serverpublic TreeCache start() throws Exception
Exception - errorspublic void close()
close in interface Closeableclose in interface AutoCloseablepublic org.apache.curator.framework.listen.Listenable<TreeCacheListener> getListenable()
public org.apache.curator.framework.listen.Listenable<org.apache.curator.framework.api.UnhandledErrorListener> getUnhandledErrorListenable()
public Map<String,ChildData> getCurrentChildren(String fullPath)
null is returned.fullPath - full path to the node to checkpublic ChildData getCurrentData(String fullPath)
null is returned.fullPath - full path to the node to checkCopyright © 2011–2018 The Apache Software Foundation. All rights reserved.