/**
  * Get a node's data and set a watch.
  *
  * @param path
  * @param watcher
  * @param stat
  * @return
  * @throws InterruptedException
  * @throws KeeperException
  */
 public Object getData(Object path, final Closure watcher, Stat stat)
     throws InterruptedException, KeeperException {
   return deserialize(
       zookeeper.getData(
           getPathAsString(path),
           new Watcher() {
             public void process(WatchedEvent event) {
               watcher.call(event);
             }
           },
           stat));
 }
 /**
  * Asynchronously delete the node at the given path, with the specified version, and execute the
  * given {@link groovy.lang.Closure} as a callback.
  *
  * @param path
  * @param version
  * @param callback
  */
 public void delete(Object path, int version, final Closure callback) {
   zookeeper.delete(
       getPathAsString(path),
       version,
       new AsyncCallback.VoidCallback() {
         public void processResult(int rc, String path, Object ctx) {
           callback.setProperty("returnCode", rc);
           callback.setProperty("path", path);
           callback.setDelegate(ctx);
           callback.call();
         }
       },
       this);
 }
 /**
  * Set a node's data asynchronously.
  *
  * @param path
  * @param data
  * @param version
  * @param callback
  */
 public void setData(Object path, Object data, int version, final Closure callback) {
   zookeeper.setData(
       getPathAsString(path),
       serialize(data),
       version,
       new AsyncCallback.StatCallback() {
         public void processResult(int rc, String path, Object ctx, Stat stat) {
           callback.setDelegate(ctx);
           callback.setProperty("returnCode", rc);
           callback.setProperty("path", path);
           callback.call(stat);
         }
       },
       this);
 }
 /**
  * Check if node exists asynchronously.
  *
  * @param path
  * @param watch
  * @param callback
  * @throws InterruptedException
  * @throws KeeperException
  */
 public void exists(Object path, boolean watch, final Closure callback)
     throws InterruptedException, KeeperException {
   zookeeper.exists(
       getPathAsString(path),
       watch,
       new AsyncCallback.StatCallback() {
         public void processResult(int rc, String path, Object ctx, Stat stat) {
           callback.setProperty("returnCode", rc);
           callback.setProperty("path", path);
           callback.setDelegate(ctx);
           callback.call(stat);
         }
       },
       this);
 }
 /**
  * Create a ZooKeeper node asynchronously by specifying all parameters.
  *
  * @param path
  * @param data
  * @param acls
  * @param mode
  * @param callback
  */
 public void create(
     Object path, Object data, List<ACL> acls, CreateMode mode, final Closure callback) {
   zookeeper.create(
       getPathAsString(path),
       serialize(data),
       acls,
       mode,
       new AsyncCallback.StringCallback() {
         public void processResult(int rc, String path, Object ctx, String name) {
           callback.setProperty("returnCode", rc);
           callback.setProperty("path", path);
           callback.setDelegate(ctx);
           callback.call(name);
         }
       },
       this);
 }
 /**
  * Create a PERSISTENT type node, but also create any intermediate parent nodes.
  *
  * @param path
  * @return
  * @throws InterruptedException
  * @throws KeeperException
  */
 public String createPersistentNodeAndParents(Object path)
     throws InterruptedException, KeeperException {
   String spath = getPathAsString(path);
   String[] parts = spath.substring(1).split("/");
   StringBuffer buff = new StringBuffer();
   String fullPath = null;
   for (String p : parts) {
     buff.append("/").append(p);
     try {
       fullPath =
           zookeeper.create(
               buff.toString(), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
     } catch (KeeperException.NodeExistsException ignored) {
       fullPath = buff.toString();
     }
   }
   return fullPath;
 }
 /**
  * Set a node's data.
  *
  * @param path
  * @param data
  * @param version
  * @return
  * @throws InterruptedException
  * @throws KeeperException
  */
 public Stat setData(Object path, Object data, int version)
     throws InterruptedException, KeeperException {
   return zookeeper.setData(getPathAsString(path), serialize(data), version);
 }
 /**
  * Get a specific version of the node's data.
  *
  * @param path
  * @param stat
  * @return
  * @throws InterruptedException
  * @throws KeeperException
  */
 public Object getData(Object path, Stat stat) throws InterruptedException, KeeperException {
   return deserialize(zookeeper.getData(getPathAsString(path), false, stat));
 }
 /**
  * Get a node's children and specify whether to set a watch or not.
  *
  * @param path
  * @param watch
  * @return
  * @throws InterruptedException
  * @throws KeeperException
  */
 public List<String> getChildren(Object path, boolean watch)
     throws InterruptedException, KeeperException {
   return zookeeper.getChildren(getPathAsString(path), watch);
 }
 /**
  * Check if a node exists synchronously.
  *
  * @param path
  * @param watch
  * @return
  * @throws InterruptedException
  * @throws KeeperException
  */
 public Stat exists(Object path, boolean watch) throws InterruptedException, KeeperException {
   return zookeeper.exists(getPathAsString(path), watch);
 }
 /**
  * Create a ZooKeeper node synchronously by specifying all parameters.
  *
  * @param path
  * @param data
  * @param acls
  * @param mode
  * @return
  * @throws InterruptedException
  * @throws KeeperException
  */
 public Node create(Object path, Object data, List<ACL> acls, CreateMode mode)
     throws InterruptedException, KeeperException {
   String s = zookeeper.create(getPathAsString(path), serialize(data), acls, mode);
   return new Node(s, mode);
 }
 /**
  * Delete the node with the given version.
  *
  * @param path plain or Groovy string
  * @param version version to delete
  * @throws InterruptedException
  * @throws KeeperException
  */
 public void delete(Object path, int version) throws InterruptedException, KeeperException {
   zookeeper.delete(getPathAsString(path), version);
 }
 /**
  * Close all resources.
  *
  * @throws InterruptedException
  */
 public void close() throws InterruptedException {
   zookeeper.close();
 }