Search in sources :

Example 16 with NodeCache

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

the class DashboardLeaderTreeCache 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 17 with NodeCache

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

the class ZKGarbageCollector method registerWatch.

@SneakyThrows(Exception.class)
private NodeCache registerWatch(String watchPath) {
    NodeCache nodeCache = new NodeCache(zkStoreHelper.getClient(), watchPath);
    NodeCacheListener watchListener = () -> {
        currentBatch.set(nodeCache.getCurrentData().getStat().getVersion());
        log.debug("Current batch for {} changed to {}", gcName, currentBatch.get());
    };
    nodeCache.getListenable().addListener(watchListener);
    nodeCache.start();
    return nodeCache;
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) NodeCacheListener(org.apache.curator.framework.recipes.cache.NodeCacheListener) SneakyThrows(lombok.SneakyThrows)

Example 18 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 addListener.

public void addListener(String path, AbstractNodeCacheListener listener) {
    LOG.info("add listener for path:" + path);
    NodeCache cache = cacheMap.get(path);
    if (cache == null) {
        cache = new NodeCache(client.getInnerClient(), path);
        cacheMap.put(path, cache);
        startCache(path);
    }
    cache.getListenable().addListener(listener);
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache)

Example 19 with NodeCache

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

the class ServiceDiscoveryImpl method makeNodeCache.

private NodeCache makeNodeCache(final ServiceInstance<T> instance) {
    if (!watchInstances) {
        return null;
    }
    final NodeCache nodeCache = new NodeCache(client, pathForInstance(instance.getName(), instance.getId()));
    try {
        nodeCache.start(true);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return null;
    } catch (Exception e) {
        log.error("Could not start node cache for: " + instance, e);
    }
    NodeCacheListener listener = new NodeCacheListener() {

        @Override
        public void nodeChanged() throws Exception {
            if (nodeCache.getCurrentData() != null) {
                ServiceInstance<T> newInstance = serializer.deserialize(nodeCache.getCurrentData().getData());
                Entry<T> entry = services.get(newInstance.getId());
                if (entry != null) {
                    synchronized (entry) {
                        entry.service = newInstance;
                    }
                }
            } else {
                log.warn("Instance data has been deleted for: " + instance);
            }
        }
    };
    nodeCache.getListenable().addListener(listener);
    return nodeCache;
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) NodeCacheListener(org.apache.curator.framework.recipes.cache.NodeCacheListener) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Example 20 with NodeCache

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

the class ExecutorConfigService method start.

public void start() throws Exception {
    validateAndInitExecutorConfig();
    nodeCache = new NodeCache(curatorFramework.usingNamespace(null), EXECUTOR_CONFIG_PATH);
    nodeCache.getListenable().addListener(new NodeCacheListener() {

        @Override
        public void nodeChanged() throws Exception {
            // Watch create, update event
            try {
                final ChildData currentData = nodeCache.getCurrentData();
                if (currentData == null) {
                    return;
                }
                String configStr = null;
                byte[] data = currentData.getData();
                if (data != null && data.length > 0) {
                    configStr = new String(data, "UTF-8");
                }
                LogUtils.info(log, LogEvents.ExecutorEvent.INIT, "The path {} created or updated event is received by {}, the data is {}", EXECUTOR_CONFIG_PATH, executorName, configStr);
                if (StringUtils.isBlank(configStr)) {
                    executorConfig = executorConfigClass.newInstance();
                } else {
                    executorConfig = JsonUtils.getGson().fromJson(configStr, executorConfigClass);
                }
            } catch (Throwable t) {
                LogUtils.error(log, LogEvents.ExecutorEvent.INIT, t.toString(), t);
            }
        }
    });
    nodeCache.start(false);
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) ChildData(org.apache.curator.framework.recipes.cache.ChildData) NodeCacheListener(org.apache.curator.framework.recipes.cache.NodeCacheListener) SaturnExecutorException(com.vip.saturn.job.exception.SaturnExecutorException)

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