Class ZooCache


  • public class ZooCache
    extends Object
    A cache for values stored in ZooKeeper. Values are kept up to date as they change.
    • Constructor Detail

      • 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 reader
        watcher - 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 given Stat object. A watch is established by this call.
        Parameters:
        zPath - path to get
        status - 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 object
        cachedStat - 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