java.lang.Object
org.apache.curator.framework.recipes.cache.TreeCache
All Implemented Interfaces:
Closeable, AutoCloseable

@Deprecated public class TreeCache extends Object implements Closeable
Deprecated.
replace by CuratorCache

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.

  • Constructor Details

    • TreeCache

      public TreeCache(CuratorFramework client, String path)
      Deprecated.
      Create a TreeCache for the given client and path with default options.

      If the client is namespaced, all operations on the resulting TreeCache will be in terms of the namespace, including all published events. The given path is the root at which the TreeCache will watch and explore. If no node exists at the given path, the TreeCache will be initially empty.

      Parameters:
      client - the client to use; may be namespaced
      path - the path to the root node to watch/explore; this path need not actually exist on the server
      See Also:
  • Method Details

    • newBuilder

      public static TreeCache.Builder newBuilder(CuratorFramework client, String path)
      Deprecated.
      Create a TreeCache builder for the given client and path to configure advanced options.

      If the client is namespaced, all operations on the resulting TreeCache will be in terms of the namespace, including all published events. The given path is the root at which the TreeCache will watch and explore. If no node exists at the given path, the TreeCache will be initially empty.

      Parameters:
      client - the client to use; may be namespaced
      path - the path to the root node to watch/explore; this path need not actually exist on the server
      Returns:
      a new builder
    • start

      public TreeCache start() throws Exception
      Deprecated.
      Start the cache. The cache is not started automatically. You must call this method.
      Returns:
      this
      Throws:
      Exception - errors
    • close

      public void close()
      Deprecated.
      Close/end the cache.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • getListenable

      public Listenable<TreeCacheListener> getListenable()
      Deprecated.
      Return the cache listenable
      Returns:
      listenable
    • getUnhandledErrorListenable

      public Listenable<UnhandledErrorListener> getUnhandledErrorListenable()
      Deprecated.
      Allows catching unhandled errors in asynchronous operations. TODO: consider making public.
    • getCurrentChildren

      public Map<String,ChildData> getCurrentChildren(String fullPath)
      Deprecated.
      Return the current set of children at the given path, mapped by child name. There are no guarantees of accuracy; this is merely the most recent view of the data. If there is no node at this path, null is returned.
      Parameters:
      fullPath - full path to the node to check
      Returns:
      a possibly-empty list of children if the node is alive, or null
    • getCurrentData

      public ChildData getCurrentData(String fullPath)
      Deprecated.
      Return the current data for the given path. There are no guarantees of accuracy. This is merely the most recent view of the data. If there is no node at the given path, null is returned.
      Parameters:
      fullPath - full path to the node to check
      Returns:
      data if the node is alive, or null
    • iterator

      public Iterator<ChildData> iterator()
      Deprecated.
      Return an iterator over all nodes in the cache. There are no guarantees of accuracy; this is merely the most recent view of the data.
      Returns:
      a possibly-empty iterator of nodes in the cache
    • size

      public int size()
      Deprecated.
      Return the number of nodes in the cache. There are no guarantees of accuracy; this is merely the most recent view of the data.
      Returns:
      size