java.io.Closeable, java.lang.AutoCloseablepublic class TreeCache
extends java.lang.Object
implements java.io.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 | Description |
|---|---|---|
static class |
TreeCache.Builder |
| Constructor | Description |
|---|---|
TreeCache(org.apache.curator.framework.CuratorFramework client,
java.lang.String path) |
Create a TreeCache for the given client and path with default options.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
Close/end the cache.
|
java.util.Map<java.lang.String,ChildData> |
getCurrentChildren(java.lang.String fullPath) |
Return the current set of children at the given path, mapped by child name.
|
ChildData |
getCurrentData(java.lang.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,
java.lang.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,
java.lang.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, java.lang.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 java.lang.Exception
java.lang.Exception - errorspublic void close()
close in interface java.lang.AutoCloseableclose in interface java.io.Closeablepublic org.apache.curator.framework.listen.Listenable<TreeCacheListener> getListenable()
public org.apache.curator.framework.listen.Listenable<org.apache.curator.framework.api.UnhandledErrorListener> getUnhandledErrorListenable()
public java.util.Map<java.lang.String,ChildData> getCurrentChildren(java.lang.String fullPath)
null is returned.fullPath - full path to the node to checkpublic ChildData getCurrentData(java.lang.String fullPath)
null is returned.fullPath - full path to the node to checkCopyright © 2011–2018 The Apache Software Foundation. All rights reserved.