Search in sources :

Example 31 with NodeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project sofa-ark by alipay.

the class ZookeeperConfigActivator method subscribeIpConfig.

protected void subscribeIpConfig() {
    ipNodeCache = new NodeCache(zkClient, ipResourcePath);
    ipNodeCache.getListenable().addListener(new NodeCacheListener() {

        private int version = -1;

        @Override
        public void nodeChanged() throws Exception {
            if (ipNodeCache.getCurrentData() != null && ipNodeCache.getCurrentData().getStat().getVersion() > version) {
                version = ipNodeCache.getCurrentData().getStat().getVersion();
                String configData = new String(ipNodeCache.getCurrentData().getData());
                ipConfigDeque.add(configData);
                LOGGER.info("Receive ip config data: {}, version is {}.", configData, version);
            }
        }
    });
    try {
        LOGGER.info("Subscribe ip config: {}.", ipResourcePath);
        ipNodeCache.start(true);
    } catch (Exception e) {
        throw new ArkRuntimeException("Failed to subscribe ip resource path.", e);
    }
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) NodeCacheListener(org.apache.curator.framework.recipes.cache.NodeCacheListener) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException) KeeperException(org.apache.zookeeper.KeeperException) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Example 32 with NodeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project sofa-ark by alipay.

the class ZookeeperConfigActivator method subscribeBizConfig.

protected void subscribeBizConfig() {
    bizNodeCache = new NodeCache(zkClient, bizResourcePath);
    bizNodeCache.getListenable().addListener(new NodeCacheListener() {

        private int version = -1;

        @Override
        public void nodeChanged() throws Exception {
            if (bizNodeCache.getCurrentData() != null && bizNodeCache.getCurrentData().getStat().getVersion() > version) {
                version = bizNodeCache.getCurrentData().getStat().getVersion();
                String configData = new String(bizNodeCache.getCurrentData().getData());
                bizConfigDeque.add(configData);
                LOGGER.info("Receive app config data: {}, version is {}.", configData, version);
            }
        }
    });
    try {
        bizNodeCache.start(true);
    } catch (Exception e) {
        throw new ArkRuntimeException("Failed to subscribe resource path.", e);
    }
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) NodeCacheListener(org.apache.curator.framework.recipes.cache.NodeCacheListener) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException) KeeperException(org.apache.zookeeper.KeeperException) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Example 33 with NodeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project twister2 by DSC-SPIDAL.

the class ZKJobMasterFinder method getJobMasterIPandPortFromCache.

private String getJobMasterIPandPortFromCache() {
    // if the job master address already retrieved, return it
    if (jobMasterIP != null) {
        return jobMasterIP + ":" + jobMasterPort;
    }
    // if the cache is not started, start it
    if (jobMasterNodeCache == null) {
        jobMasterNodeCache = new NodeCache(client, jobMasterPath);
        try {
            jobMasterNodeCache.start();
        } catch (Exception e) {
            LOG.log(Level.SEVERE, "Exception when starting jobMasterNodeCache", e);
        }
    }
    ChildData currentData = jobMasterNodeCache.getCurrentData();
    if (currentData == null) {
        return null;
    } else {
        String jobMasterIPandPort = new String(currentData.getData());
        setJobMasterIPandPort(jobMasterIPandPort);
        return jobMasterIPandPort;
    }
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) ChildData(org.apache.curator.framework.recipes.cache.ChildData)

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