コード例 #1
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);
 }
コード例 #2
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;
 }
コード例 #3
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);
 }