Search in sources :

Example 11 with PathChildrenCache

use of 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 12 with PathChildrenCache

use of 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 13 with PathChildrenCache

use of 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 14 with PathChildrenCache

use of 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)

Example 15 with PathChildrenCache

use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project drill by axbaretto.

the class TestEphemeralStore method testStoreRegistersDispatcherAndStartsItsClient.

/**
 * This test ensures store subscribes to receive events from underlying client. Dispatcher tests ensures listeners
 * are fired on incoming events. These two sets of tests ensure observer pattern in {@code TransientStore} works fine.
 */
@Test
public void testStoreRegistersDispatcherAndStartsItsClient() throws Exception {
    final StoreWithMockClient<String> store = new StoreWithMockClient<>(config, curator);
    final PathChildrenCache cache = Mockito.mock(PathChildrenCache.class);
    final ZookeeperClient client = store.getClient();
    Mockito.when(client.getCache()).thenReturn(cache);
    final ListenerContainer<PathChildrenCacheListener> container = Mockito.mock(ListenerContainer.class);
    Mockito.when(cache.getListenable()).thenReturn(container);
    store.start();
    Mockito.verify(container).addListener(store.dispatcher);
    Mockito.verify(client).start();
}
Also used : PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) Test(org.junit.Test)

Aggregations

PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)68 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)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 ChildData (org.apache.curator.framework.recipes.cache.ChildData)7 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