Search in sources :

Example 11 with PathChildrenCache

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);
    }
}
Also used : PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) IOException(java.io.IOException)

Example 12 with PathChildrenCache

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);
    }
}
Also used : PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache)

Example 13 with PathChildrenCache

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;
}
Also used : PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) KeeperException(org.apache.zookeeper.KeeperException)

Example 14 with PathChildrenCache

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();
        }
    }
}
Also used : PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache)

Example 15 with PathChildrenCache

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);
                }
            }
        }
    }
}
Also used : PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)73 IOException (java.io.IOException)25 CuratorFramework (org.apache.curator.framework.CuratorFramework)21 PathChildrenCacheListener (org.apache.curator.framework.recipes.cache.PathChildrenCacheListener)20 PathChildrenCacheEvent (org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent)14 KeeperException (org.apache.zookeeper.KeeperException)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 ChildData (org.apache.curator.framework.recipes.cache.ChildData)8 CountDownLatch (java.util.concurrent.CountDownLatch)6 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)6 Before (org.junit.Before)5 Test (org.junit.Test)5 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 ExecutorService (java.util.concurrent.ExecutorService)4 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 Slf4j (lombok.extern.slf4j.Slf4j)4 ZKPaths (org.apache.curator.utils.ZKPaths)4 Preconditions (com.google.common.base.Preconditions)3 StreamImpl (io.pravega.client.stream.impl.StreamImpl)3 CompletableFuture (java.util.concurrent.CompletableFuture)3