Package org.apache.bookkeeper.util
Class ZkUtils
- java.lang.Object
-
- org.apache.bookkeeper.util.ZkUtils
-
public class ZkUtils extends java.lang.Object
Provided utilities for zookeeper access, etc.
-
-
Constructor Summary
Constructors Constructor Description ZkUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
asyncCreateFullPathOptimistic(org.apache.zookeeper.ZooKeeper zk, java.lang.String originalPath, byte[] data, java.util.List<org.apache.zookeeper.data.ACL> acl, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.AsyncCallback.StringCallback callback, java.lang.Object ctx)
Asynchronously create zookeeper path recursively and optimistically.static void
asyncDeleteFullPathOptimistic(org.apache.zookeeper.ZooKeeper zk, java.lang.String originalPath, int znodeVersion, org.apache.zookeeper.AsyncCallback.VoidCallback callback, java.lang.String leafNodePath)
Asynchronously deletes zookeeper path recursively and optimistically.static void
createFullPathOptimistic(org.apache.zookeeper.ZooKeeper zkc, java.lang.String path, byte[] data, java.util.List<org.apache.zookeeper.data.ACL> acl, org.apache.zookeeper.CreateMode createMode)
Create zookeeper path recursively and optimistically.static void
deleteFullPathOptimistic(org.apache.zookeeper.ZooKeeper zkc, java.lang.String path, int znodeVersion)
static java.util.List<org.apache.zookeeper.data.ACL>
getACLs(AbstractConfiguration conf)
Compute ZooKeeper ACLs using actual configuration.static java.util.List<java.lang.String>
getChildrenInSingleNode(org.apache.zookeeper.ZooKeeper zk, java.lang.String node, long zkOpTimeoutMs)
Sync get all children under single zk node.static void
getChildrenInSingleNode(org.apache.zookeeper.ZooKeeper zk, java.lang.String node, BookkeeperInternalCallbacks.GenericCallback<java.util.List<java.lang.String>> cb)
Async get direct children under single node.
-
-
-
Method Detail
-
asyncCreateFullPathOptimistic
public static void asyncCreateFullPathOptimistic(org.apache.zookeeper.ZooKeeper zk, java.lang.String originalPath, byte[] data, java.util.List<org.apache.zookeeper.data.ACL> acl, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.AsyncCallback.StringCallback callback, java.lang.Object ctx)
Asynchronously create zookeeper path recursively and optimistically.- Parameters:
zk
- Zookeeper clientoriginalPath
- Zookeeper full pathdata
- Zookeeper dataacl
- Acl of the zk pathcreateMode
- Create mode of zk pathcallback
- Callbackctx
- Context object- See Also:
createFullPathOptimistic(ZooKeeper, String, byte[], List, CreateMode)
-
asyncDeleteFullPathOptimistic
public static void asyncDeleteFullPathOptimistic(org.apache.zookeeper.ZooKeeper zk, java.lang.String originalPath, int znodeVersion, org.apache.zookeeper.AsyncCallback.VoidCallback callback, java.lang.String leafNodePath)
Asynchronously deletes zookeeper path recursively and optimistically. This method is used for deleting the leaf nodes and its corresponding parents if they don't have anymore children after deleting the child node. For deleting the parent nodes it uses -1 as znodeversion. If it fails to delete the leafnode then it will callback with the received error code, but it fails to delete the parent node for whatsoever reason it stops proceeding further and it will callback with ok error code.- Parameters:
zk
- Zookeeper clientoriginalPath
- Zookeeper full pathznodeVersion
- the expected node version of the leafnodecallback
- callbackleafNodePath
- for actual caller this leafNodePath should be same as the originalPath. But when it is called recursively leafNodePath remains the same, but the originalPath will be internal nodes.
-
createFullPathOptimistic
public static void createFullPathOptimistic(org.apache.zookeeper.ZooKeeper zkc, java.lang.String path, byte[] data, java.util.List<org.apache.zookeeper.data.ACL> acl, org.apache.zookeeper.CreateMode createMode) throws org.apache.zookeeper.KeeperException, java.lang.InterruptedException
Create zookeeper path recursively and optimistically. This method can throw any of the KeeperExceptions which can be thrown by ZooKeeper#create. KeeperException.NodeExistsException will only be thrown if the full path specified by _path_ already exists. The existence of any parent znodes is not an error condition.- Parameters:
zkc
- - ZK instancepath
- - znode pathdata
- - znode dataacl
- - Acl of the zk pathcreateMode
- - Create mode of zk path- Throws:
org.apache.zookeeper.KeeperException
- if the server returns a non-zero error code, or invalid ACLjava.lang.InterruptedException
- if the transaction is interrupted
-
deleteFullPathOptimistic
public static void deleteFullPathOptimistic(org.apache.zookeeper.ZooKeeper zkc, java.lang.String path, int znodeVersion) throws org.apache.zookeeper.KeeperException, java.lang.InterruptedException
- Throws:
org.apache.zookeeper.KeeperException
java.lang.InterruptedException
-
getChildrenInSingleNode
public static java.util.List<java.lang.String> getChildrenInSingleNode(org.apache.zookeeper.ZooKeeper zk, java.lang.String node, long zkOpTimeoutMs) throws java.lang.InterruptedException, java.io.IOException, org.apache.zookeeper.KeeperException.NoNodeException
Sync get all children under single zk node.- Parameters:
zk
- zookeeper clientnode
- node path- Returns:
- direct children
- Throws:
java.lang.InterruptedException
java.io.IOException
org.apache.zookeeper.KeeperException.NoNodeException
-
getChildrenInSingleNode
public static void getChildrenInSingleNode(org.apache.zookeeper.ZooKeeper zk, java.lang.String node, BookkeeperInternalCallbacks.GenericCallback<java.util.List<java.lang.String>> cb)
Async get direct children under single node.- Parameters:
zk
- zookeeper clientnode
- node pathcb
- callback function
-
getACLs
public static java.util.List<org.apache.zookeeper.data.ACL> getACLs(AbstractConfiguration conf)
Compute ZooKeeper ACLs using actual configuration.- Parameters:
conf
- Bookie or BookKeeper configuration
-
-