Class ZooCache
- java.lang.Object
-
- org.apache.accumulo.fate.zookeeper.ZooCache
-
public class ZooCache extends Object
A cache for values stored in ZooKeeper. Values are kept up to date as they change.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ZooCache.ZcStat
-
Constructor Summary
Constructors Constructor Description ZooCache(String zooKeepers, int sessionTimeout)
Creates a new cache.ZooCache(String zooKeepers, int sessionTimeout, org.apache.zookeeper.Watcher watcher)
Creates a new cache.ZooCache(ZooReader reader)
ZooCache(ZooReader reader, org.apache.zookeeper.Watcher watcher)
Creates a new cache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears this cache.void
clear(String zPath)
Clears this cache of all information about nodes rooted at the given path.void
close()
protected void
copyStats(ZooCache.ZcStat userStat, ZooCache.ZcStat cachedStat)
Helper method to copy stats from the cached stat into userStatbyte[]
get(String zPath)
Gets data at the given path.byte[]
get(String zPath, ZooCache.ZcStat status)
Gets data at the given path, filling status information into the givenStat
object.List<String>
getChildren(String zPath)
Gets the children of the given node.long
getUpdateCount()
Returns a monotonically increasing count of the number of time the cache was updated.
-
-
-
Constructor Detail
-
ZooCache
public ZooCache(String zooKeepers, int sessionTimeout)
Creates a new cache.- Parameters:
zooKeepers
- comma-separated list of ZooKeeper host[:port]ssessionTimeout
- ZooKeeper session timeout
-
ZooCache
public ZooCache(String zooKeepers, int sessionTimeout, org.apache.zookeeper.Watcher watcher)
Creates a new cache. The given watcher is called whenever a watched node changes.- Parameters:
zooKeepers
- comma-separated list of ZooKeeper host[:port]ssessionTimeout
- ZooKeeper session timeoutwatcher
- watcher object
-
ZooCache
public ZooCache(ZooReader reader)
-
ZooCache
public ZooCache(ZooReader reader, org.apache.zookeeper.Watcher watcher)
Creates a new cache. The given watcher is called whenever a watched node changes.- Parameters:
reader
- ZooKeeper readerwatcher
- watcher object
-
-
Method Detail
-
getChildren
public List<String> getChildren(String zPath)
Gets the children of the given node. A watch is established by this call.- Parameters:
zPath
- path of node- Returns:
- children list, or null if node has no children or does not exist
-
get
public byte[] get(String zPath)
Gets data at the given path. Status information is not returned. A watch is established by this call.- Parameters:
zPath
- path to get- Returns:
- path data, or null if non-existent
-
get
public byte[] get(String zPath, ZooCache.ZcStat status)
Gets data at the given path, filling status information into the givenStat
object. A watch is established by this call.- Parameters:
zPath
- path to getstatus
- status object to populate- Returns:
- path data, or null if non-existent
-
copyStats
protected void copyStats(ZooCache.ZcStat userStat, ZooCache.ZcStat cachedStat)
Helper method to copy stats from the cached stat into userStat- Parameters:
userStat
- user Stat objectcachedStat
- cached statistic, that is or will be cached
-
clear
public void clear()
Clears this cache.
-
close
public void close()
-
getUpdateCount
public long getUpdateCount()
Returns a monotonically increasing count of the number of time the cache was updated. If the count is the same, then it means cache did not change.
-
clear
public void clear(String zPath)
Clears this cache of all information about nodes rooted at the given path.- Parameters:
zPath
- path of top node
-
-