com.netflix.curator.framework.recipes.cache
Class PathChildrenCache

java.lang.Object
  extended by com.netflix.curator.framework.recipes.cache.PathChildrenCache
All Implemented Interfaces:
Closeable

public class PathChildrenCache
extends Object
implements Closeable

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 Summary
PathChildrenCache(CuratorFramework client, String path, PathChildrenCacheMode mode)
           
PathChildrenCache(CuratorFramework client, String path, PathChildrenCacheMode mode, ThreadFactory threadFactory)
           
 
Method Summary
 void clearAndRefresh()
          Clear out current data and begin a new query on the path
 void close()
          Close/end the cache
 List<ChildData> getCurrentData()
          Return the current data.
 ChildData getCurrentData(String fullPath)
          Return the current data for the given path.
 ListenerContainer<PathChildrenCacheListener> getListenable()
          Return the cache listenable
protected  void handleException(Throwable e)
          Default behavior is just to log the exception
 void start()
          Start the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PathChildrenCache

public PathChildrenCache(CuratorFramework client,
                         String path,
                         PathChildrenCacheMode mode)
Parameters:
client - the client
path - path to watch
mode - caching mode

PathChildrenCache

public PathChildrenCache(CuratorFramework client,
                         String path,
                         PathChildrenCacheMode mode,
                         ThreadFactory threadFactory)
Parameters:
client - the client
path - path to watch
mode - caching mode
threadFactory - factory to use when creating internal threads
Method Detail

start

public void start()
           throws Exception
Start the cache. The cache is not started automatically. You must call this method.

Throws:
Exception - errors

close

public void close()
           throws IOException
Close/end the cache

Specified by:
close in interface Closeable
Throws:
IOException - errors

getListenable

public ListenerContainer<PathChildrenCacheListener> getListenable()
Return the cache listenable

Returns:
listenable

getCurrentData

public List<ChildData> getCurrentData()
Return the current data. There are no guarantees of accuracy. This is merely the most recent view of the data. The data is returned in sorted order.

Returns:
list of children and data

getCurrentData

public ChildData getCurrentData(String fullPath)
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 child with that path, null is returned.

Parameters:
fullPath - full path to the node to check
Returns:
data or null

clearAndRefresh

public void clearAndRefresh()
                     throws Exception
Clear out current data and begin a new query on the path

Throws:
Exception - errors

handleException

protected void handleException(Throwable e)
Default behavior is just to log the exception

Parameters:
e - the exception


Copyright © 2012. All Rights Reserved.