Class ZKPaths

java.lang.Object
org.apache.curator.utils.ZKPaths

public class ZKPaths extends Object
  • Field Details

  • Method Details

    • 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 String fixForNamespace(String namespace, String path)
      Apply the namespace to the given path
      Parameters:
      namespace - namespace (can be null)
      path - path
      Returns:
      adjusted path
    • fixForNamespace

      public static String fixForNamespace(String namespace, 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 String getNodeFromPath(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(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 String extractSequentialSuffix(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 List<String> split(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, String path) throws 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:
      InterruptedException - thread interruption
      org.apache.zookeeper.KeeperException - Zookeeper errors
    • mkdirs

      public static void mkdirs(org.apache.zookeeper.ZooKeeper zookeeper, String path, boolean makeLastNode) throws 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:
      InterruptedException - thread interruption
      org.apache.zookeeper.KeeperException - Zookeeper errors
    • mkdirs

      public static void mkdirs(org.apache.zookeeper.ZooKeeper zookeeper, String path, boolean makeLastNode, InternalACLProvider aclProvider) throws 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:
      InterruptedException - thread interruption
      org.apache.zookeeper.KeeperException - Zookeeper errors
    • mkdirs

      public static void mkdirs(org.apache.zookeeper.ZooKeeper zookeeper, String path, boolean makeLastNode, InternalACLProvider aclProvider, boolean asContainers) throws 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:
      InterruptedException - thread interruption
      org.apache.zookeeper.KeeperException - Zookeeper errors
    • deleteChildren

      public static void deleteChildren(org.apache.zookeeper.ZooKeeper zookeeper, String path, boolean deleteSelf) throws 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:
      InterruptedException
      org.apache.zookeeper.KeeperException
    • getSortedChildren

      public static List<String> getSortedChildren(org.apache.zookeeper.ZooKeeper zookeeper, String path) throws 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:
      InterruptedException - thread interruption
      org.apache.zookeeper.KeeperException - zookeeper errors
    • makePath

      public static String makePath(String parent, 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 String makePath(String parent, String firstChild, 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