use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project sofa-ark by alipay.
the class ZookeeperConfigActivator method subscribeIpConfig.
protected void subscribeIpConfig() {
ipNodeCache = new NodeCache(zkClient, ipResourcePath);
ipNodeCache.getListenable().addListener(new NodeCacheListener() {
private int version = -1;
@Override
public void nodeChanged() throws Exception {
if (ipNodeCache.getCurrentData() != null && ipNodeCache.getCurrentData().getStat().getVersion() > version) {
version = ipNodeCache.getCurrentData().getStat().getVersion();
String configData = new String(ipNodeCache.getCurrentData().getData());
ipConfigDeque.add(configData);
LOGGER.info("Receive ip config data: {}, version is {}.", configData, version);
}
}
});
try {
LOGGER.info("Subscribe ip config: {}.", ipResourcePath);
ipNodeCache.start(true);
} catch (Exception e) {
throw new ArkRuntimeException("Failed to subscribe ip resource path.", e);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project sofa-ark by alipay.
the class ZookeeperConfigActivator method subscribeBizConfig.
protected void subscribeBizConfig() {
bizNodeCache = new NodeCache(zkClient, bizResourcePath);
bizNodeCache.getListenable().addListener(new NodeCacheListener() {
private int version = -1;
@Override
public void nodeChanged() throws Exception {
if (bizNodeCache.getCurrentData() != null && bizNodeCache.getCurrentData().getStat().getVersion() > version) {
version = bizNodeCache.getCurrentData().getStat().getVersion();
String configData = new String(bizNodeCache.getCurrentData().getData());
bizConfigDeque.add(configData);
LOGGER.info("Receive app config data: {}, version is {}.", configData, version);
}
}
});
try {
bizNodeCache.start(true);
} catch (Exception e) {
throw new ArkRuntimeException("Failed to subscribe resource path.", e);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project twister2 by DSC-SPIDAL.
the class ZKJobMasterFinder method getJobMasterIPandPortFromCache.
private String getJobMasterIPandPortFromCache() {
// if the job master address already retrieved, return it
if (jobMasterIP != null) {
return jobMasterIP + ":" + jobMasterPort;
}
// if the cache is not started, start it
if (jobMasterNodeCache == null) {
jobMasterNodeCache = new NodeCache(client, jobMasterPath);
try {
jobMasterNodeCache.start();
} catch (Exception e) {
LOG.log(Level.SEVERE, "Exception when starting jobMasterNodeCache", e);
}
}
ChildData currentData = jobMasterNodeCache.getCurrentData();
if (currentData == null) {
return null;
} else {
String jobMasterIPandPort = new String(currentData.getData());
setJobMasterIPandPort(jobMasterIPandPort);
return jobMasterIPandPort;
}
}
Aggregations