use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project Saturn by vipshop.
the class RestartAndDumpService method initDump.
private void initDump() throws Exception {
dumpES = Executors.newSingleThreadExecutor(new SaturnThreadFactory(executorName + "-dump-watcher-thread", false));
final String nodePath = SaturnExecutorsNode.EXECUTORS_ROOT + "/" + executorName + "/dump";
coordinatorRegistryCenter.remove(nodePath);
dumpNC = new NodeCache(curatorFramework, nodePath);
dumpNC.getListenable().addListener(new NodeCacheListener() {
@Override
public void nodeChanged() throws Exception {
// Watch create, update event
if (dumpNC.getCurrentData() != null) {
LogUtils.info(log, LogEvents.ExecutorEvent.DUMP, "The executor {} dump event is received", executorName);
dumpES.execute(new Runnable() {
@Override
public void run() {
executeRestartOrDumpCmd("dump", LogEvents.ExecutorEvent.DUMP);
coordinatorRegistryCenter.remove(nodePath);
}
});
}
}
});
dumpNC.start(false);
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project Saturn by vipshop.
the class DashboardLeaderHandler method createNodeCache.
private void createNodeCache() throws Exception {
executorService = Executors.newSingleThreadExecutor(new ConsoleThreadFactory("nodeCache-for-dashboardLeaderHost-" + zkAlias, false));
nodeCache = new NodeCache(curatorFramework, SaturnSelfNodePath.SATURN_CONSOLE_DASHBOARD_LEADER_HOST);
nodeCache.start();
nodeCache.getListenable().addListener(new NodeCacheListener() {
@Override
public void nodeChanged() throws Exception {
electLeaderIfNecessary();
}
}, executorService);
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project BRFS by zhangnianli.
the class CuratorNodeCache method removeListener.
public void removeListener(String path, AbstractNodeCacheListener listener) {
LOG.info("remove listener for path:" + path);
NodeCache cache = cacheMap.get(path);
if (cache != null) {
cache.getListenable().removeListener(listener);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project BRFS by zhangnianli.
the class CuratorNodeCache method cancelListener.
public void cancelListener(String path) throws IOException {
LOG.info("cancel listener for path:" + path);
NodeCache cache = cacheMap.get(path);
if (cache != null) {
cache.close();
cacheMap.remove(path);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project zipkin by openzipkin.
the class ZooKeeperCollectorSampler method targetStoreRate.
/** read-only */
static AtomicInteger targetStoreRate(CuratorFramework client, Builder builder, Closer closer) {
String targetStoreRatePath = ensureExists(client, builder.basePath + "/targetStoreRate");
NodeCache cache = closer.register(new NodeCache(client, targetStoreRatePath));
try {
cache.start();
} catch (Exception e) {
throw new IllegalStateException("Error starting cache for " + targetStoreRatePath, e);
}
AtomicInteger targetStoreRate = new AtomicInteger();
cache.getListenable().addListener(() -> {
byte[] bytes = cache.getCurrentData().getData();
if (bytes.length == 0)
return;
try {
targetStoreRate.set(Integer.valueOf(new String(bytes, UTF_8)));
} catch (NumberFormatException e) {
log.warn("Error parsing target store rate {}", e.getMessage());
return;
}
});
return targetStoreRate;
}
Aggregations