use of org.apache.curator.framework.recipes.cache.ChildData in project hive by apache.
the class ZkRegistryBase method populateCache.
protected final void populateCache(PathChildrenCache instancesCache, boolean doInvokeListeners) {
for (ChildData childData : instancesCache.getCurrentData()) {
byte[] data = getWorkerData(childData, workerNodePrefix);
if (data == null)
continue;
String nodeName = extractNodeName(childData);
if (!nodeName.startsWith(workerNodePrefix))
continue;
int ephSeqVersion = extractSeqNum(nodeName);
try {
ServiceRecord srv = encoder.fromBytes(childData.getPath(), data);
InstanceType instance = createServiceInstance(srv);
addToCache(childData.getPath(), instance.getHost(), instance);
if (doInvokeListeners) {
for (ServiceInstanceStateChangeListener<InstanceType> listener : stateChangeListeners) {
listener.onCreate(instance, ephSeqVersion);
}
}
} catch (IOException e) {
LOG.error("Unable to decode data for zkpath: {}." + " Ignoring from current instances list..", childData.getPath());
}
}
}
use of org.apache.curator.framework.recipes.cache.ChildData in project paascloud-master by paascloud.
the class ZookeeperRegistryCenter method get.
/**
* Get string.
*
* @param key the key
*
* @return the string
*/
@Override
public String get(final String key) {
TreeCache cache = findTreeCache(key);
if (null == cache) {
return getDirectly(key);
}
ChildData resultInCache = cache.getCurrentData(key);
if (null != resultInCache) {
return null == resultInCache.getData() ? null : new String(resultInCache.getData(), Charsets.UTF_8);
}
return getDirectly(key);
}
use of org.apache.curator.framework.recipes.cache.ChildData in project paascloud-master by paascloud.
the class MqConsumerChangeListener method childEvent.
/**
* Child event.
*
* @param client the client
* @param event the event
*/
@Override
public void childEvent(final CuratorFramework client, final TreeCacheEvent event) {
ChildData data = event.getData();
if (data == null) {
return;
}
String path = data.getPath();
if (GlobalConstant.ZK_REGISTRY_CONSUMER_ROOT_PATH.equals(path) || GlobalConstant.ZK_REGISTRY_CONSUMER_ROOT_PATH.equals(path)) {
return;
}
String[] split = path.split(GlobalConstant.Symbol.SLASH);
String dataStr = new String(data.getData());
switch(event.getType()) {
case NODE_ADDED:
log.info("MqConsumerChangeListener CHILD_ADDED path={}, data={}", path, dataStr);
if (split.length == GlobalConstant.Number.SIX_INT) {
String appPath = path.substring(0, path.lastIndexOf(GlobalConstant.Symbol.SLASH));
ReliableMessageRegisterDto dto = JSON.parseObject(getDirectly(client, appPath), ReliableMessageRegisterDto.class);
if (this.getNumChildrenCount(client, appPath) > 0) {
tpcMqConsumerService.updateOnLineStatusByCid(dto.getConsumerGroup());
MqProducerBeanFactory.putCid(dto.getConsumerGroup());
}
}
break;
case NODE_REMOVED:
log.info("MqConsumerChangeListener NODE_REMOVED path={}, data={}", path, dataStr);
if (split.length == GlobalConstant.Number.SIX_INT) {
String appPath = path.substring(0, path.lastIndexOf(GlobalConstant.Symbol.SLASH));
ReliableMessageRegisterDto dto = JSON.parseObject(getDirectly(client, appPath), ReliableMessageRegisterDto.class);
if (this.getNumChildrenCount(client, appPath) < 1) {
tpcMqConsumerService.updateOffLineStatusByCid(dto.getConsumerGroup());
MqProducerBeanFactory.rmCid(dto.getConsumerGroup());
}
}
break;
case NODE_UPDATED:
log.error("MqConsumerChangeListener 本次版本不对更新做处理, path={}, data={}", path, new String(data.getData()));
break;
default:
break;
}
}
Aggregations