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

x33g5p2x  于2022-02-05 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(113)

本文整理了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

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

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

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

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

  1. @Override public Boolean get() throws JoinException {
  2. try {
  3. ZooKeeperUtils.ensurePath(zkClient, acl, path);
  4. return true;
  5. } catch (InterruptedException e) {
  6. Thread.currentThread().interrupt();
  7. throw new JoinException("Interrupted trying to ensure group at path: " + path, e);
  8. } catch (ZooKeeperConnectionException e) {
  9. LOG.log(Level.WARNING, "Problem connecting to ZooKeeper, retrying", e);
  10. return false;
  11. } catch (KeeperException e) {
  12. if (zkClient.shouldRetry(e)) {
  13. LOG.log(Level.WARNING, "Temporary error ensuring path: " + path, e);
  14. return false;
  15. } else {
  16. throw new JoinException("Problem ensuring group at path: " + path, e);
  17. }
  18. }
  19. }
  20. });

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

  1. @Override public Boolean get() throws JoinException {
  2. try {
  3. ZooKeeperUtils.ensurePath(zkClient, acl, path);
  4. return true;
  5. } catch (InterruptedException e) {
  6. Thread.currentThread().interrupt();
  7. throw new JoinException("Interrupted trying to ensure group at path: " + path, e);
  8. } catch (ZooKeeperConnectionException e) {
  9. LOG.log(Level.WARNING, "Problem connecting to ZooKeeper, retrying", e);
  10. return false;
  11. } catch (KeeperException e) {
  12. if (zkClient.shouldRetry(e)) {
  13. LOG.log(Level.WARNING, "Temporary error ensuring path: " + path, e);
  14. return false;
  15. } else {
  16. throw new JoinException("Problem ensuring group at path: " + path, e);
  17. }
  18. }
  19. }
  20. });

相关文章

ZooKeeperUtils类方法