java.io.Closeable, java.lang.AutoCloseablepublic class NodeCache
extends java.lang.Object
implements java.io.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 | Description |
|---|---|
NodeCache(org.apache.curator.framework.CuratorFramework client,
java.lang.String path) |
|
NodeCache(org.apache.curator.framework.CuratorFramework client,
java.lang.String path,
boolean dataIsCompressed) |
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
|
org.apache.curator.framework.CuratorFramework |
getClient() |
|
ChildData |
getCurrentData() |
Return the current data.
|
org.apache.curator.framework.listen.ListenerContainer<NodeCacheListener> |
getListenable() |
Return the cache listenable
|
java.lang.String |
getPath() |
Return the path this cache is watching
|
protected void |
handleException(java.lang.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,
java.lang.String path)
client - curztor clientpath - the full path to the node to cachepublic NodeCache(org.apache.curator.framework.CuratorFramework client,
java.lang.String path,
boolean dataIsCompressed)
client - curztor clientpath - the full path to the node to cachedataIsCompressed - if true, data in the path is compressedpublic org.apache.curator.framework.CuratorFramework getClient()
public void start()
throws java.lang.Exception
java.lang.Exception - errorspublic void start(boolean buildInitial)
throws java.lang.Exception
start() but gives the option of doing an initial buildbuildInitial - if true, rebuild() will be called before this method
returns in order to get an initial view of the nodejava.lang.Exception - errorspublic void close()
throws java.io.IOException
close in interface java.lang.AutoCloseableclose in interface java.io.Closeablejava.io.IOExceptionpublic org.apache.curator.framework.listen.ListenerContainer<NodeCacheListener> getListenable()
public void rebuild()
throws java.lang.Exception
java.lang.Exception - errorspublic ChildData getCurrentData()
public java.lang.String getPath()
protected void handleException(java.lang.Throwable e)
e - the exceptionCopyright © 2011–2018 The Apache Software Foundation. All rights reserved.