gpt4 book ai didi

com.twitter.common.zookeeper.ZooKeeperUtils.ensurePath()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-19 02:13:31 26 4
gpt4 key购买 nike

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

ZooKeeperUtils.ensurePath介绍

[英]Ensures the given path exists in the ZK cluster accessed by zkClient. If the path already exists, nothing is done; however if any portion of the path is missing, it will be created with the given acl as a persistent zookeeper node. The given path must be a valid zookeeper absolute path.
[中]确保给定路径存在于ZK客户端访问的ZK集群中。如果路径已经存在,则什么也不做;但是,如果路径的任何部分丢失,将使用给定的acl作为持久的zookeeper节点创建该路径。给定路径必须是有效的zookeeper绝对路径。

代码示例

代码示例来源:origin: com.twitter.common/zookeeper

private synchronized void prepare()
 throws ZooKeeperClient.ZooKeeperConnectionException, InterruptedException, KeeperException {
 ZooKeeperUtils.ensurePath(zkClient, acl, lockPath);
 LOG.log(Level.FINE, "Working with locking path:" + lockPath);
 // Create an EPHEMERAL_SEQUENTIAL node.
 currentNode =
   zkClient.get().create(lockPath + "/member_", null, acl, CreateMode.EPHEMERAL_SEQUENTIAL);
 // We only care about our actual id since we want to compare ourselves to siblings.
 if (currentNode.contains("/")) {
  currentId = currentNode.substring(currentNode.lastIndexOf("/") + 1);
 }
 LOG.log(Level.FINE, "Received ID from zk:" + currentId);
 this.watcher = new LockWatcher();
}

代码示例来源:origin: com.twitter.common.zookeeper/lock

private synchronized void prepare()
 throws ZooKeeperClient.ZooKeeperConnectionException, InterruptedException, KeeperException {
 ZooKeeperUtils.ensurePath(zkClient, acl, lockPath);
 LOG.log(Level.FINE, "Working with locking path:" + lockPath);
 // Create an EPHEMERAL_SEQUENTIAL node.
 currentNode =
   zkClient.get().create(lockPath + "/member_", null, acl, CreateMode.EPHEMERAL_SEQUENTIAL);
 // We only care about our actual id since we want to compare ourselves to siblings.
 if (currentNode.contains("/")) {
  currentId = currentNode.substring(currentNode.lastIndexOf("/") + 1);
 }
 LOG.log(Level.FINE, "Received ID from zk:" + currentId);
 this.watcher = new LockWatcher();
}

代码示例来源:origin: com.twitter.common.zookeeper/group

@Override public Boolean get() throws JoinException {
  try {
   ZooKeeperUtils.ensurePath(zkClient, acl, path);
   return true;
  } catch (InterruptedException e) {
   Thread.currentThread().interrupt();
   throw new JoinException("Interrupted trying to ensure group at path: " + path, e);
  } catch (ZooKeeperConnectionException e) {
   LOG.log(Level.WARNING, "Problem connecting to ZooKeeper, retrying", e);
   return false;
  } catch (KeeperException e) {
   if (zkClient.shouldRetry(e)) {
    LOG.log(Level.WARNING, "Temporary error ensuring path: " + path, e);
    return false;
   } else {
    throw new JoinException("Problem ensuring group at path: " + path, e);
   }
  }
 }
});

代码示例来源:origin: com.twitter.common/zookeeper

@Override public Boolean get() throws JoinException {
  try {
   ZooKeeperUtils.ensurePath(zkClient, acl, path);
   return true;
  } catch (InterruptedException e) {
   Thread.currentThread().interrupt();
   throw new JoinException("Interrupted trying to ensure group at path: " + path, e);
  } catch (ZooKeeperConnectionException e) {
   LOG.log(Level.WARNING, "Problem connecting to ZooKeeper, retrying", e);
   return false;
  } catch (KeeperException e) {
   if (zkClient.shouldRetry(e)) {
    LOG.log(Level.WARNING, "Temporary error ensuring path: " + path, e);
    return false;
   } else {
    throw new JoinException("Problem ensuring group at path: " + path, e);
   }
  }
 }
});

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