use of com.vip.saturn.job.sharding.exception.ShardingException 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 com.vip.saturn.job.sharding.exception.ShardingException in project Saturn by vipshop.
the class ShardingTreeCacheService method addTreeCacheListenerIfAbsent.
public void addTreeCacheListenerIfAbsent(String path, int depth, TreeCacheListener treeCacheListener) throws ShardingException {
synchronized (isShutdownFlag) {
if (isShutdownFlag.get()) {
throw new ShardingException("ShardingTreeCacheService has been shutdown");
}
String fullPath = namespace + path;
TreeCacheListener treeCacheListenerOld = shardingTreeCache.addTreeCacheListenerIfAbsent(path, depth, treeCacheListener);
if (treeCacheListenerOld == null) {
LOGGER.info("add {}, full path is {}, depth is {}", treeCacheListener.getClass().getSimpleName(), fullPath, depth);
}
}
}
Aggregations