Class ZKPaths


  • public class ZKPaths
    extends java.lang.Object
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ZKPaths.PathAndNode  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String PATH_SEPARATOR
      Zookeeper's path separator character.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void deleteChildren​(org.apache.zookeeper.ZooKeeper zookeeper, java.lang.String path, boolean deleteSelf)
      Recursively deletes children of a node.
      static java.lang.String extractSequentialSuffix​(java.lang.String path)
      Extracts the ten-digit suffix from a sequential znode path.
      static java.lang.String fixForNamespace​(java.lang.String namespace, java.lang.String path)
      Apply the namespace to the given path
      static java.lang.String fixForNamespace​(java.lang.String namespace, java.lang.String path, boolean isSequential)
      Apply the namespace to the given path
      static org.apache.zookeeper.CreateMode getContainerCreateMode()  
      static java.lang.String getNodeFromPath​(java.lang.String path)
      Given a full path, return the node name.
      static ZKPaths.PathAndNode getPathAndNode​(java.lang.String path)
      Given a full path, return the node name and its path.
      static java.util.List<java.lang.String> getSortedChildren​(org.apache.zookeeper.ZooKeeper zookeeper, java.lang.String path)
      Return the children of the given path sorted by sequence number
      static boolean hasContainerSupport()
      Returns true if the version of ZooKeeper client in use supports containers
      static java.lang.String makePath​(java.lang.String parent, java.lang.String child)
      Given a parent path and a child node, create a combined full path
      static java.lang.String makePath​(java.lang.String parent, java.lang.String firstChild, java.lang.String... restChildren)
      Given a parent path and a list of children nodes, create a combined full path
      static void mkdirs​(org.apache.zookeeper.ZooKeeper zookeeper, java.lang.String path)
      Make sure all the nodes in the path are created.
      static void mkdirs​(org.apache.zookeeper.ZooKeeper zookeeper, java.lang.String path, boolean makeLastNode)
      Make sure all the nodes in the path are created.
      static void mkdirs​(org.apache.zookeeper.ZooKeeper zookeeper, java.lang.String path, boolean makeLastNode, InternalACLProvider aclProvider)
      Make sure all the nodes in the path are created.
      static void mkdirs​(org.apache.zookeeper.ZooKeeper zookeeper, java.lang.String path, boolean makeLastNode, InternalACLProvider aclProvider, boolean asContainers)
      Make sure all the nodes in the path are created.
      static java.util.List<java.lang.String> split​(java.lang.String path)
      Given a full path, return the the individual parts, without slashes.
      • Methods inherited from class java.lang.Object

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

      • PATH_SEPARATOR

        public static final java.lang.String PATH_SEPARATOR
        Zookeeper's path separator character.
        See Also:
        Constant Field Values
    • Method Detail

      • getContainerCreateMode

        public static org.apache.zookeeper.CreateMode getContainerCreateMode()
        Returns:
        CreateMode.CONTAINER if the ZK JAR supports it. Otherwise CreateMode.PERSISTENT
      • hasContainerSupport

        public static boolean hasContainerSupport()
        Returns true if the version of ZooKeeper client in use supports containers
        Returns:
        true/false
      • fixForNamespace

        public static java.lang.String fixForNamespace​(java.lang.String namespace,
                                                       java.lang.String path)
        Apply the namespace to the given path
        Parameters:
        namespace - namespace (can be null)
        path - path
        Returns:
        adjusted path
      • fixForNamespace

        public static java.lang.String fixForNamespace​(java.lang.String namespace,
                                                       java.lang.String path,
                                                       boolean isSequential)
        Apply the namespace to the given path
        Parameters:
        namespace - namespace (can be null)
        path - path
        isSequential - if the path is being created with a sequential flag
        Returns:
        adjusted path
      • getNodeFromPath

        public static java.lang.String getNodeFromPath​(java.lang.String path)
        Given a full path, return the node name. i.e. "/one/two/three" will return "three"
        Parameters:
        path - the path
        Returns:
        the node
      • getPathAndNode

        public static ZKPaths.PathAndNode getPathAndNode​(java.lang.String path)
        Given a full path, return the node name and its path. i.e. "/one/two/three" will return {"/one/two", "three"}
        Parameters:
        path - the path
        Returns:
        the node
      • extractSequentialSuffix

        public static java.lang.String extractSequentialSuffix​(java.lang.String path)
        Extracts the ten-digit suffix from a sequential znode path. Does not currently perform validation on the provided path; it will just return a string comprising the last ten characters.
        Parameters:
        path - the path of a sequential znodes
        Returns:
        the sequential suffix
      • split

        public static java.util.List<java.lang.String> split​(java.lang.String path)
        Given a full path, return the the individual parts, without slashes. The root path will return an empty list.
        Parameters:
        path - the path
        Returns:
        an array of parts
      • mkdirs

        public static void mkdirs​(org.apache.zookeeper.ZooKeeper zookeeper,
                                  java.lang.String path)
                           throws java.lang.InterruptedException,
                                  org.apache.zookeeper.KeeperException
        Make sure all the nodes in the path are created. NOTE: Unlike File.mkdirs(), Zookeeper doesn't distinguish between directories and files. So, every node in the path is created. The data for each node is an empty blob
        Parameters:
        zookeeper - the client
        path - path to ensure
        Throws:
        java.lang.InterruptedException - thread interruption
        org.apache.zookeeper.KeeperException - Zookeeper errors
      • mkdirs

        public static void mkdirs​(org.apache.zookeeper.ZooKeeper zookeeper,
                                  java.lang.String path,
                                  boolean makeLastNode)
                           throws java.lang.InterruptedException,
                                  org.apache.zookeeper.KeeperException
        Make sure all the nodes in the path are created. NOTE: Unlike File.mkdirs(), Zookeeper doesn't distinguish between directories and files. So, every node in the path is created. The data for each node is an empty blob
        Parameters:
        zookeeper - the client
        path - path to ensure
        makeLastNode - if true, all nodes are created. If false, only the parent nodes are created
        Throws:
        java.lang.InterruptedException - thread interruption
        org.apache.zookeeper.KeeperException - Zookeeper errors
      • mkdirs

        public static void mkdirs​(org.apache.zookeeper.ZooKeeper zookeeper,
                                  java.lang.String path,
                                  boolean makeLastNode,
                                  InternalACLProvider aclProvider)
                           throws java.lang.InterruptedException,
                                  org.apache.zookeeper.KeeperException
        Make sure all the nodes in the path are created. NOTE: Unlike File.mkdirs(), Zookeeper doesn't distinguish between directories and files. So, every node in the path is created. The data for each node is an empty blob
        Parameters:
        zookeeper - the client
        path - path to ensure
        makeLastNode - if true, all nodes are created. If false, only the parent nodes are created
        aclProvider - if not null, the ACL provider to use when creating parent nodes
        Throws:
        java.lang.InterruptedException - thread interruption
        org.apache.zookeeper.KeeperException - Zookeeper errors
      • mkdirs

        public static void mkdirs​(org.apache.zookeeper.ZooKeeper zookeeper,
                                  java.lang.String path,
                                  boolean makeLastNode,
                                  InternalACLProvider aclProvider,
                                  boolean asContainers)
                           throws java.lang.InterruptedException,
                                  org.apache.zookeeper.KeeperException
        Make sure all the nodes in the path are created. NOTE: Unlike File.mkdirs(), Zookeeper doesn't distinguish between directories and files. So, every node in the path is created. The data for each node is an empty blob
        Parameters:
        zookeeper - the client
        path - path to ensure
        makeLastNode - if true, all nodes are created. If false, only the parent nodes are created
        aclProvider - if not null, the ACL provider to use when creating parent nodes
        asContainers - if true, nodes are created as CreateMode.CONTAINER
        Throws:
        java.lang.InterruptedException - thread interruption
        org.apache.zookeeper.KeeperException - Zookeeper errors
      • deleteChildren

        public static void deleteChildren​(org.apache.zookeeper.ZooKeeper zookeeper,
                                          java.lang.String path,
                                          boolean deleteSelf)
                                   throws java.lang.InterruptedException,
                                          org.apache.zookeeper.KeeperException
        Recursively deletes children of a node.
        Parameters:
        zookeeper - the client
        path - path of the node to delete
        deleteSelf - flag that indicates that the node should also get deleted
        Throws:
        java.lang.InterruptedException
        org.apache.zookeeper.KeeperException
      • getSortedChildren

        public static java.util.List<java.lang.String> getSortedChildren​(org.apache.zookeeper.ZooKeeper zookeeper,
                                                                         java.lang.String path)
                                                                  throws java.lang.InterruptedException,
                                                                         org.apache.zookeeper.KeeperException
        Return the children of the given path sorted by sequence number
        Parameters:
        zookeeper - the client
        path - the path
        Returns:
        sorted list of children
        Throws:
        java.lang.InterruptedException - thread interruption
        org.apache.zookeeper.KeeperException - zookeeper errors
      • makePath

        public static java.lang.String makePath​(java.lang.String parent,
                                                java.lang.String child)
        Given a parent path and a child node, create a combined full path
        Parameters:
        parent - the parent
        child - the child
        Returns:
        full path
      • makePath

        public static java.lang.String makePath​(java.lang.String parent,
                                                java.lang.String firstChild,
                                                java.lang.String... restChildren)
        Given a parent path and a list of children nodes, create a combined full path
        Parameters:
        parent - the parent
        firstChild - the first children in the path
        restChildren - the rest of the children in the path
        Returns:
        full path