Search in sources :

Example 1 with NodeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project fabric8 by jboss-fuse.

the class HttpMappingRuleConfiguration method initializeNodeCache.

private void initializeNodeCache(final Map<String, ?> configuration) {
    if (immediateUpdate == true) {
        if (nodeCache == null) {
            final String containerName = fabricService.get().getCurrentContainer().getId();
            final String factoryPid = (String) configuration.get("fabric.zookeeper.pid");
            nodeCache = new NodeCache(curator.get(), ZkPath.CONFIG_CONTAINER.getPath(containerName));
            nodeCache.getListenable().addListener(new NodeCacheListener() {

                @Override
                public void nodeChanged() throws Exception {
                    LOG.info("Detected version change in container {} with http gateway profile {}.", containerName, factoryPid);
                    updateConfiguration(configuration);
                }
            });
            try {
                nodeCache.start();
                LOG.info("Enabling immediateUpdate in HTTP Gateway on container {} for factoryPid={}.", containerName, factoryPid);
            } catch (Exception e) {
                LOG.warn("Possible problems when enabling immediateUpdate in HTTP Gateway rule", e);
            }
        }
    } else {
        if (nodeCache != null) {
            try {
                LOG.info("Disabling immediateUpdate in HTTP Gateway");
                nodeCache.close();
                nodeCache = null;
            } catch (IOException e) {
                LOG.warn("Possible problems when disabling immediateUpdate in HTTP Gateway", e);
            }
        }
    }
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) NodeCacheListener(org.apache.curator.framework.recipes.cache.NodeCacheListener) IOException(java.io.IOException) IOException(java.io.IOException)

Example 2 with NodeCache

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

the class ZktoXmlMain method loadZkWatch.

private static void loadZkWatch(Set<String> setPaths, final CuratorFramework zkConn, final ZookeeperProcessListen zkListen) throws Exception {
    if (null != setPaths && !setPaths.isEmpty()) {
        for (String path : setPaths) {
            // 进行本地节点的监控操作
            NodeCache node = runWatch(zkConn, path, zkListen);
            node.start();
            LOGGER.info("ZktoxmlMain loadZkWatch path:" + path + " regist success");
        }
    }
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache)

Example 3 with NodeCache

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

the class ZktoXmlMain method runWatch.

/**
 * 进行zk的watch操作
 * 方法描述
 * @param zkConn zk的连接信息
 * @param path 路径信息
 * @param zkListen 监控路径信息
 * @throws Exception
 * @创建日期 2016年9月20日
 */
private static NodeCache runWatch(final CuratorFramework zkConn, final String path, final ZookeeperProcessListen zkListen) throws Exception {
    final NodeCache cache = new NodeCache(zkConn, path);
    NodeCacheListener listen = new NodeCacheListener() {

        @Override
        public void nodeChanged() throws Exception {
            LOGGER.info("ZktoxmlMain runWatch  process path  event start ");
            LOGGER.info("NodeCache changed, path is: " + cache.getCurrentData().getPath());
            String notPath = cache.getCurrentData().getPath();
            // 进行通知更新
            zkListen.notifly(notPath);
            LOGGER.info("ZktoxmlMain runWatch  process path  event over");
        }
    };
    // 添加监听
    cache.getListenable().addListener(listen);
    return cache;
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) NodeCacheListener(org.apache.curator.framework.recipes.cache.NodeCacheListener)

Example 4 with NodeCache

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

the class ZktoXmlMain method loadZkWatch.

private static void loadZkWatch(Set<String> setPaths, final CuratorFramework zkConn, final ZookeeperProcessListen zkListen) throws Exception {
    if (null != setPaths && !setPaths.isEmpty()) {
        for (String path : setPaths) {
            final NodeCache node = new NodeCache(zkConn, path);
            node.start(true);
            runWatch(node, zkListen);
            LOGGER.info("ZktoxmlMain loadZkWatch path:" + path + " regist success");
        }
    }
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache)

Example 5 with NodeCache

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

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 (Exception e) {
        ThreadUtils.checkInterrupted(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)

Aggregations

NodeCache (org.apache.curator.framework.recipes.cache.NodeCache)31 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 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 ChildData (org.apache.curator.framework.recipes.cache.ChildData)1 CuratorFrameworkWithUnhandledErrorListener (org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener)1 LeaderRetrievalDriver (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalDriver)1