Search in sources :

Example 1 with ShardingException

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);
            }
        }
    }
}
Also used : ShardingException(com.vip.saturn.job.sharding.exception.ShardingException) ShardingTreeCache(com.vip.saturn.job.sharding.entity.ShardingTreeCache) TreeCache(org.apache.curator.framework.recipes.cache.TreeCache) CloseableExecutorService(org.apache.curator.utils.CloseableExecutorService) ShardingException(com.vip.saturn.job.sharding.exception.ShardingException)

Example 2 with ShardingException

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);
        }
    }
}
Also used : ShardingException(com.vip.saturn.job.sharding.exception.ShardingException) TreeCacheListener(org.apache.curator.framework.recipes.cache.TreeCacheListener)

Aggregations

ShardingException (com.vip.saturn.job.sharding.exception.ShardingException)2 ShardingTreeCache (com.vip.saturn.job.sharding.entity.ShardingTreeCache)1 TreeCache (org.apache.curator.framework.recipes.cache.TreeCache)1 TreeCacheListener (org.apache.curator.framework.recipes.cache.TreeCacheListener)1 CloseableExecutorService (org.apache.curator.utils.CloseableExecutorService)1