Class 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ZkUtils

        public ZkUtils()
    • 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 client
        originalPath - Zookeeper full path
        data - Zookeeper data
        acl - Acl of the zk path
        createMode - Create mode of zk path
        callback - Callback
        ctx - 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 client
        originalPath - Zookeeper full path
        znodeVersion - the expected node version of the leafnode
        callback - callback
        leafNodePath - 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 instance
        path - - znode path
        data - - znode data
        acl - - Acl of the zk path
        createMode - - Create mode of zk path
        Throws:
        org.apache.zookeeper.KeeperException - if the server returns a non-zero error code, or invalid ACL
        java.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 client
        node - 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 client
        node - node path
        cb - 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