本文整理了Java中com.alibaba.otter.shared.common.utils.zookeeper.ZkClientx.create()
方法的一些代码示例,展示了ZkClientx.create()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkClientx.create()
方法的具体详情如下:
包路径:com.alibaba.otter.shared.common.utils.zookeeper.ZkClientx
类名称:ZkClientx
方法名:create
[英]Create a node.
[中]创建一个节点。
代码示例来源:origin: com.alibaba.otter/shared.common
/**
* Create an ephemeral node.
*
* @param path
* @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted
* @throws IllegalArgumentException if called from anything except the ZooKeeper event thread
* @throws ZkException if any ZooKeeper exception occurred
* @throws RuntimeException if any other exception occurs
*/
public void createEphemeral(final String path) throws ZkInterruptedException, IllegalArgumentException,
ZkException, RuntimeException {
create(path, null, CreateMode.EPHEMERAL);
}
代码示例来源:origin: com.alibaba.otter/shared.common
/**
* 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 from anything except the ZooKeeper event thread
* @throws ZkException if any ZooKeeper exception occurred
* @throws RuntimeException if any other exception 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: com.alibaba.otter/shared.common
/**
* 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 from anything except the ZooKeeper event thread
* @throws ZkException if any ZooKeeper exception occurred
* @throws RuntimeException if any other exception occurs
*/
public void createPersistent(String path, Object data, boolean createParents) throws ZkInterruptedException,
IllegalArgumentException, ZkException,
RuntimeException {
try {
create(path, data, CreateMode.PERSISTENT);
} catch (ZkNodeExistsException e) {
if (!createParents) {
throw e;
}
} catch (ZkNoNodeException e) {
if (!createParents) {
throw e;
}
String parentDir = path.substring(0, path.lastIndexOf('/'));
createPersistent(parentDir, createParents);
createPersistent(path, data, createParents);
}
}
代码示例来源:origin: com.alibaba.otter/shared.common
/**
* Create a persistent 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 from anything except the ZooKeeper event thread
* @throws ZkException if any ZooKeeper exception occurred
* @throws RuntimeException if any other exception occurs
*/
public void createPersistent(String path, boolean createParents) throws ZkInterruptedException,
IllegalArgumentException, ZkException,
RuntimeException {
try {
create(path, null, CreateMode.PERSISTENT);
} catch (ZkNodeExistsException e) {
if (!createParents) {
throw e;
}
} catch (ZkNoNodeException e) {
if (!createParents) {
throw e;
}
String parentDir = path.substring(0, path.lastIndexOf('/'));
createPersistent(parentDir, createParents);
createPersistent(path, createParents);
}
}
代码示例来源:origin: com.alibaba.otter/shared.common
/**
* Create an ephemeral node.
*
* @param path
* @param data
* @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted
* @throws IllegalArgumentException if called from anything except the ZooKeeper event thread
* @throws ZkException if any ZooKeeper exception occurred
* @throws RuntimeException if any other exception occurs
*/
public void createEphemeral(final String path, final Object data) throws ZkInterruptedException,
IllegalArgumentException, ZkException,
RuntimeException {
create(path, data, CreateMode.EPHEMERAL);
}
代码示例来源:origin: com.alibaba.otter/shared.common
/**
* 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 from anything except the ZooKeeper event thread
* @throws ZkException if any ZooKeeper exception occurred
* @throws RuntimeException if any other exception 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: com.alibaba.otter/shared.arbitrate
/**
* 初始化对应的pipeline节点,同步调用
*/
public void init(Long channelId, Long pipelineId) {
String path = ManagePathUtils.getPipeline(channelId, pipelineId);
String processRootPath = ManagePathUtils.getProcessRoot(channelId, pipelineId);
String terminRootPath = ManagePathUtils.getTerminRoot(channelId, pipelineId);
String remedyRootPath = ManagePathUtils.getRemedyRoot(channelId, pipelineId);
String lockRootPath = ManagePathUtils.getLockRoot(channelId, pipelineId);
String loadLockPath = lockRootPath + "/" + ArbitrateConstants.NODE_LOCK_LOAD;
try {
zookeeper.createPersistent(path, true);//创建父节点
zookeeper.create(processRootPath, new byte[0], CreateMode.PERSISTENT);
zookeeper.create(terminRootPath, new byte[0], CreateMode.PERSISTENT);
zookeeper.create(remedyRootPath, new byte[0], CreateMode.PERSISTENT);
zookeeper.create(lockRootPath, new byte[0], CreateMode.PERSISTENT);
zookeeper.create(loadLockPath, new byte[0], CreateMode.PERSISTENT);
} catch (ZkNodeExistsException e) {
// 如果节点已经存在,则不抛异常
// ignore
} catch (ZkException e) {
throw new ArbitrateException("Pipeline_init", pipelineId.toString(), e);
}
}
代码示例来源:origin: com.alibaba.otter/shared.common
/**
* Create a persistent node.
*
* @param path
* @param data
* @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted
* @throws IllegalArgumentException if called from anything except the ZooKeeper event thread
* @throws ZkException if any ZooKeeper exception occurred
* @throws RuntimeException if any other exception occurs
*/
public void createPersistent(String path, Object data) throws ZkInterruptedException, IllegalArgumentException,
ZkException, RuntimeException {
create(path, data, CreateMode.PERSISTENT);
}
代码示例来源:origin: com.alibaba.otter/shared.arbitrate
/**
* 初始化对应的channel节点,同步调用
*/
public void init(Long channelId) {
String path = ManagePathUtils.getChannelByChannelId(channelId);
byte[] data = JsonUtils.marshalToByte(ChannelStatus.STOP);// 初始化的数据对象
try {
zookeeper.create(path, data, CreateMode.PERSISTENT);
} catch (ZkNodeExistsException e) {
// 如果节点已经存在,则不抛异常
// ignore
} catch (ZkNoNodeException e) {
zookeeper.createPersistent(path, data, true);//创建父节点
} catch (ZkException e) {
throw new ArbitrateException("Channel_init", channelId.toString(), e);
}
}
代码示例来源:origin: com.alibaba.otter/shared.common
/**
* Create a persistent, sequental node.
*
* @param path
* @param data
* @return create node's path
* @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted
* @throws IllegalArgumentException if called from anything except the ZooKeeper event thread
* @throws ZkException if any ZooKeeper exception occurred
* @throws RuntimeException if any other exception occurs
*/
public String createPersistentSequential(String path, Object data) throws ZkInterruptedException,
IllegalArgumentException, ZkException,
RuntimeException {
return create(path, data, CreateMode.PERSISTENT_SEQUENTIAL);
}
代码示例来源:origin: com.alibaba.otter/shared.common
/**
* Create an ephemeral, sequential node.
*
* @param path
* @param data
* @return created path
* @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted
* @throws IllegalArgumentException if called from anything except the ZooKeeper event thread
* @throws ZkException if any ZooKeeper exception occurred
* @throws RuntimeException if any other exception occurs
*/
public String createEphemeralSequential(final String path, final Object data) throws ZkInterruptedException,
IllegalArgumentException, ZkException,
RuntimeException {
return create(path, data, CreateMode.EPHEMERAL_SEQUENTIAL);
}
代码示例来源:origin: com.alibaba.otter/shared.arbitrate
/**
* 初始化对应的系统节点,同步调用
*/
public void init() {
String rootPath = ManagePathUtils.getRoot();
String channelRootPath = ManagePathUtils.getChannelRoot();
String nodeRootPath = ManagePathUtils.getNodeRoot();
try {
zookeeper.create(rootPath, new byte[0], CreateMode.PERSISTENT);
zookeeper.create(channelRootPath, new byte[0], CreateMode.PERSISTENT);
zookeeper.create(nodeRootPath, new byte[0], CreateMode.PERSISTENT);
} catch (ZkNodeExistsException e) {
// 如果节点已经存在,则不抛异常
// ignore
} catch (ZkException e) {
throw new ArbitrateException("system_init", e);
}
}
代码示例来源:origin: com.alibaba.otter/shared.arbitrate
/**
* 创建相应的node节点,说明:node节点的生命周期为EPHEMERAL
*
* <pre>
* 1. 是个同步调用
* </pre>
*/
public void init(Long nid) {
String path = ManagePathUtils.getNode(nid);
try {
zookeeper.create(path, new byte[0], CreateMode.EPHEMERAL);// 创建为临时节点
} catch (ZkException e) {
throw new ArbitrateException("Node_init", nid.toString(), e);
}
}
代码示例来源:origin: com.alibaba.otter/shared.arbitrate
private void ensureExists(final String path) {
try {
if (zookeeper.exists(path)) {
return;
}
zookeeper.create(path, data, CreateMode.PERSISTENT);
} catch (ZkInterruptedException e) {
Thread.currentThread().interrupt();
interrupt = (InterruptedException) e.getCause();
} catch (ZkException e) {
exception = (KeeperException) e.getCause();
}
}
代码示例来源:origin: com.alibaba.otter/shared.arbitrate
/**
* 添加一个index节点
*/
public void addRemedyIndex(RemedyIndexEventData data) {
String path = StagePathUtils.getRemedyRoot(data.getPipelineId());
try {
zookeeper.create(path + "/" + RemedyIndexEventData.formatNodeName(data), new byte[] {},
CreateMode.PERSISTENT);
} catch (ZkNodeExistsException e) {
// ignore
} catch (ZkException e) {
throw new ArbitrateException("addRemedyIndex", data.getPipelineId().toString(), e);
}
}
代码示例来源:origin: com.alibaba.otter/shared.arbitrate
private boolean createTermin(TerminEventData data, Long pipelineId, Long processId) {
// 1. 创建end节点
String path = StagePathUtils.getTermin(pipelineId, processId);
data.setCurrNid(ArbitrateConfigUtils.getCurrentNid());
// 序列化
byte[] bytes = JsonUtils.marshalToByte(data);
try {
zookeeper.create(path, bytes, CreateMode.PERSISTENT);
} catch (ZkNodeExistsException e) {
// ignore
return false;
} catch (ZkException e) {
throw new ArbitrateException("Termin_single", e);
}
return true;
}
代码示例来源:origin: com.alibaba.otter/shared.arbitrate
/**
* <pre>
* 算法:
* 1. 创建对应的transformed节点,标志transform已完成
* </pre>
*
* @param pipelineId 同步流id
*/
public void single(EtlEventData data) {
Assert.notNull(data);
String path = StagePathUtils.getTransformStage(data.getPipelineId(), data.getProcessId());
data.setCurrNid(ArbitrateConfigUtils.getCurrentNid());
// 序列化
byte[] bytes = JsonUtils.marshalToByte(data, SerializerFeature.WriteClassName);
try {
zookeeper.create(path, bytes, CreateMode.PERSISTENT);
} catch (ZkNoNodeException e) {
// process节点不存在,出现了rollback/shutdown操作,直接忽略
logger.warn("pipelineId[{}] transform ignore processId[{}] single by data:{}",
new Object[] { data.getPipelineId(), data.getProcessId(), data });
} catch (ZkNodeExistsException e) {
// process节点已存在,出现了ConnectionLoss retry操作
logger.warn("pipelineId[{}] transform ignore processId[{}] single by data:{}",
new Object[] { data.getPipelineId(), data.getProcessId(), data });
} catch (ZkException e) {
throw new ArbitrateException("transform_single", e.getMessage(), e);
}
}
代码示例来源:origin: com.alibaba.otter/shared.arbitrate
/**
* <pre>
* 算法:
* 1. 创建对应的selected节点,标志selected已完成
* </pre>
*
* @param pipelineId 同步流id
*/
public void single(EtlEventData data) {
Assert.notNull(data);
String path = StagePathUtils.getSelectStage(data.getPipelineId(), data.getProcessId());
data.setCurrNid(ArbitrateConfigUtils.getCurrentNid());
// 序列化
byte[] bytes = JsonUtils.marshalToByte(data, SerializerFeature.WriteClassName);
try {
zookeeper.create(path, bytes, CreateMode.PERSISTENT);
} catch (ZkNoNodeException e) {
// process节点不存在,出现了rollback/shutdown操作,直接忽略
logger.warn("pipelineId[{}] select ignore processId[{}] single by data:{}",
new Object[] { data.getPipelineId(), data.getProcessId(), data });
} catch (ZkNodeExistsException e) {
// process节点已存在,出现了ConnectionLoss retry操作
logger.warn("pipelineId[{}] select ignore processId[{}] single by data:{}",
new Object[] { data.getPipelineId(), data.getProcessId(), data });
} catch (ZkException e) {
throw new ArbitrateException("Select_single", e.getMessage(), e);
}
}
代码示例来源:origin: com.alibaba.otter/shared.arbitrate
/**
* <pre>
* 算法:
* 1. 创建对应的extracted节点,标志extract已完成
* </pre>
*
* @param pipelineId 同步流id
*/
public void single(EtlEventData data) {
Assert.notNull(data);
String path = StagePathUtils.getExtractStage(data.getPipelineId(), data.getProcessId());
data.setCurrNid(ArbitrateConfigUtils.getCurrentNid());
// 序列化
byte[] bytes = JsonUtils.marshalToByte(data, SerializerFeature.WriteClassName);
try {
zookeeper.create(path, bytes, CreateMode.PERSISTENT);
} catch (ZkNoNodeException e) {
// process节点不存在,出现了rollback/shutdown操作,直接忽略
logger.warn("pipelineId[{}] extract ignore processId[{}] single by data:{}",
new Object[] { data.getPipelineId(), data.getProcessId(), data });
} catch (ZkNodeExistsException e) {
// process节点已存在,出现了ConnectionLoss retry操作
logger.warn("pipelineId[{}] extract ignore processId[{}] single by data:{}",
new Object[] { data.getPipelineId(), data.getProcessId(), data });
} catch (ZkInterruptedException e) {
// ignore
} catch (ZkException e) {
throw new ArbitrateException("Extract_single", e.getMessage(), e);
}
}
代码示例来源:origin: com.alibaba.otter/shared.arbitrate
try {
mutex.set(false);
zookeeper.create(path, bytes, CreateMode.EPHEMERAL);
activeData = data;
内容来源于网络,如有侵权,请联系作者删除!