Skip to content

Path Cache

Randgalt edited this page Nov 30, 2012 · 10 revisions

Description

A Path Cache is used to watch a ZNode. Whenever a child is added, updated or removed, the Path Cache will change its state to contain the current set of children, the children's data and the children's state.

Participating Classes

  • PathChildrenCache
  • PathChildrenCacheMode
  • PathChildrenCacheListener
  • ChildData

Usage

Creating a PathChildrenCache

public PathChildrenCache(CuratorFramework client,
String path,
boolean cacheData)
Parameters:
client - the client
path - path to watch
cacheData - if true, node contents are cached in addition to the stat

General Usage

The cache must be started by calling start(). Call close() when you are through with the cache.

At any time, call getCurrentData() to get the current state of the cache. You can also register to be notified when a change occurs by calling getListenable() and then:

public void addListener(PathChildrenCacheListener listener)
Add a change listener
Parameters:
listener - the listener

Error Handling

PathChildrenCache instances internally monitor a ConnectionStateListener. If the connection state changes, the cache is reset (the PathChildrenCacheListener will receive a RESET).

Clone this wiki locally