本文整理了Java中me.hao0.antares.common.zk.ZkClient.newChildWatcher()
方法的一些代码示例,展示了ZkClient.newChildWatcher()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkClient.newChildWatcher()
方法的具体详情如下:
包路径:me.hao0.antares.common.zk.ZkClient
类名称:ZkClient
方法名:newChildWatcher
[英]new a watcher of path child
[中]新的路径儿童观察者
代码示例来源:origin: ihaolin/antares
/**
* new a watcher of path child
* @param path the parent path
* @param listener a listener
* NOTE:
* Only watch first level children, not recursive
*/
public ChildWatcher newChildWatcher(String path, ChildListener listener) {
return newChildWatcher(path, listener, Boolean.TRUE);
}
代码示例来源:origin: ihaolin/antares
private void listenOnServerChanged() {
zk.newChildWatcher(ZkPaths.SERVERS, new ChildListener() {
@Override
protected void onAdd(String path, byte[] data) {
String server = ZkPaths.lastNode(path);
client.addHttpServer(server);
log.info("The server({}) joined.", server);
}
@Override
protected void onDelete(String path) {
String server = ZkPaths.lastNode(path);
client.removeHttpServer(server);
log.info("The server({}) left.", server);
}
});
}
代码示例来源:origin: ihaolin/antares
@Override
public void doStart(){
// watching the alive servers
watcher = zk.client().newChildWatcher(ZkPaths.SERVERS, new ChildListener() {
@Override
protected void onAdd(String path, byte[] data) {
String server = ZkPaths.lastNode(path);
if (!alives.contains(server)){
alives.add(server);
notifyListeners(server, true);
Logs.info("The server ({}) is joined.", server);
}
}
@Override
protected void onDelete(String path) {
String server = ZkPaths.lastNode(path);
if(alives.remove(server)){
notifyListeners(server, false);
Logs.warn("The server ({}) is left.", server);
}
}
});
}
代码示例来源:origin: ihaolin/antares
@Override
public void doStart() {
// listen app's clients change
watcher = zk.client().newChildWatcher(ZkPaths.pathOfAppClients(appName), new ChildListener() {
@Override
protected void onAdd(String path, byte[] data) {
// not started, or has shutdown
// prevent multiple redundant notifies before started
if (!started || shutdowned) {
return;
}
String client = ZkPaths.lastNode(path);
if (alives.contains(client)){
return;
}
alives.add(client);
onClientChanged(appName, client, true);
Logs.info("The app({})'s client({}) joined.", appName, client);
}
@Override
protected void onDelete(String path) {
String client = ZkPaths.lastNode(path);
alives.remove(client);
onClientChanged(appName, client, false);
Logs.info("The app({})'s client({}) left.", appName, client);
}
});
}
代码示例来源:origin: ihaolin/antares
@Override
public void doStart() {
String appName = client.getAppName();
String jobClass = getJobClass();
String jobInstancesNodePath = ZkPaths.pathOfJobInstances(appName, jobClass);
this.watcher = client.getZk().newChildWatcher(jobInstancesNodePath, new ChildListener() {
@Override
protected void onAdd(String path, byte[] data) {
// fired a new job instance
String instanceId = ZkPaths.lastNode(path);
if (Strings.isNullOrEmpty(instanceId)) return;
// execute the job
client.getJobExecutor().execute(Long.valueOf(instanceId), ZkJob.this);
}
});
}
内容来源于网络,如有侵权,请联系作者删除!