gpt4 book ai didi

com.indeed.util.zookeeper.ZooKeeperConnection.create()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 12:45:43 26 4
gpt4 key购买 nike

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

ZooKeeperConnection.create介绍

暂无

代码示例

代码示例来源:origin: indeedeng/util

public static boolean createFullPath(ZooKeeperConnection zooKeeperConnection, String path, byte[] value, CreateMode createMode, boolean ignoreIfExists)
    throws InterruptedException, KeeperException {
  final byte[] empty = new byte[0];
  final String[] nodes = path.split("/");
  final StringBuilder pathBuilder = new StringBuilder();
  for (int i = 1; i < nodes.length-1; i++) {
    pathBuilder.append("/").append(nodes[i]);
    createIfNotExists(zooKeeperConnection, pathBuilder.toString(), empty, CreateMode.PERSISTENT);
  }
  pathBuilder.append("/").append(nodes[nodes.length-1]);
  if (ignoreIfExists) {
    return createIfNotExists(zooKeeperConnection, path, value, createMode);
  }
  zooKeeperConnection.create(pathBuilder.toString(), value, ZooDefs.Ids.OPEN_ACL_UNSAFE, createMode);
  return true;
}

代码示例来源:origin: indeedeng/imhotep

private void createNode() {
  boolean created = false;
  while (!created) {
    try {
      try {
        zkConnection.connect();
        ZooKeeperConnection.createFullPath(zkConnection, rootPath, new byte[0], CreateMode.PERSISTENT, true);
        zkConnection.create(rootPath + "/"+nodeName, data, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
        created = true;
      } catch (IOException e) {
        log.error(e);
        Thread.sleep(TIMEOUT);
      } catch (KeeperException e) {
        log.error(e);
        zkConnection.close();
        Thread.sleep(TIMEOUT);
      }
    } catch (InterruptedException e) {
      log.error(e);
    }
  }
}

代码示例来源:origin: indeedeng/util

public static boolean createIfNotExists(ZooKeeperConnection zooKeeper, String path, byte[] value, CreateMode createMode)
    throws InterruptedException, KeeperException {
  if (zooKeeper.exists(path, false) == null) {
    try {
      zooKeeper.create(path, value, ZooDefs.Ids.OPEN_ACL_UNSAFE, createMode);
    } catch (KeeperException e) {
      if (e.code() != KeeperException.Code.NODEEXISTS) throw e;
      return false;
    }
    return true;
  }
  return false;
}

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