Search in sources :

Example 76 with PathChildrenCache

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

the class ZkDiscoveryService method initZkClient.

private void initZkClient() {
    try {
        client = CuratorFrameworkFactory.newClient(zkUrl, zkSessionTimeout, zkConnectionTimeout, new RetryForever(zkRetryInterval));
        client.start();
        client.blockUntilConnected();
        cache = new PathChildrenCache(client, zkNodesDir, true);
        cache.getListenable().addListener(this);
        cache.start();
        stopped = false;
        log.info("ZK client connected");
    } catch (Exception e) {
        log.error("Failed to connect to ZK: {}", e.getMessage(), e);
        CloseableUtils.closeQuietly(cache);
        CloseableUtils.closeQuietly(client);
        throw new RuntimeException(e);
    }
}
Also used : PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) RetryForever(org.apache.curator.retry.RetryForever) NoSuchElementException(java.util.NoSuchElementException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) 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