-
Notifications
You must be signed in to change notification settings - Fork 435
Utilities
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.
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.
Various static methods to help with using ZooKeeper ZNode paths:
- getNodeFromPath: Given a full path, return the node name. i.e. "/one/two/three" will return "three"
- mkdirs: Make sure all the nodes in the path are created.
- getSortedChildren: Return the children of the given path sorted by sequence number
- makePath: Given a parent path and a child node, create a combined full path
Utility to ensure that a particular path is created.
The first time it is used, a synchronized call to ZKPaths.mkdirs(ZooKeeper, String)
is made to ensure that the entire path has been created (with an empty byte array if needed). Subsequent calls with the instance are un-synchronized NOPs.
Usage:
EnsurePath ensurePath = new EnsurePath(aFullPathToEnsure);
...
String nodePath = aFullPathToEnsure + "/foo";
ensurePath.ensure(zk); // first time syncs and creates if needed
zk.create(nodePath, ...);
...
ensurePath.ensure(zk); // subsequent times are NOPs
zk.create(nodePath, ...);
- Curator
- Javadoc
- Coverage Report
- Getting Started
- Examples
- FAQ
- Client
- Framework
-
Recipes
- Leader Latch
- Leader Election
- Shared Reentrant Lock
- Shared Lock
- Shared Reentrant Read Write Lock
- Shared Semaphore
- Multi Shared Lock
- Distributed Queue
- Distributed Id Queue
- Distributed Priority Queue
- Distributed Delay Queue
- Simple Distributed Queue
- Barrier
- Double Barrier
- Shared counter
- Distributed Atomic Long
- Path Cache
- Node Cache
- Utilities – Test Server, Test Cluster, ZKPaths, EnsurePath, QueueSharder, Reaper, ChildReaper
- Tech Notes
- Errors
- Exhibitor Integration
- Extensions
- Logging and Tracing