Search in sources :

Example 26 with TreeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCache in project sharding-jdbc by shardingjdbc.

the class ZookeeperRegistryCenter method addCacheData.

private void addCacheData(final String cachePath) {
    TreeCache cache = new TreeCache(client, cachePath);
    try {
        cache.start();
    // CHECKSTYLE:OFF
    } catch (final Exception ex) {
        // CHECKSTYLE:ON
        RegExceptionHandler.handleException(ex);
    }
    caches.put(cachePath + "/", cache);
}
Also used : TreeCache(org.apache.curator.framework.recipes.cache.TreeCache) OperationTimeoutException(org.apache.zookeeper.KeeperException.OperationTimeoutException)

Example 27 with TreeCache

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

the class ZooKeeperUtils method createTreeCache.

/**
 * Creates a {@link TreeCache} that only observes a specific node.
 *
 * @param client ZK client
 * @param pathToNode full path of the node to observe
 * @param nodeChangeCallback callback to run if the node has changed
 * @return tree cache
 */
public static TreeCache createTreeCache(final CuratorFramework client, final String pathToNode, final RunnableWithException nodeChangeCallback) {
    final TreeCache cache = TreeCache.newBuilder(client, pathToNode).setCacheData(true).setCreateParentNodes(false).setSelector(ZooKeeperUtils.treeCacheSelectorForPath(pathToNode)).setExecutor(Executors.newDirectExecutorService()).build();
    cache.getListenable().addListener(createTreeCacheListener(nodeChangeCallback));
    return cache;
}
Also used : TreeCache(org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCache)

Example 28 with TreeCache

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

the class ZooKeeperUtilsTreeCacheTest method setUp.

@Before
public void setUp() throws Exception {
    closer = Closer.create();
    final TestingServer testingServer = closer.register(new TestingServer());
    Configuration configuration = new Configuration();
    configuration.set(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM, testingServer.getConnectString());
    curatorFrameworkWrapper = closer.register(ZooKeeperUtils.startCuratorFramework(configuration, NoOpFatalErrorHandler.INSTANCE));
    client = curatorFrameworkWrapper.asCuratorFramework();
    final TreeCache cache = closer.register(ZooKeeperUtils.createTreeCache(client, CHILD_PATH, () -> callbackFutureReference.get().complete(null)));
    cache.start();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) TreeCache(org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCache) Configuration(org.apache.flink.configuration.Configuration) Before(org.junit.Before)

Aggregations

TreeCache (org.apache.curator.framework.recipes.cache.TreeCache)26 ChildData (org.apache.curator.framework.recipes.cache.ChildData)6 TreeCacheListener (org.apache.curator.framework.recipes.cache.TreeCacheListener)5 CuratorFramework (org.apache.curator.framework.CuratorFramework)3 TreeCacheEvent (org.apache.curator.framework.recipes.cache.TreeCacheEvent)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 CloseableExecutorService (org.apache.curator.utils.CloseableExecutorService)2 TreeCache (org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCache)2 KeeperException (org.apache.zookeeper.KeeperException)2 OperationTimeoutException (org.apache.zookeeper.KeeperException.OperationTimeoutException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ShardingTreeCache (com.vip.saturn.job.sharding.entity.ShardingTreeCache)1 ShardingException (com.vip.saturn.job.sharding.exception.ShardingException)1 DataChangedEvent (io.shardingjdbc.orchestration.reg.listener.DataChangedEvent)1 StandardCharsets (java.nio.charset.StandardCharsets)1 EnumMap (java.util.EnumMap)1 Entry (java.util.Map.Entry)1 CountDownLatch (java.util.concurrent.CountDownLatch)1