use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project Saturn by vipshop.
the class RestartAndDumpService method initRestart.
private void initRestart() throws Exception {
restartES = Executors.newSingleThreadExecutor(new SaturnThreadFactory(executorName + "-restart-watcher-thread", false));
// Remove the restart node, before add watcher that watches the create and update event
String nodePath = SaturnExecutorsNode.EXECUTORS_ROOT + "/" + executorName + "/restart";
coordinatorRegistryCenter.remove(nodePath);
restartNC = new NodeCache(curatorFramework, nodePath);
restartNC.getListenable().addListener(new NodeCacheListener() {
@Override
public void nodeChanged() throws Exception {
// Watch create, update event
if (restartNC.getCurrentData() != null) {
LogUtils.info(log, LogEvents.ExecutorEvent.RESTART, "The executor {} restart event is received", executorName);
restartES.execute(new Runnable() {
@Override
public void run() {
executeRestartOrDumpCmd("restart", LogEvents.ExecutorEvent.RESTART);
}
});
}
}
});
// Start, with not buildInitial.
// The initial data is null, so the create event will be triggered firstly.
restartNC.start(false);
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project Saturn by vipshop.
the class ZkCacheManager method closeAllNodeCache.
public void closeAllNodeCache() {
Iterator<Entry<String, NodeCache>> iterator = nodeCacheMap.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, NodeCache> next = iterator.next();
NodeCache nc = next.getValue();
String path = next.getKey();
try {
nc.close();
iterator.remove();
LogUtils.info(log, jobName, "{} - {} closed nodeCache, path is {}", executorName, jobName, path);
} catch (Exception e) {
LogUtils.error(log, jobName, e.getMessage(), e);
}
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project Saturn by vipshop.
the class ZkCacheManager method buildAndStartNodeCache.
public NodeCache buildAndStartNodeCache(String path) {
try {
NodeCache nc = nodeCacheMap.get(path);
if (nc == null) {
nc = new NodeCache(client, path);
nodeCacheMap.put(path, nc);
nc.start();
LogUtils.info(log, jobName, "{} - {} builds nodeCache for path = {}", executorName, jobName, path);
}
return nc;
} catch (Exception e) {
LogUtils.error(log, jobName, "{} - {} fails in building nodeCache for path = {}, saturn will not work correctly.", executorName, jobName, path);
LogUtils.error(log, jobName, e.getMessage(), e);
}
return null;
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project Saturn by vipshop.
the class ZkCacheManager method closeNodeCache.
public void closeNodeCache(String path) {
NodeCache nc = nodeCacheMap.get(path);
if (nc != null) {
try {
nc.close();
nodeCacheMap.remove(path);
LogUtils.info(log, jobName, "{} - {} closed nodeCache, path is {}", executorName, jobName, path);
} catch (Exception e) {
LogUtils.error(log, jobName, e.getMessage(), e);
}
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project dubbo by alibaba.
the class CuratorZookeeperClient method addTargetDataListener.
@Override
protected void addTargetDataListener(String path, CuratorZookeeperClient.NodeCacheListenerImpl nodeCacheListener, Executor executor) {
try {
NodeCache nodeCache = new NodeCache(client, path);
if (nodeCacheMap.putIfAbsent(path, nodeCache) != null) {
return;
}
if (executor == null) {
nodeCache.getListenable().addListener(nodeCacheListener);
} else {
nodeCache.getListenable().addListener(nodeCacheListener, executor);
}
nodeCache.start();
} catch (Exception e) {
throw new IllegalStateException("Add nodeCache listener for path:" + path, e);
}
}
Aggregations