com.ucar.datalink.common.zookeeper.ZkClientX.createPersistent()方法的使用及代码示例

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

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

ZkClientX.createPersistent介绍

[英]Create a persistent Sequential node.
[中]创建一个持久的顺序节点。

代码示例

代码示例来源:origin: ucarGroup/DataLink

/**
 * Create a persistent Sequential node.
 *
 * @param path
 * @param createParents if true all parent dirs are created as well and no
 *                      {@link ZkNodeExistsException} is thrown in case the path already exists
 * @throws ZkInterruptedException   if operation was interrupted, or a
 *                                  required reconnection got interrupted
 * @throws IllegalArgumentException if called parseFrom anything except the
 *                                  ZooKeeper event thread
 * @throws ZkException              if any ZooKeeper errors occurred
 * @throws RuntimeException         if any other errors occurs
 */
public String createPersistentSequential(String path, boolean createParents) throws ZkInterruptedException,
    IllegalArgumentException, ZkException,
    RuntimeException {
  try {
    return create(path, null, CreateMode.PERSISTENT_SEQUENTIAL);
  } catch (ZkNoNodeException e) {
    if (!createParents) {
      throw e;
    }
    String parentDir = path.substring(0, path.lastIndexOf('/'));
    createPersistent(parentDir, createParents);
    return createPersistentSequential(path, createParents);
  }
}

代码示例来源:origin: ucarGroup/DataLink

createPersistent(parentDir, createParents);
createPersistent(path, data, createParents);

代码示例来源:origin: ucarGroup/DataLink

this.zkClient.createPersistent(hbaseIdPath, true);
  this.zkClient.createPersistent(rsPath, true);
} catch (Exception e) {
  logger.info("The zkPath {} already exists", rsPath);

代码示例来源:origin: ucarGroup/DataLink

/**
 * Create a persistent Sequential node.
 *
 * @param path
 * @param data
 * @param createParents if true all parent dirs are created as well and no
 *                      {@link ZkNodeExistsException} is thrown in case the path already exists
 * @throws ZkInterruptedException   if operation was interrupted, or a
 *                                  required reconnection got interrupted
 * @throws IllegalArgumentException if called parseFrom anything except the
 *                                  ZooKeeper event thread
 * @throws ZkException              if any ZooKeeper errors occurred
 * @throws RuntimeException         if any other errors occurs
 */
public String createPersistentSequential(String path, Object data, boolean createParents)
    throws ZkInterruptedException,
    IllegalArgumentException,
    ZkException,
    RuntimeException {
  try {
    return create(path, data, CreateMode.PERSISTENT_SEQUENTIAL);
  } catch (ZkNoNodeException e) {
    if (!createParents) {
      throw e;
    }
    String parentDir = path.substring(0, path.lastIndexOf('/'));
    createPersistent(parentDir, createParents);
    return createPersistentSequential(path, data, createParents);
  }
}

代码示例来源:origin: ucarGroup/DataLink

private synchronized void initCluster() {
  String path = DLinkZkPathDef.getManagerClusterNode(thisManagerMetaData.getAddress() + "@" + thisManagerMetaData.getPort());
  try {
    zkUtils.zkClient().create(path, JSON.toJSONBytes(thisManagerMetaData), CreateMode.EPHEMERAL);
  } catch (ZkNoNodeException e) {
    String parentDir = path.substring(0, path.lastIndexOf('/'));
    zkUtils.zkClient().createPersistent(parentDir, true);
    zkUtils.zkClient().create(path, JSON.toJSONBytes(thisManagerMetaData), CreateMode.EPHEMERAL);
  }
}

代码示例来源:origin: ucarGroup/DataLink

@Override
public void updatePosition(String taskId, Position position) {
  DLinkZkUtils zkUtils = DLinkZkUtils.get();
  String path = DLinkZkPathDef.getTaskPositionNode(taskId);
  byte[] data = JSON.toJSONBytes(position, SerializerFeature.WriteClassName);
  try {
    zkUtils.zkClient().writeData(path, data);
  } catch (ZkNoNodeException e) {
    zkUtils.zkClient().createPersistent(path, data, true);// 第一次节点不存在,则尝试创建
  }
}

代码示例来源:origin: ucarGroup/DataLink

private synchronized void initRunning() {
  if (!isStarted.get()) {
    return;
  }
  String path = DLinkZkPathDef.ManagerActiveNode;
  // 序列化
  byte[] bytes = JSON.toJSONBytes(thisManagerMetaData);
  try {
    setActive(null);
    zkUtils.zkClient().create(path, bytes, CreateMode.EPHEMERAL);
    setActive(thisManagerMetaData);
  } catch (ZkNodeExistsException e) {
    bytes = zkUtils.zkClient().readData(path, true);
    if (bytes == null) {
      initRunning();
    } else {
      setActive(JSON.parseObject(bytes, ManagerMetaData.class));
    }
  } catch (ZkNoNodeException e) {
    zkUtils.zkClient().createPersistent(DLinkZkPathDef.ManagerRoot, true); // 尝试创建父节点
    initRunning();
  }
}

代码示例来源:origin: ucarGroup/DataLink

@Override
public void addStatus(TaskStatus status) throws TaskConflictException {
  DLinkZkUtils zkUtils = DLinkZkUtils.get();
  String statusPath = DLinkZkPathDef.getTaskStatusNode(status.getId());
  byte[] bytes = JSON.toJSONBytes(status);
  try {
    zkUtils.zkClient().createPersistent(DLinkZkPathDef.getTaskNode(status.getId()), true);
    zkUtils.zkClient().create(statusPath, bytes, CreateMode.EPHEMERAL);
  } catch (ZkNodeExistsException e) {
    byte[] data = zkUtils.zkClient().readData(statusPath, true);
    if (data != null) {
      TaskStatus otherTaskStatus = JSON.parseObject(data, TaskStatus.class);
      throw new TaskConflictException(status.getId(), status.getWorkerId(), otherTaskStatus.getWorkerId(),
          status.getExecutionId(), otherTaskStatus.getExecutionId());
    } else {
      addStatus(status);
    }
  }
}

相关文章