use of org.apache.curator.framework.recipes.cache.ChildData in project flink by apache.
the class ZooKeeperLeaderRetrievalService method nodeChanged.
@Override
public void nodeChanged() throws Exception {
try {
LOG.debug("Leader node has changed.");
ChildData childData = cache.getCurrentData();
String leaderAddress;
UUID leaderSessionID;
if (childData == null) {
leaderAddress = null;
leaderSessionID = null;
} else {
byte[] data = childData.getData();
if (data == null || data.length == 0) {
leaderAddress = null;
leaderSessionID = null;
} else {
ByteArrayInputStream bais = new ByteArrayInputStream(data);
ObjectInputStream ois = new ObjectInputStream(bais);
leaderAddress = ois.readUTF();
leaderSessionID = (UUID) ois.readObject();
}
}
if (!(Objects.equals(leaderAddress, lastLeaderAddress) && Objects.equals(leaderSessionID, lastLeaderSessionID))) {
LOG.debug("New leader information: Leader={}, session ID={}.", leaderAddress, leaderSessionID);
lastLeaderAddress = leaderAddress;
lastLeaderSessionID = leaderSessionID;
leaderListener.notifyLeaderAddress(leaderAddress, leaderSessionID);
}
} catch (Exception e) {
leaderListener.handleError(new Exception("Could not handle node changed event.", e));
throw e;
}
}
use of org.apache.curator.framework.recipes.cache.ChildData in project archaius by Netflix.
the class ZooKeeperConfigurationSource method getCurrentData.
@Override
public Map<String, Object> getCurrentData() throws Exception {
logger.debug("getCurrentData() retrieving current data.");
List<ChildData> children = pathChildrenCache.getCurrentData();
Map<String, Object> all = new HashMap<String, Object>(children.size());
for (ChildData child : children) {
String path = child.getPath();
String key = removeRootPath(path);
byte[] value = child.getData();
all.put(key, new String(value, charset));
}
logger.debug("getCurrentData() retrieved [{}] config elements.", children.size());
return all;
}
use of org.apache.curator.framework.recipes.cache.ChildData in project exhibitor by soabase.
the class ZookeeperConfigProvider method loadConfig.
@Override
public LoadedInstanceConfig loadConfig() throws Exception {
int version = -1;
Properties properties = new Properties();
ChildData childData = getConfigNode();
if (childData != null) {
version = childData.getStat().getVersion();
properties.load(new ByteArrayInputStream(childData.getData()));
}
PropertyBasedInstanceConfig config = new PropertyBasedInstanceConfig(properties, defaults);
return new LoadedInstanceConfig(config, version);
}
Aggregations