本文整理了Java中org.I0Itec.zkclient.ZkClient.createPersistent()
方法的一些代码示例,展示了ZkClient.createPersistent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkClient.createPersistent()
方法的具体详情如下:
包路径:org.I0Itec.zkclient.ZkClient
类名称:ZkClient
方法名:createPersistent
暂无
代码示例来源:origin: ltsopensource/light-task-scheduler
protected String createPersistent(String path, boolean sequential) {
try {
if (sequential) {
return zkClient.createPersistentSequential(path, true);
} else {
zkClient.createPersistent(path, true);
return path;
}
} catch (ZkNodeExistsException ignored) {
}
return null;
}
代码示例来源:origin: networknt/light-4j
@Override
public void createPersistent(String path, boolean createParents) throws ZkInterruptedException, IllegalArgumentException, ZkException, RuntimeException {
zkClient.createPersistent(path, createParents);
}
代码示例来源:origin: apache/incubator-dubbo
public void createPersistent(String path, String data) {
Assert.notNull(client, new IllegalStateException("Zookeeper is not connected yet!"));
client.createPersistent(path, data);
}
代码示例来源:origin: ltsopensource/light-task-scheduler
protected String createPersistent(String path, Object data, boolean sequential) {
try {
if (sequential) {
return zkClient.createPersistentSequential(path, data);
} else {
zkClient.createPersistent(path, data);
return path;
}
} catch (ZkNodeExistsException ignored) {
}
return null;
}
代码示例来源:origin: apache/incubator-dubbo
public void createPersistent(String path) {
Assert.notNull(client, new IllegalStateException("Zookeeper is not connected yet!"));
client.createPersistent(path, true);
}
代码示例来源:origin: ltsopensource/light-task-scheduler
protected String createPersistent(String path, Object data, boolean sequential) {
try {
if (sequential) {
return zkClient.createPersistentSequential(path, data);
} else {
zkClient.createPersistent(path, data);
return path;
}
} catch (ZkNodeExistsException ignored) {
}
return null;
}
代码示例来源:origin: apache/incubator-dubbo
public void createPersistent(String path) {
Assert.notNull(client, new IllegalStateException("Zookeeper is not connected yet!"));
client.createPersistent(path, true);
}
代码示例来源:origin: ltsopensource/light-task-scheduler
protected String createPersistent(String path, boolean sequential) {
try {
if (sequential) {
return zkClient.createPersistentSequential(path, true);
} else {
zkClient.createPersistent(path, true);
return path;
}
} catch (ZkNodeExistsException ignored) {
}
return null;
}
代码示例来源:origin: apache/incubator-dubbo
public void createPersistent(String path, String data) {
Assert.notNull(client, new IllegalStateException("Zookeeper is not connected yet!"));
client.createPersistent(path, data);
}
代码示例来源:origin: killme2008/Metamorphosis
/**
* create the parent path
*/
public static void createParentPath(final ZkClient client, final String path) throws Exception {
final String parentDir = path.substring(0, path.lastIndexOf('/'));
if (parentDir.length() != 0) {
client.createPersistent(parentDir, true);
}
}
代码示例来源:origin: killme2008/Metamorphosis
/**
* make sure a persiste.nt path exists in ZK. Create the path if not exist.
*/
public static void makeSurePersistentPathExists(final ZkClient client, final String path) throws Exception {
if (!client.exists(path)) {
try {
client.createPersistent(path, true);
}
catch (final ZkNodeExistsException e) {
}
catch (final Exception e) {
throw e;
}
}
}
代码示例来源:origin: killme2008/Metamorphosis
/**
* Update the value of a persistent node with the given path and data.
* create parrent directory if necessary. Never throw NodeExistException.
*/
public static void updatePersistentPath(final ZkClient client, final String path, final String data)
throws Exception {
try {
client.writeData(path, data);
}
catch (final ZkNoNodeException e) {
createParentPath(client, path);
client.createPersistent(path, data);
}
catch (final Exception e) {
throw e;
}
}
代码示例来源:origin: crossoverJie/cim
/**
* 创建父级节点
*/
public void createRootNode(){
boolean exists = zkClient.exists(appConfiguration.getZkRoot());
if (exists){
return;
}
//创建 root
zkClient.createPersistent(appConfiguration.getZkRoot()) ;
}
代码示例来源:origin: crossoverJie/cim
/**
* 创建父级节点
*/
public void createRootNode(){
boolean exists = zkClient.exists(appConfiguration.getZkRoot());
if (exists){
return;
}
//创建 root
zkClient.createPersistent(appConfiguration.getZkRoot()) ;
}
代码示例来源:origin: weibocom/motan
private void createNode(URL url, ZkNodeType nodeType) {
String nodeTypePath = ZkUtils.toNodeTypePath(url, nodeType);
if (!zkClient.exists(nodeTypePath)) {
zkClient.createPersistent(nodeTypePath, true);
}
zkClient.createEphemeral(ZkUtils.toNodePath(url, nodeType), url.toFullStr());
}
代码示例来源:origin: apache/incubator-pinot
public static KafkaServerStartable startServer(final int port, final int brokerId, final String zkStr,
final String logDirPath, final Properties configuration) {
// Create the ZK nodes for Kafka, if needed
int indexOfFirstSlash = zkStr.indexOf('/');
if (indexOfFirstSlash != -1) {
String bareZkUrl = zkStr.substring(0, indexOfFirstSlash);
String zkNodePath = zkStr.substring(indexOfFirstSlash);
ZkClient client = new ZkClient(bareZkUrl);
client.createPersistent(zkNodePath, true);
client.close();
}
File logDir = new File(logDirPath);
logDir.mkdirs();
configureKafkaPort(configuration, port);
configureZkConnectionString(configuration, zkStr);
configureBrokerId(configuration, brokerId);
configureKafkaLogDirectory(configuration, logDir);
configuration.put("zookeeper.session.timeout.ms", "60000");
KafkaConfig config = new KafkaConfig(configuration);
KafkaServerStartable serverStartable = new KafkaServerStartable(config);
serverStartable.startup();
return serverStartable;
}
代码示例来源:origin: weibocom/motan
/**
* 更新指定group的指令列表
*
* @param command
* @param group
* @return
*/
@Override
public boolean setCommand(String group, RpcCommand command) {
String path = getCommandPath(group);
if (!zkClient.exists(path)) {
zkClient.createPersistent(path, true);
}
try {
zkClient.writeData(path, RpcCommandUtil.commandToString(command));
} catch (Exception e) {
return false;
}
return true;
}
}
代码示例来源:origin: linkedin/cruise-control
void startDetection() {
try {
_zkClient.createPersistent(_failedBrokersZkPath);
} catch (ZkNodeExistsException znee) {
// let it go.
}
// Load the failed broker information from zookeeper.
loadPersistedFailedBrokerList();
// Detect broker failures.
detectBrokerFailures();
_zkClient.subscribeChildChanges(ZkUtils.BrokerIdsPath(), new BrokerFailureListener());
}
代码示例来源:origin: apache/incubator-pinot
private void addAndRemoveNewInstanceConfig(ZkClient zkClient)
throws Exception {
int biggerRandomNumber = NUM_INSTANCES + new Random().nextInt(NUM_INSTANCES);
String instanceName = "Server_localhost_" + String.valueOf(biggerRandomNumber);
String instanceConfigPath = PropertyPathBuilder.instanceConfig(_helixClusterName, instanceName);
Assert.assertFalse(zkClient.exists(instanceConfigPath));
List<String> instances = _helixResourceManager.getAllInstances();
Assert.assertFalse(instances.contains(instanceName));
// Add new ZNode.
ZNRecord znRecord = new ZNRecord(instanceName);
zkClient.createPersistent(instanceConfigPath, znRecord);
List<String> latestAllInstances = _helixResourceManager.getAllInstances();
long maxTime = System.currentTimeMillis() + MAX_TIMEOUT_IN_MILLISECOND;
while (!latestAllInstances.contains(instanceName) && System.currentTimeMillis() < maxTime) {
Thread.sleep(100L);
latestAllInstances = _helixResourceManager.getAllInstances();
}
Assert.assertTrue(System.currentTimeMillis() < maxTime, "Timeout when waiting for adding instance config");
// Remove new ZNode.
zkClient.delete(instanceConfigPath);
latestAllInstances = _helixResourceManager.getAllInstances();
maxTime = System.currentTimeMillis() + MAX_TIMEOUT_IN_MILLISECOND;
while (latestAllInstances.contains(instanceName) && System.currentTimeMillis() < maxTime) {
Thread.sleep(100L);
latestAllInstances = _helixResourceManager.getAllInstances();
}
Assert.assertTrue(System.currentTimeMillis() < maxTime, "Timeout when waiting for removing instance config");
}
代码示例来源:origin: uber/chaperone
private void maybeCreateZkPath(String path) {
try {
_zkClient.createPersistent(path, true);
} catch (ZkNodeExistsException e) {
LOGGER.debug("Path={} is created in zk already", path);
}
}
内容来源于网络,如有侵权,请联系作者删除!