本文整理了Java中com.ucar.datalink.common.zookeeper.ZkClientX.create()
方法的一些代码示例,展示了ZkClientX.create()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkClientX.create()
方法的具体详情如下:
包路径:com.ucar.datalink.common.zookeeper.ZkClientX
类名称:ZkClientX
方法名:create
[英]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
RuntimeException {
try {
create(path, data, CreateMode.PERSISTENT);
} catch (ZkNodeExistsException e) {
if (!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
/**
* 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 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);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!