コード例 #1
0
 /**
  * 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));
 }
コード例 #2
0
 /**
  * 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);
 }
コード例 #3
0
 /**
  * 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);
 }
コード例 #4
0
 /**
  * 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);
 }
コード例 #5
0
 /**
  * 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);
 }
コード例 #6
0
 /**
  * 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;
 }
コード例 #7
0
 /**
  * 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);
 }
コード例 #8
0
 /**
  * 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));
 }
コード例 #9
0
 /**
  * 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);
 }
コード例 #10
0
 /**
  * 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);
 }
コード例 #11
0
 /**
  * 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);
 }
コード例 #12
0
 /**
  * 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);
 }
コード例 #13
0
 /**
  * Close all resources.
  *
  * @throws InterruptedException
  */
 public void close() throws InterruptedException {
   zookeeper.close();
 }