Search in sources :

Example 21 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 removeListener.

public void removeListener(String path, TreeCacheListener listener) {
    LOG.info("remove listener for tree:" + path);
    TreeCache cache = cacheMap.get(path);
    if (cache != null) {
        cache.getListenable().removeListener(listener);
    }
}
Also used : TreeCache(org.apache.curator.framework.recipes.cache.TreeCache)

Example 22 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 addTreeCacheListenerIfAbsent.

public TreeCacheListener addTreeCacheListenerIfAbsent(String path, int depth, TreeCacheListener treeCacheListener) {
    synchronized (this) {
        TreeCacheListener treeCacheListenerOld = null;
        String key = getKey(path, depth);
        TreeCache treeCache = treeCacheMap.get(key);
        if (treeCache == null) {
            logger.error("The TreeCache is not exists, cannot add TreeCacheListener, path is {}, depth is {}", path, depth);
        } else {
            List<TreeCacheListener> treeCacheListeners = treeCacheListenerMap.get(treeCache);
            boolean included = false;
            for (TreeCacheListener tmp : treeCacheListeners) {
                Class<? extends TreeCacheListener> tmpClass = tmp.getClass();
                Class<? extends TreeCacheListener> treeCacheListenerClass = treeCacheListener.getClass();
                if (tmpClass.equals(treeCacheListenerClass)) {
                    treeCacheListenerOld = tmp;
                    included = true;
                    break;
                }
            }
            if (included) {
                logger.info("The TreeCache has already included the instance of listener, will not be added, path is {}, depth is {}, listener is {}", path, depth, treeCacheListener.getClass());
            } else {
                treeCacheListeners.add(treeCacheListener);
                treeCache.getListenable().addListener(treeCacheListener);
            }
        }
        return treeCacheListenerOld;
    }
}
Also used : TreeCache(org.apache.curator.framework.recipes.cache.TreeCache) TreeCacheListener(org.apache.curator.framework.recipes.cache.TreeCacheListener)

Example 23 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 closeAllTreeCache.

public void closeAllTreeCache() {
    Iterator<Entry<String, TreeCache>> iterator = treeCacheMap.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, TreeCache> next = iterator.next();
        TreeCache tc = next.getValue();
        String path = next.getKey();
        try {
            tc.close();
            iterator.remove();
            LogUtils.info(log, jobName, "{} - {} closed treeCache, path and depth is {}", executorName, jobName, path);
        } catch (Exception e) {
            LogUtils.error(log, jobName, e.getMessage(), e);
        }
    }
}
Also used : Entry(java.util.Map.Entry) TreeCache(org.apache.curator.framework.recipes.cache.TreeCache)

Example 24 with TreeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCache in project paascloud-master by paascloud.

the class ZookeeperRegistryCenter method get.

/**
 * Get string.
 *
 * @param key the key
 *
 * @return the string
 */
@Override
public String get(final String key) {
    TreeCache cache = findTreeCache(key);
    if (null == cache) {
        return getDirectly(key);
    }
    ChildData resultInCache = cache.getCurrentData(key);
    if (null != resultInCache) {
        return null == resultInCache.getData() ? null : new String(resultInCache.getData(), Charsets.UTF_8);
    }
    return getDirectly(key);
}
Also used : TreeCache(org.apache.curator.framework.recipes.cache.TreeCache) ChildData(org.apache.curator.framework.recipes.cache.ChildData)

Example 25 with TreeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCache in project sharding-jdbc by shardingjdbc.

the class ZookeeperRegistryCenter method get.

@Override
public String get(final String key) {
    TreeCache cache = findTreeCache(key);
    if (null == cache) {
        return getDirectly(key);
    }
    ChildData resultInCache = cache.getCurrentData(key);
    if (null != resultInCache) {
        return null == resultInCache.getData() ? null : new String(resultInCache.getData(), Charsets.UTF_8);
    }
    return getDirectly(key);
}
Also used : TreeCache(org.apache.curator.framework.recipes.cache.TreeCache) ChildData(org.apache.curator.framework.recipes.cache.ChildData)

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