Skip to content

Utilities

Randgalt edited this page Sep 1, 2011 · 20 revisions

Path Cache

See: Path Cache

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.

Path caches in the Curator Framework are provided by the PathChildrenCache class. Changes to the path are passed to registered PathChildrenCacheListener instances.

Usage
Allocate a PathChildrenCache passing in the CuratorFramework instance and the ZNode path to watch. Register one or more listeners (optional) via the addListener() method. Call start() to begin watching. Call close() when done with the cache. At any time, call getCurrentData() to get the current list of children and their data and states. Whenever the state of the path changes, listeners are notified via their childEvent() methods, receiving a PathChildrenCacheEvent object.

IMPORTANT: it's not possible for the cache to be absolutely consistent/coherent with the ZooKeeper cluster. Always use version numbers when mutating state.

Test Server

In the utils package of the Client code, the TestingServer class is provided. This class creates a local, in-process ZooKeeper server that can be used for testing.

Clone this wiki locally