Search in sources :

Example 6 with NodeCache

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

the class AbstractZkSubscriptionClient method subscribeForCursorsReset.

@Override
public final Closeable subscribeForCursorsReset(final Runnable listener) throws NakadiRuntimeException, UnsupportedOperationException {
    final NodeCache cursorResetCache = new NodeCache(getCurator(), resetCursorPath);
    cursorResetCache.getListenable().addListener(listener::run);
    try {
        cursorResetCache.start();
    } catch (final Exception e) {
        throw new NakadiRuntimeException(e);
    }
    return () -> {
        try {
            cursorResetCache.getListenable().clear();
            cursorResetCache.close();
        } catch (final IOException e) {
            throw new NakadiRuntimeException(e);
        }
    };
}
Also used : NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) IOException(java.io.IOException) RequestInProgressException(org.zalando.nakadi.exceptions.runtime.RequestInProgressException) UnableProcessException(org.zalando.nakadi.exceptions.UnableProcessException) ServiceUnavailableException(org.zalando.nakadi.exceptions.ServiceUnavailableException) OperationInterruptedException(org.zalando.nakadi.exceptions.runtime.OperationInterruptedException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) OperationTimeoutException(org.zalando.nakadi.exceptions.runtime.OperationTimeoutException) ZookeeperException(org.zalando.nakadi.exceptions.runtime.ZookeeperException) NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) ServiceTemporarilyUnavailableException(org.zalando.nakadi.exceptions.runtime.ServiceTemporarilyUnavailableException)

Example 7 with NodeCache

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

the class ZkKeyValueCacheUtil method createNodeCache.

private static NodeCache createNodeCache(String subPath) {
    String fullPath = getFullPath(subPath);
    NodeCache nodeCache = new NodeCache(ZkConnection.client, fullPath);
    try {
        nodeCache.start();
    } catch (Exception e) {
        LOG.error(e);
    }
    nodeCache.getListenable().addListener(() -> {
        String newDataStr = new String(nodeCache.getCurrentData().getData());
        LOG.info("监听到zk缓存取值有变化:" + fullPath + "=" + newDataStr);
        loadingCache.get(subPath).snd = newDataStr;
    });
    return nodeCache;
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) ExecutionException(java.util.concurrent.ExecutionException) KeeperException(org.apache.zookeeper.KeeperException) TimeoutException(java.util.concurrent.TimeoutException)

Example 8 with NodeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project Mycat-Server by MyCATApache.

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 9 with NodeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project Mycat-Server by MyCATApache.

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 10 with NodeCache

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

the class Curator5ZookeeperClient method removeTargetDataListener.

@Override
protected void removeTargetDataListener(String path, Curator5ZookeeperClient.NodeCacheListenerImpl nodeCacheListener) {
    NodeCache nodeCache = nodeCacheMap.get(path);
    if (nodeCache != null) {
        nodeCache.getListenable().removeListener(nodeCacheListener);
    }
    nodeCacheListener.dataListener = null;
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache)

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