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