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);
}
}
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;
}
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();
}
}
}
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);
}
}
}
}
}
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();
}
Aggregations