use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCache in project Saturn by vipshop.
the class ShardingTreeCacheService method addTreeCacheIfAbsent.
public void addTreeCacheIfAbsent(String path, int depth) throws Exception {
synchronized (isShutdownFlag) {
if (isShutdownFlag.get()) {
throw new ShardingException("ShardingTreeCacheService has been shutdown");
}
String fullPath = namespace + path;
if (!shardingTreeCache.containsTreeCache(path, depth)) {
TreeCache treeCache = TreeCache.newBuilder(curatorFramework, path).setExecutor(new CloseableExecutorService(executorService, false)).setMaxDepth(depth).build();
try {
treeCache.start();
} catch (Exception e) {
treeCache.close();
throw e;
}
TreeCache treeCacheOld = shardingTreeCache.putTreeCacheIfAbsent(path, depth, treeCache);
if (treeCacheOld != null) {
treeCache.close();
} else {
LOGGER.info("create TreeCache, full path is {}, depth is {}", fullPath, depth);
}
}
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCache in project Saturn by vipshop.
the class ZkCacheManager method buildAndStartTreeCache.
private TreeCache buildAndStartTreeCache(String path, int depth) {
try {
String key = buildMapKey(path, depth);
TreeCache tc = treeCacheMap.get(key);
if (tc == null) {
tc = TreeCache.newBuilder(client, path).setMaxDepth(depth).setExecutor(new CloseableExecutorService(executorService, false)).build();
treeCacheMap.put(key, tc);
tc.start();
LogUtils.info(log, jobName, "{} - {} builds treeCache for path = {}, depth = {}", executorName, jobName, path, depth);
}
return tc;
} catch (Exception e) {
LogUtils.error(log, jobName, "{} - {} fails in building treeCache for path = {}, depth = {}, saturn will not work correctly.", executorName, jobName, path, depth);
LogUtils.error(log, jobName, e.getMessage(), e);
}
return null;
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCache in project Saturn by vipshop.
the class ZkCacheManager method closeTreeCache.
public void closeTreeCache(String path, int depth) {
String key = buildMapKey(path, depth);
TreeCache tc = treeCacheMap.get(key);
if (tc != null) {
try {
tc.close();
treeCacheMap.remove(key);
LogUtils.info(log, jobName, "{} - {} closed treeCache, path and depth is {}", executorName, jobName, key);
} catch (Exception e) {
LogUtils.error(log, jobName, e.getMessage(), e);
}
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCache in project Saturn by vipshop.
the class ShardingTreeCache method removeTreeCacheByKey.
public void removeTreeCacheByKey(String key) {
synchronized (this) {
TreeCache treeCache = treeCacheMap.get(key);
if (treeCache != null) {
treeCacheListenerMap.remove(treeCache);
treeCacheMap.remove(key);
treeCache.close();
logger.info("remove TreeCache success, path+depth is {}", key);
}
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCache in project BRFS by zhangnianli.
the class CuratorTreeCache method addListener.
public void addListener(String path, TreeCacheListener listener) {
LOG.info("add listener for tree:" + path);
TreeCache cache = cacheMap.get(path);
if (cache == null) {
cache = new TreeCache(client.getInnerClient(), path);
cacheMap.put(path, cache);
startCache(path);
}
cache.getListenable().addListener(listener);
}
Aggregations