use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project Saturn by vipshop.
the class DashboardLeaderTreeCache 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 pravega by pravega.
the class ZKGarbageCollector method registerWatch.
@SneakyThrows(Exception.class)
private NodeCache registerWatch(String watchPath) {
NodeCache nodeCache = new NodeCache(zkStoreHelper.getClient(), watchPath);
NodeCacheListener watchListener = () -> {
currentBatch.set(nodeCache.getCurrentData().getStat().getVersion());
log.debug("Current batch for {} changed to {}", gcName, currentBatch.get());
};
nodeCache.getListenable().addListener(watchListener);
nodeCache.start();
return nodeCache;
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project BRFS by zhangnianli.
the class CuratorNodeCache method addListener.
public void addListener(String path, AbstractNodeCacheListener listener) {
LOG.info("add listener for path:" + path);
NodeCache cache = cacheMap.get(path);
if (cache == null) {
cache = new NodeCache(client.getInnerClient(), path);
cacheMap.put(path, cache);
startCache(path);
}
cache.getListenable().addListener(listener);
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project BRFS by zhangnianli.
the class ServiceDiscoveryImpl method makeNodeCache.
private NodeCache makeNodeCache(final ServiceInstance<T> instance) {
if (!watchInstances) {
return null;
}
final NodeCache nodeCache = new NodeCache(client, pathForInstance(instance.getName(), instance.getId()));
try {
nodeCache.start(true);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return null;
} catch (Exception e) {
log.error("Could not start node cache for: " + instance, e);
}
NodeCacheListener listener = new NodeCacheListener() {
@Override
public void nodeChanged() throws Exception {
if (nodeCache.getCurrentData() != null) {
ServiceInstance<T> newInstance = serializer.deserialize(nodeCache.getCurrentData().getData());
Entry<T> entry = services.get(newInstance.getId());
if (entry != null) {
synchronized (entry) {
entry.service = newInstance;
}
}
} else {
log.warn("Instance data has been deleted for: " + instance);
}
}
};
nodeCache.getListenable().addListener(listener);
return nodeCache;
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project Saturn by vipshop.
the class ExecutorConfigService method start.
public void start() throws Exception {
validateAndInitExecutorConfig();
nodeCache = new NodeCache(curatorFramework.usingNamespace(null), EXECUTOR_CONFIG_PATH);
nodeCache.getListenable().addListener(new NodeCacheListener() {
@Override
public void nodeChanged() throws Exception {
// Watch create, update event
try {
final ChildData currentData = nodeCache.getCurrentData();
if (currentData == null) {
return;
}
String configStr = null;
byte[] data = currentData.getData();
if (data != null && data.length > 0) {
configStr = new String(data, "UTF-8");
}
LogUtils.info(log, LogEvents.ExecutorEvent.INIT, "The path {} created or updated event is received by {}, the data is {}", EXECUTOR_CONFIG_PATH, executorName, configStr);
if (StringUtils.isBlank(configStr)) {
executorConfig = executorConfigClass.newInstance();
} else {
executorConfig = JsonUtils.getGson().fromJson(configStr, executorConfigClass);
}
} catch (Throwable t) {
LogUtils.error(log, LogEvents.ExecutorEvent.INIT, t.toString(), t);
}
}
});
nodeCache.start(false);
}
Aggregations