Search in sources :

Example 61 with PathChildrenCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project dubbo by alibaba.

the class ZKTools method testPathCache.

public static void testPathCache() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", 60 * 1000, 60 * 1000, new ExponentialBackoffRetry(1000, 3));
    client.start();
    PathChildrenCache pathChildrenCache = new PathChildrenCache(client, "/dubbo/config", true);
    pathChildrenCache.start(true);
    pathChildrenCache.getListenable().addListener((zkClient, event) -> {
        System.out.println(event.getData().getPath());
    }, Executors.newFixedThreadPool(1));
    List<ChildData> dataList = pathChildrenCache.getCurrentData();
    dataList.stream().map(ChildData::getPath).forEach(System.out::println);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) ChildData(org.apache.curator.framework.recipes.cache.ChildData)

Aggregations

PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)58 IOException (java.io.IOException)22 CuratorFramework (org.apache.curator.framework.CuratorFramework)20 PathChildrenCacheListener (org.apache.curator.framework.recipes.cache.PathChildrenCacheListener)17 PathChildrenCacheEvent (org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent)13 KeeperException (org.apache.zookeeper.KeeperException)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 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 ExecutorService (java.util.concurrent.ExecutorService)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 ExecutionException (java.util.concurrent.ExecutionException)3 ZKPaths (org.apache.curator.utils.ZKPaths)3 Duration (org.joda.time.Duration)3 Preconditions (com.google.common.base.Preconditions)2 MapMaker (com.google.common.collect.MapMaker)2 CommandPathListener (io.mycat.config.loader.zkprocess.zktoxml.command.CommandPathListener)2