Skip to content

Utilities

Randgalt edited this page Feb 8, 2012 · 20 revisions

Test Server

In the curator-test sub-model the TestingServer class is provided. This class creates a local, in-process ZooKeeper server that can be used for testing.

Test Cluster

In the curator-test sub-model the TestingCluster class is provided. This class creates an internally running ensemble of ZooKeeper servers.

ZKPaths

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

EnsurePath

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, ...);

NOTE: There's a method in the CuratorFramework class that returns an EnsurePath instance that is namespace aware.

BlockingQueueConsumer

See: DistributedQueue and DistributedPriorityQueue

A queue consumer that provides behavior similar to a the JDK's BlockingQueue.

Clone this wiki locally