本文整理了Java中me.hao0.antares.common.zk.ZkClient.checkExists()
方法的一些代码示例,展示了ZkClient.checkExists()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkClient.checkExists()
方法的具体详情如下:
包路径:me.hao0.antares.common.zk.ZkClient
类名称:ZkClient
方法名:checkExists
[英]Check the path exists or not
[中]检查路径是否存在
代码示例来源:origin: ihaolin/antares
/**
* Get the children of the path
* @param path the path
* @return the children of the path
*/
public List<String> gets(String path){
try {
if (!checkExists(path)){
return Collections.emptyList();
}
return client.getChildren().forPath(path);
} catch (Exception e) {
handleConnectionLoss(e);
throw new ZkException(e);
}
}
代码示例来源:origin: ihaolin/antares
/**
* Try to wait server to start
* @param server the server
* @return return true if server started, or false
*/
private Boolean tryWaitServerStart(String server) {
Sleeps.sleep(serverFailoverWaitTime);
// check server register?
String serverPath = ZkPaths.pathOfServer(server);
return zk.client().checkExists(serverPath);
}
代码示例来源:origin: ihaolin/antares
/**
* Checking the job is scheduling or not
* @param appName the app name
* @param jobClass the job class
* @return return true if the job is scheduling, or false
*/
public Boolean checkJobScheduling(String appName, String jobClass) {
String jobPath = ZkPaths.pathOfJob(appName, jobClass);
if(!zk.client().checkExists(jobPath)){
return Boolean.FALSE;
}
String scheduler = getJobScheduler(appName, jobClass);
if(Strings.isNullOrEmpty(scheduler)){
// The scheduler is empty
return Boolean.FALSE;
}
if(!zk.client().checkExists(ZkPaths.pathOfServer(scheduler))){
// The scheduler server offline
return Boolean.FALSE;
}
return Boolean.TRUE;
}
代码示例来源:origin: ihaolin/antares
/**
* Delete the node recursively if the path exists
* @param path the node path
*/
public void deleteRecursivelyIfExists(String path){
try {
if(checkExists(path)){
deleteRecursively(path);
}
} catch (Exception e){
handleConnectionLoss(e);
throw new ZkException(e);
}
}
代码示例来源:origin: ihaolin/antares
/**
* Delete the node if the node exists
* @param path node path
*/
public void deleteIfExists(String path) {
try {
if(checkExists(path)){
delete(path);
}
} catch (Exception e){
handleConnectionLoss(e);
throw new ZkException(e);
}
}
代码示例来源:origin: ihaolin/antares
/**
* Get the job fire time info
* @param appName the app name
* @param jobClass the job class
* @return the job fire time info
*/
public JobFireTime getJobFireTime(String appName, String jobClass){
String jobFireTimeNode = ZkPaths.pathOfJobFireTime(appName, jobClass);
if (!zk.client().checkExists(jobFireTimeNode)){
return null;
}
return zk.client().getJson(jobFireTimeNode, JobFireTime.class);
}
代码示例来源:origin: ihaolin/antares
/**
* Get the job scheduler
* @param appName the app name
* @param jobClass the job class
* @return the job scheduler
*/
public String getJobScheduler(String appName, String jobClass) {
String jobSchedulerNode = ZkPaths.pathOfJobScheduler(appName, jobClass);
if (!zk.client().checkExists(jobSchedulerNode)){
return null;
}
return zk.client().getString(jobSchedulerNode);
}
代码示例来源:origin: ihaolin/antares
@Override
public void run() {
ZkClient zk = client.getZk();
// register period, prevent client disconnects unexpected
String appClientPath = ZkPaths.pathOfAppClient(client.getAppName(), Systems.hostPid());
if (!zk.checkExists(appClientPath)){
zk.createEphemeral(appClientPath);
}
}
}, 1, 10, TimeUnit.SECONDS);
代码示例来源:origin: ihaolin/antares
/**
* Get the job state
* @param appName the app name
* @param jobClass the job class
* @return the job state
*/
public JobState getJobState(String appName, String jobClass) {
String jobStateNode = ZkPaths.pathOfJobState(appName, jobClass);
if (!zk.client().checkExists(jobStateNode)){
return JobState.STOPPED;
}
return JobState.from(zk.client().getInteger(jobStateNode));
}
代码示例来源:origin: ihaolin/antares
@Override
public void run() {
String server = serverHost.get();
// mkdirs /cluster/servers if necessary
zk.client().mkdirs(ZkPaths.SERVERS);
// register the server node
String serverPath = ZkPaths.pathOfServer(server);
if (!zk.client().checkExists(serverPath)){
String result = zk.client().createEphemeral(ZkPaths.pathOfServer(server));
Logs.info("server({}) registered: {}", server, result);
}
}
}, 1, 5, TimeUnit.SECONDS);
内容来源于网络,如有侵权,请联系作者删除!