gpt4 book ai didi

org.apache.zookeeper.ZKUtil.listSubTreeBFS()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 12:28:40 29 4
gpt4 key购买 nike

本文整理了Java中org.apache.zookeeper.ZKUtil.listSubTreeBFS()方法的一些代码示例,展示了ZKUtil.listSubTreeBFS()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKUtil.listSubTreeBFS()方法的具体详情如下:
包路径:org.apache.zookeeper.ZKUtil
类名称:ZKUtil
方法名:listSubTreeBFS

ZKUtil.listSubTreeBFS介绍

[英]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.
[中]BFS遍历pathRoot下的系统,列表中的条目与遍历的顺序相同。
重要提示:这不是树的原子快照,而是从zkClient到集成的多个RPC之间存在的状态。出于实际目的,建议将客户端带到集成中(即防止写入pathRoot),以“模拟”快照行为。

代码示例

代码示例来源:origin: apache/zookeeper

/**
 * Recursively delete the node with the given path.
 * <p>
 * Important: All versions, of all nodes, under the given node are deleted.
 * <p>
 * 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.
 *
 * See {@link #delete(String, int)} for more details.
 *
 * @throws IllegalArgumentException if an invalid path is specified
 */
public static void deleteRecursive(ZooKeeper zk, final String pathRoot)
  throws InterruptedException, KeeperException
{
  PathUtils.validatePath(pathRoot);
  List<String> tree = listSubTreeBFS(zk, pathRoot);
  LOG.debug("Deleting " + tree);
  LOG.debug("Deleting " + tree.size() + " subnodes ");
  for (int i = tree.size() - 1; i >= 0 ; --i) {
    //Delete the leaves first and eventually get rid of the root
    zk.delete(tree.get(i), -1); //Delete all versions of the node with -1.
  }
}

代码示例来源:origin: apache/zookeeper

/**
 * Recursively delete the node with the given path. (async version).
 *
 * <p>
 * Important: All versions, of all nodes, under the given node are deleted.
 * <p>
 * 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.
 * <p>
 * @param zk the zookeeper handle
 * @param pathRoot the path to be deleted
 * @param cb call back method
 * @param ctx the context the callback method is called with
 * @throws IllegalArgumentException if an invalid path is specified
 */
public static void deleteRecursive(ZooKeeper zk, final String pathRoot, VoidCallback cb,
  Object ctx)
  throws InterruptedException, KeeperException
{
  PathUtils.validatePath(pathRoot);
  List<String> tree = listSubTreeBFS(zk, pathRoot);
  LOG.debug("Deleting " + tree);
  LOG.debug("Deleting " + tree.size() + " subnodes ");
  for (int i = tree.size() - 1; i >= 0 ; --i) {
    //Delete the leaves first and eventually get rid of the root
    zk.delete(tree.get(i), -1, cb, ctx); //Delete all versions of the node with -1.
  }
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

/**
 * Recursively delete the node with the given path. 
 * <p>
 * Important: All versions, of all nodes, under the given node are deleted.
 * <p>
 * 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.
 * 
 * See {@link #delete(String, int)} for more details.
 * 
 * @throws IllegalArgumentException if an invalid path is specified
 */
public static void deleteRecursive(ZooKeeper zk, final String pathRoot)
  throws InterruptedException, KeeperException
{
  PathUtils.validatePath(pathRoot);
 
  List<String> tree = listSubTreeBFS(zk, pathRoot);
  LOG.debug("Deleting " + tree);
  LOG.debug("Deleting " + tree.size() + " subnodes ");
  for (int i = tree.size() - 1; i >= 0 ; --i) {
    //Delete the leaves first and eventually get rid of the root
    zk.delete(tree.get(i), -1); //Delete all versions of the node with -1.
  }
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

/**
 * Recursively delete the node with the given path. (async version).
 * 
 * <p>
 * Important: All versions, of all nodes, under the given node are deleted.
 * <p>
 * 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.
 * <p>
 * @param zk the zookeeper handle
 * @param pathRoot the path to be deleted
 * @param cb call back method
 * @param ctx the context the callback method is called with
 * @throws IllegalArgumentException if an invalid path is specified
 */
public static void deleteRecursive(ZooKeeper zk, final String pathRoot, VoidCallback cb,
  Object ctx)
  throws InterruptedException, KeeperException
{
  PathUtils.validatePath(pathRoot);
 
  List<String> tree = listSubTreeBFS(zk, pathRoot);
  LOG.debug("Deleting " + tree);
  LOG.debug("Deleting " + tree.size() + " subnodes ");
  for (int i = tree.size() - 1; i >= 0 ; --i) {
    //Delete the leaves first and eventually get rid of the root
    zk.delete(tree.get(i), -1, cb, ctx); //Delete all versions of the node with -1.
  }
}

代码示例来源:origin: apache/ignite

/**
 * @param zk ZooKeeper client.
 * @param root Root path.
 * @return All children znodes for given path.
 * @throws Exception If failed/
 */
private List<String> listSubTree(ZooKeeper zk, String root) throws Exception {
  for (int i = 0; i < 30; i++) {
    try {
      return ZKUtil.listSubTreeBFS(zk, root);
    }
    catch (KeeperException.NoNodeException e) {
      info("NoNodeException when get znodes, will retry: " + e);
    }
  }
  throw new Exception("Failed to get znodes: " + root);
}

代码示例来源:origin: at.molindo/helios-services

final List<String> paths = ZKUtil.listSubTreeBFS(
  client.getZookeeperClient().getZooKeeper(), namespacedPath);

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com