Search in sources :

Example 11 with NodeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project Saturn by vipshop.

the class RestartAndDumpService method initDump.

private void initDump() throws Exception {
    dumpES = Executors.newSingleThreadExecutor(new SaturnThreadFactory(executorName + "-dump-watcher-thread", false));
    final String nodePath = SaturnExecutorsNode.EXECUTORS_ROOT + "/" + executorName + "/dump";
    coordinatorRegistryCenter.remove(nodePath);
    dumpNC = new NodeCache(curatorFramework, nodePath);
    dumpNC.getListenable().addListener(new NodeCacheListener() {

        @Override
        public void nodeChanged() throws Exception {
            // Watch create, update event
            if (dumpNC.getCurrentData() != null) {
                LogUtils.info(log, LogEvents.ExecutorEvent.DUMP, "The executor {} dump event is received", executorName);
                dumpES.execute(new Runnable() {

                    @Override
                    public void run() {
                        executeRestartOrDumpCmd("dump", LogEvents.ExecutorEvent.DUMP);
                        coordinatorRegistryCenter.remove(nodePath);
                    }
                });
            }
        }
    });
    dumpNC.start(false);
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) NodeCacheListener(org.apache.curator.framework.recipes.cache.NodeCacheListener) SaturnThreadFactory(com.vip.saturn.job.threads.SaturnThreadFactory) SaturnJobException(com.vip.saturn.job.exception.SaturnJobException)

Example 12 with NodeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project Saturn by vipshop.

the class DashboardLeaderHandler method createNodeCache.

private void createNodeCache() throws Exception {
    executorService = Executors.newSingleThreadExecutor(new ConsoleThreadFactory("nodeCache-for-dashboardLeaderHost-" + zkAlias, false));
    nodeCache = new NodeCache(curatorFramework, SaturnSelfNodePath.SATURN_CONSOLE_DASHBOARD_LEADER_HOST);
    nodeCache.start();
    nodeCache.getListenable().addListener(new NodeCacheListener() {

        @Override
        public void nodeChanged() throws Exception {
            electLeaderIfNecessary();
        }
    }, executorService);
}
Also used : ConsoleThreadFactory(com.vip.saturn.job.console.utils.ConsoleThreadFactory) NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) NodeCacheListener(org.apache.curator.framework.recipes.cache.NodeCacheListener)

Example 13 with NodeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project BRFS by zhangnianli.

the class CuratorNodeCache method removeListener.

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

Example 14 with NodeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project BRFS by zhangnianli.

the class CuratorNodeCache method cancelListener.

public void cancelListener(String path) throws IOException {
    LOG.info("cancel listener for path:" + path);
    NodeCache cache = cacheMap.get(path);
    if (cache != null) {
        cache.close();
        cacheMap.remove(path);
    }
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache)

Example 15 with NodeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project zipkin by openzipkin.

the class ZooKeeperCollectorSampler method targetStoreRate.

/** read-only */
static AtomicInteger targetStoreRate(CuratorFramework client, Builder builder, Closer closer) {
    String targetStoreRatePath = ensureExists(client, builder.basePath + "/targetStoreRate");
    NodeCache cache = closer.register(new NodeCache(client, targetStoreRatePath));
    try {
        cache.start();
    } catch (Exception e) {
        throw new IllegalStateException("Error starting cache for " + targetStoreRatePath, e);
    }
    AtomicInteger targetStoreRate = new AtomicInteger();
    cache.getListenable().addListener(() -> {
        byte[] bytes = cache.getCurrentData().getData();
        if (bytes.length == 0)
            return;
        try {
            targetStoreRate.set(Integer.valueOf(new String(bytes, UTF_8)));
        } catch (NumberFormatException e) {
            log.warn("Error parsing target store rate {}", e.getMessage());
            return;
        }
    });
    return targetStoreRate;
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOException(java.io.IOException)

Aggregations

NodeCache (org.apache.curator.framework.recipes.cache.NodeCache)32 NodeCacheListener (org.apache.curator.framework.recipes.cache.NodeCacheListener)14 IOException (java.io.IOException)6 KeeperException (org.apache.zookeeper.KeeperException)6 TimeoutException (java.util.concurrent.TimeoutException)3 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)2 ConsoleThreadFactory (com.vip.saturn.job.console.utils.ConsoleThreadFactory)2 SaturnJobException (com.vip.saturn.job.exception.SaturnJobException)2 SaturnThreadFactory (com.vip.saturn.job.threads.SaturnThreadFactory)2 ChildData (org.apache.curator.framework.recipes.cache.ChildData)2 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)2 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)2 SaturnExecutorException (com.vip.saturn.job.exception.SaturnExecutorException)1 Entry (java.util.Map.Entry)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 SneakyThrows (lombok.SneakyThrows)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 CuratorFrameworkWithUnhandledErrorListener (org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener)1 LeaderRetrievalDriver (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalDriver)1