use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project hive by apache.
the class TezAmRegistryImpl method populateCache.
public void populateCache(boolean doInvokeListeners) throws IOException {
PathChildrenCache pcc = ensureInstancesCache(0);
populateCache(pcc, doInvokeListeners);
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project hive by apache.
the class HS2ActivePassiveHARegistry method populateCache.
private void populateCache() throws IOException {
PathChildrenCache pcc = ensureInstancesCache(0);
populateCache(pcc, false);
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project druid by alibaba.
the class ZookeeperNodeListener method init.
/**
* Init a PathChildrenCache to watch the given path.
*/
@Override
public void init() {
checkParameters();
super.init();
if (client == null) {
client = CuratorFrameworkFactory.builder().canBeReadOnly(true).connectionTimeoutMs(5000).connectString(zkConnectString).retryPolicy(new RetryForever(10000)).sessionTimeoutMs(30000).build();
client.start();
privateZkClient = true;
}
cache = new PathChildrenCache(client, path, true);
cache.getListenable().addListener(new PathChildrenCacheListener() {
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
try {
LOG.info("Receive an event: " + event.getType());
lock.lock();
PathChildrenCacheEvent.Type eventType = event.getType();
switch(eventType) {
case CHILD_REMOVED:
updateSingleNode(event, NodeEventTypeEnum.DELETE);
break;
case CHILD_ADDED:
updateSingleNode(event, NodeEventTypeEnum.ADD);
break;
case CONNECTION_RECONNECTED:
refreshAllNodes();
break;
default:
// CHILD_UPDATED
// INITIALIZED
// CONNECTION_LOST
// CONNECTION_SUSPENDED
LOG.info("Received a PathChildrenCacheEvent, IGNORE it: " + event);
}
} finally {
lock.unlock();
LOG.info("Finish the processing of event: " + event.getType());
}
}
});
try {
// Use BUILD_INITIAL_CACHE to force build cache in the current Thread.
// We don't use POST_INITIALIZED_EVENT, so there's no INITIALIZED event.
cache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
} catch (Exception e) {
LOG.error("Can't start PathChildrenCache", e);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project pravega by pravega.
the class ZooKeeperBucketService method startBucketChangeListener.
@Override
public void startBucketChangeListener() {
PathChildrenCacheListener bucketListener = (client, event) -> {
StreamImpl stream;
switch(event.getType()) {
case CHILD_ADDED:
case CHILD_UPDATED:
stream = bucketStore.getStreamFromPath(event.getData().getPath());
notify(new StreamNotification(stream.getScope(), stream.getStreamName(), NotificationType.StreamAdded));
break;
case CHILD_REMOVED:
stream = bucketStore.getStreamFromPath(event.getData().getPath());
notify(new StreamNotification(stream.getScope(), stream.getStreamName(), NotificationType.StreamRemoved));
break;
case CONNECTION_LOST:
notify(new StreamNotification(null, null, NotificationType.ConnectivityError));
break;
default:
log.warn("Received unknown event {} on bucket", event.getType(), getBucketId());
}
};
PathChildrenCache pathChildrenCache = cacheRef.updateAndGet(existing -> {
if (existing == null) {
PathChildrenCache cache = bucketStore.getBucketPathChildrenCache(getServiceType(), getBucketId());
cache.getListenable().addListener(bucketListener);
log.info("bucket {} change notification listener registered", getBucketId());
return cache;
} else {
return existing;
}
});
try {
pathChildrenCache.start(PathChildrenCache.StartMode.NORMAL);
} catch (Exception e) {
log.error("{}: Starting listener on bucket {} threw exception", getServiceType(), getBucketId(), e);
throw Exceptions.sneakyThrow(e);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project pravega by pravega.
the class ZooKeeperBucketManager method stopBucketOwnershipListener.
@Override
public void stopBucketOwnershipListener() {
PathChildrenCache pathChildrenCache = bucketOwnershipCacheMap.remove(getServiceType());
if (pathChildrenCache != null) {
try {
pathChildrenCache.clear();
pathChildrenCache.close();
} catch (IOException e) {
log.warn("unable to close listener for bucket ownership", e);
}
}
}
Aggregations