Search in sources :

Example 11 with TreeCache

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);
            }
        }
    }
}
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 12 with TreeCache

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;
}
Also used : TreeCache(org.apache.curator.framework.recipes.cache.TreeCache) CloseableExecutorService(org.apache.curator.utils.CloseableExecutorService)

Example 13 with TreeCache

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);
        }
    }
}
Also used : TreeCache(org.apache.curator.framework.recipes.cache.TreeCache)

Example 14 with TreeCache

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);
        }
    }
}
Also used : TreeCache(org.apache.curator.framework.recipes.cache.TreeCache)

Example 15 with TreeCache

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);
}
Also used : TreeCache(org.apache.curator.framework.recipes.cache.TreeCache)

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