Database Reference
In-Depth Information
.storingStatIn(stat)
.forPath("/queue");
for (String job : jobs)
System. out .println("Job: "+job);
System. out .println("Number of children: "
+stat.getNumChildren());
To remove a path, use the delete command. Like the native ZooKeeper
client, this command can be set to act on a specific version with the
withVersion command. This example checks to see if the path exists and
then deletes the specific version if it does. It will also delete any children the
znode may have:
Stat stat;
if((stat = client.checkExists().forPath("/a/test/
path")) != null)
client.delete()
.deletingChildrenIfNeeded()
.withVersion(stat.getVersion())
.forPath("/a/test/path");
Using Watches with Curator
The checkExists , getData , and getChildren commands support
having watches set on them via the usingWatch method. This method
takes, as an argument, an object implementing either the native ZooKeeper
Watcher interface or the Curator-specific CuratorWatcher interface. The
Watcher interface has been described previously, and the
CuratorWatcher is essentially identical. For example, the following code
uses a CuratorWatcher to observe changes to the existence of a specific
path:
client.checkExists().usingWatcher( new CuratorWatcher()
{
public void process(WatchedEvent arg0) throws
Exception {
if (arg0.getType() ==
Watcher.Event.EventType. None ) {
//State change
Search WWH ::




Custom Search