Class ZKUtil
- java.lang.Object
- 
- org.apache.zookeeper.ZKUtil
 
- 
 public class ZKUtil extends Object 
- 
- 
Constructor SummaryConstructors Constructor Description ZKUtil()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static StringaclToString(List<ACL> acls)static voiddeleteRecursive(ZooKeeper zk, String pathRoot)Same asdeleteRecursive(org.apache.zookeeper.ZooKeeper, java.lang.String, int)kept here for compatibility with 3.5 clients.static booleandeleteRecursive(ZooKeeper zk, String pathRoot, int batchSize)Recursively delete the node with the given path.static voiddeleteRecursive(ZooKeeper zk, String pathRoot, AsyncCallback.VoidCallback cb, Object ctx)Recursively delete the node with the given path.static StringgetPermString(int perms)static List<String>listSubTreeBFS(ZooKeeper zk, String pathRoot)BFS Traversal of the system under pathRoot, with the entries in the list, in the same order as that of the traversal.static StringvalidateFileInput(String filePath)static voidvisitSubTreeDFS(ZooKeeper zk, String path, boolean watch, AsyncCallback.StringCallback cb)Visits the subtree with root as given path and calls the passed callback with each znode found during the search.
 
- 
- 
- 
Method Detail- 
deleteRecursivepublic static boolean deleteRecursive(ZooKeeper zk, String pathRoot, int batchSize) throws InterruptedException, KeeperException Recursively delete the node with the given path.Important: All versions, of all nodes, under the given node are deleted. If there is an error with deleting one of the sub-nodes in the tree, this operation would abort and would be the responsibility of the app to handle the same. - Parameters:
- zk- Zookeeper client
- pathRoot- path to be deleted
- batchSize- number of delete operations to be submitted in one call. batchSize is also used to decide sync and async delete API invocation. If batchSize>0 then async otherwise sync delete API is invoked. batchSize>0 gives better performance. batchSize<=0 scenario is handled to preserve backward compatibility.
- Returns:
- true if given node and all its sub nodes are deleted successfully otherwise false
- Throws:
- IllegalArgumentException- if an invalid path is specified
- InterruptedException
- KeeperException
 
 - 
deleteRecursivepublic static void deleteRecursive(ZooKeeper zk, String pathRoot) throws InterruptedException, KeeperException Same asdeleteRecursive(org.apache.zookeeper.ZooKeeper, java.lang.String, int)kept here for compatibility with 3.5 clients.- Throws:
- InterruptedException
- KeeperException
- Since:
- 3.6.1
 
 - 
deleteRecursivepublic static void deleteRecursive(ZooKeeper zk, String pathRoot, AsyncCallback.VoidCallback cb, Object ctx) throws InterruptedException, KeeperException Recursively delete the node with the given path. (async version).Important: All versions, of all nodes, under the given node are deleted. If there is an error with deleting one of the sub-nodes in the tree, this operation would abort and would be the responsibility of the app to handle the same. - Parameters:
- zk- the zookeeper handle
- pathRoot- the path to be deleted
- cb- call back method
- ctx- the context the callback method is called with
- Throws:
- IllegalArgumentException- if an invalid path is specified
- InterruptedException
- KeeperException
 
 - 
validateFileInputpublic static String validateFileInput(String filePath) - Parameters:
- filePath- the file path to be validated
- Returns:
- Returns null if valid otherwise error message
 
 - 
listSubTreeBFSpublic static List<String> listSubTreeBFS(ZooKeeper zk, String pathRoot) throws KeeperException, InterruptedException BFS Traversal of the system under pathRoot, with the entries in the list, in the same order as that of the traversal.Important: This is not an atomic snapshot of the tree ever, but the state as it exists across multiple RPCs from zkClient to the ensemble. For practical purposes, it is suggested to bring the clients to the ensemble down (i.e. prevent writes to pathRoot) to 'simulate' a snapshot behavior. - Parameters:
- zk- the zookeeper handle
- pathRoot- The znode path, for which the entire subtree needs to be listed.
- Throws:
- InterruptedException
- KeeperException
 
 - 
visitSubTreeDFSpublic static void visitSubTreeDFS(ZooKeeper zk, String path, boolean watch, AsyncCallback.StringCallback cb) throws KeeperException, InterruptedException Visits the subtree with root as given path and calls the passed callback with each znode found during the search. It performs a depth-first, pre-order traversal of the tree.Important: This is not an atomic snapshot of the tree ever, but the state as it exists across multiple RPCs from zkClient to the ensemble. For practical purposes, it is suggested to bring the clients to the ensemble down (i.e. prevent writes to pathRoot) to 'simulate' a snapshot behavior. - Throws:
- KeeperException
- InterruptedException
 
 - 
getPermStringpublic static String getPermString(int perms) - Parameters:
- perms- ACL permissions
- Returns:
- string representation of permissions
 
 
- 
 
-