use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project Mycat_plus by coderczp.
the class ZKUtils method addChildPathCache.
public static void addChildPathCache(String path, PathChildrenCacheListener listener) {
NameableExecutor businessExecutor = MycatServer.getInstance().getBusinessExecutor();
ExecutorService executor = businessExecutor == null ? Executors.newFixedThreadPool(5) : businessExecutor;
try {
/**
* 监听子节点的变化情况
*/
final PathChildrenCache childrenCache = new PathChildrenCache(getConnection(), path, true);
childrenCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
childrenCache.getListenable().addListener(listener, executor);
watchMap.put(path, childrenCache);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project dble by actiontech.
the class ZKUtils method addChildPathCache.
public static void addChildPathCache(String path, PathChildrenCacheListener listener) {
try {
// watch the child status
final PathChildrenCache childrenCache = new PathChildrenCache(getConnection(), path, true);
childrenCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
childrenCache.getListenable().addListener(listener);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project nakadi by zalando.
the class EventTypeCache method setupCacheSync.
private static PathChildrenCache setupCacheSync(final CuratorFramework zkClient) throws Exception {
try {
zkClient.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(ZKNODE_PATH);
} catch (final KeeperException.NodeExistsException expected) {
// silently do nothing since it means that the node is already there
}
final PathChildrenCache cacheSync = new PathChildrenCache(zkClient, ZKNODE_PATH, false);
// It is important to preload all data before specifying callback for updates, because otherwise preload won't
// give any effect - all changes will be removed.
cacheSync.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
return cacheSync;
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project nakadi by zalando.
the class ConsumerLimitingService method deleteCacheIfPossible.
private void deleteCacheIfPossible(final ConnectionSlot slot) throws IOException {
final boolean hasMoreConnectionsToPartition = ACQUIRED_SLOTS.stream().anyMatch(s -> s.getPartition().equals(slot.getPartition()) && s.getClient().equals(slot.getClient()) && s.getEventType().equals(slot.getEventType()));
if (!hasMoreConnectionsToPartition) {
final String consumerPath = zkPathForConsumer(slot.getClient(), slot.getEventType(), slot.getPartition());
final PathChildrenCache cache = SLOTS_CACHES.remove(consumerPath);
if (cache != null) {
cache.close();
}
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project spring-integration by spring-projects.
the class ZookeeperMetadataStore method start.
@Override
public void start() {
if (!this.running) {
synchronized (this.lifecycleMonitor) {
if (!this.running) {
try {
this.client.checkExists().creatingParentContainersIfNeeded().forPath(this.root);
this.cache = new PathChildrenCache(this.client, this.root, true);
this.cache.getListenable().addListener(new MetadataStoreListenerInvokingPathChildrenCacheListener());
this.cache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
this.running = true;
} catch (Exception e) {
throw new ZookeeperMetadataStoreException("Exception while starting bean", e);
}
}
}
}
}
Aggregations