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