public class NodeCache extends Object implements Closeable
A utility that attempts to keep the data from a node locally cached. This class will watch the node, 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.
| Constructor and Description |
|---|
NodeCache(org.apache.curator.framework.CuratorFramework client,
String path) |
NodeCache(org.apache.curator.framework.CuratorFramework client,
String path,
boolean dataIsCompressed) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
ChildData |
getCurrentData()
Return the current data.
|
org.apache.curator.framework.listen.ListenerContainer<NodeCacheListener> |
getListenable()
Return the cache listenable
|
protected void |
handleException(Throwable e)
Default behavior is just to log the exception
|
void |
rebuild()
NOTE: this is a BLOCKING method.
|
void |
start()
Start the cache.
|
void |
start(boolean buildInitial)
Same as
start() but gives the option of doing an initial build |
public NodeCache(org.apache.curator.framework.CuratorFramework client,
String path)
client - curztor clientpath - the full path to the node to cachepublic NodeCache(org.apache.curator.framework.CuratorFramework client,
String path,
boolean dataIsCompressed)
client - curztor clientpath - the full path to the node to cachedataIsCompressed - if true, data in the path is compressedpublic void start()
throws Exception
Exception - errorspublic void start(boolean buildInitial)
throws Exception
start() but gives the option of doing an initial buildpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic org.apache.curator.framework.listen.ListenerContainer<NodeCacheListener> getListenable()
public void rebuild()
throws Exception
Exception - errorspublic ChildData getCurrentData()
protected void handleException(Throwable e)
e - the exceptionCopyright © 2011–2018 The Apache Software Foundation. All rights reserved.