Class ZooKeeperUtil


  • public class ZooKeeperUtil
    extends Object
    Simple utility to assist in basic operations related to Zookeeper.
    Author:
    Kelly Tisdell
    • Constructor Summary

      Constructors 
      Constructor Description
      ZooKeeperUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void deleteRecursive​(String path, org.apache.zookeeper.ZooKeeper zk)
      Recursively deletes a path in Zookeeper.
      static boolean exists​(String path, org.apache.zookeeper.ZooKeeper zk)  
      static void makePath​(String path, byte[] data, org.apache.zookeeper.ZooKeeper zk)  
      static void makePath​(String path, byte[] data, org.apache.zookeeper.ZooKeeper zk, org.apache.zookeeper.CreateMode createMode)  
      static void makePath​(String path, byte[] data, org.apache.zookeeper.ZooKeeper zk, org.apache.zookeeper.CreateMode createMode, List<org.apache.zookeeper.data.ACL> acls)
      Creates a path in Zookeeper, specified by the path argument.
      static void makePath​(String path, org.apache.zookeeper.ZooKeeper zk)
      Creates a path in Zookeeper, if it does not already exist, with CreateMode.PERSISTENT for the create mode and ZooDefs.Ids.OPEN_ACL_UNSAFE for ACLs.
    • Constructor Detail

      • ZooKeeperUtil

        public ZooKeeperUtil()
    • Method Detail

      • deleteRecursive

        public static void deleteRecursive​(String path,
                                           org.apache.zookeeper.ZooKeeper zk)
                                    throws org.apache.zookeeper.KeeperException,
                                           InterruptedException
        Recursively deletes a path in Zookeeper. For example, if you have a path like /path/to/my/element, then passing "/path" to this method will delete the directory tree recursively.
        Parameters:
        path -
        zk -
        Throws:
        org.apache.zookeeper.KeeperException
        InterruptedException
      • makePath

        public static void makePath​(String path,
                                    org.apache.zookeeper.ZooKeeper zk)
                             throws org.apache.zookeeper.KeeperException,
                                    InterruptedException
        Creates a path in Zookeeper, if it does not already exist, with CreateMode.PERSISTENT for the create mode and ZooDefs.Ids.OPEN_ACL_UNSAFE for ACLs. If any part of the path exists, then the rest of this path will be appended to it..
        Parameters:
        path -
        zk -
        Throws:
        org.apache.zookeeper.KeeperException
        InterruptedException
      • makePath

        public static void makePath​(String path,
                                    byte[] data,
                                    org.apache.zookeeper.ZooKeeper zk)
                             throws org.apache.zookeeper.KeeperException,
                                    InterruptedException
        Throws:
        org.apache.zookeeper.KeeperException
        InterruptedException
      • makePath

        public static void makePath​(String path,
                                    byte[] data,
                                    org.apache.zookeeper.ZooKeeper zk,
                                    org.apache.zookeeper.CreateMode createMode)
                             throws org.apache.zookeeper.KeeperException,
                                    InterruptedException
        Throws:
        org.apache.zookeeper.KeeperException
        InterruptedException
      • makePath

        public static void makePath​(String path,
                                    byte[] data,
                                    org.apache.zookeeper.ZooKeeper zk,
                                    org.apache.zookeeper.CreateMode createMode,
                                    List<org.apache.zookeeper.data.ACL> acls)
                             throws org.apache.zookeeper.KeeperException,
                                    InterruptedException
        Creates a path in Zookeeper, specified by the path argument. For example: /path/to/my/element. If part or all of the path already exists, then it will not be created. If the data byte array is not null and has a size greater than 0, then it will be added to the final node of the path. If the final node of the path already exists, then the data will be ignored. If the ACLs are null or empty, then ZooDefs.Ids.OPEN_ACL_UNSAFE will be used. If createMode is null, then CreateMode.PERSISTENT will be used.
        Parameters:
        path -
        data -
        zk -
        createMode -
        acls -
        Throws:
        org.apache.zookeeper.KeeperException
        InterruptedException