Search in sources :

Example 56 with PathChildrenCache

use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project BRFS by zhangnianli.

the class FileNodeDistributor method serviceAdded.

@Override
public void serviceAdded(Service service) {
    LOG.info("Service added#######{}", service.getServiceId());
    serviceTimeTable.put(service.getServiceGroup(), service.getServiceId(), service.getRegisterTime());
    if (!childWatchers.containsKey(service.getServiceId())) {
        try {
            PathChildrenCache childWatcher = new PathChildrenCache(client, ZkFileCoordinatorPaths.buildServiceSinkPath(service), false);
            childWatcher.getListenable().addListener(new PathChildrenCacheListener() {

                @Override
                public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
                    LOG.info("happen event !!!");
                    executor.submit(new Runnable() {

                        @Override
                        public void run() {
                            dispatchWildFileNode();
                        }
                    });
                }
            });
            childWatcher.start();
            childWatchers.put(service.getServiceId(), childWatcher);
        } catch (Exception e) {
            LOG.error("create path child cache error for {}", service, e);
        }
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) PathChildrenCacheEvent(org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException)

Example 57 with PathChildrenCache

use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project BRFS by zhangnianli.

the class ZkFileNodeSinkManager method registerFileNodeSink.

@Override
public void registerFileNodeSink(FileNodeSink sink) {
    // PathChildrenCache会自动创建sink节点所在的路径
    PathChildrenCache sinkWatcher = new PathChildrenCache(client, ZkFileCoordinatorPaths.buildSinkPath(service, sink.getStorageRegion().getName()), true);
    sinkWatcher.getListenable().addListener(new SinkNodeListener(sink));
    try {
        sinkWatcher.start();
        fileNodeSinks.put(sink.getStorageRegion().getName(), sinkWatcher);
    } catch (Exception e) {
        LOG.error("register file node sink for region[{}] error!", sink.getStorageRegion().getName(), e);
    }
}
Also used : PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache)

Example 58 with PathChildrenCache

use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project BRFS by zhangnianli.

the class ZkFileNodeSinkManager method unregisterFileNodeSink.

@Override
public void unregisterFileNodeSink(FileNodeSink sink) {
    PathChildrenCache sinkWatcher = fileNodeSinks.get(sink.getStorageRegion().getName());
    if (sinkWatcher != null) {
        try {
            sinkWatcher.close();
            client.delete().quietly().deletingChildrenIfNeeded().forPath(ZkFileCoordinatorPaths.buildSinkPath(service, sink.getStorageRegion().getName()));
        } catch (Exception e) {
            LOG.error("unregister file node sink for region[{}] error!", sink.getStorageRegion().getName(), e);
        }
    }
}
Also used : PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache)

Example 59 with PathChildrenCache

use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project dble by actiontech.

the class ZKUtils method addViewPathCache.

public static void addViewPathCache(String path, PathChildrenCacheListener listener) {
    try {
        // watch the child status
        final PathChildrenCache childrenCache = new PathChildrenCache(getConnection(), path, true);
        childrenCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
        childrenCache.getListenable().addListener(listener);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache)

Example 60 with PathChildrenCache

use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project druid by druid-io.

the class RemoteTaskRunner method addWorker.

/**
 * When a new worker appears, listeners are registered for status changes associated with tasks assigned to
 * the worker. Status changes indicate the creation or completion of a task.
 * The RemoteTaskRunner updates state according to these changes.
 *
 * @param worker contains metadata for a worker that has appeared in ZK
 * @return future that will contain a fully initialized worker
 */
private ListenableFuture<ZkWorker> addWorker(final Worker worker) {
    log.info("Worker[%s] reportin' for duty!", worker.getHost());
    try {
        cancelWorkerCleanup(worker.getHost());
        final String workerStatusPath = JOINER.join(indexerZkConfig.getStatusPath(), worker.getHost());
        final PathChildrenCache statusCache = workerStatusPathChildrenCacheFactory.make(cf, workerStatusPath);
        final SettableFuture<ZkWorker> retVal = SettableFuture.create();
        final ZkWorker zkWorker = new ZkWorker(worker, statusCache, jsonMapper);
        // Add status listener to the watcher for status changes
        zkWorker.addListener(getStatusListener(worker, zkWorker, retVal));
        zkWorker.start();
        return retVal;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) TimeoutException(java.util.concurrent.TimeoutException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)68 IOException (java.io.IOException)25 CuratorFramework (org.apache.curator.framework.CuratorFramework)21 PathChildrenCacheListener (org.apache.curator.framework.recipes.cache.PathChildrenCacheListener)20 PathChildrenCacheEvent (org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent)14 KeeperException (org.apache.zookeeper.KeeperException)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 ChildData (org.apache.curator.framework.recipes.cache.ChildData)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)6 Before (org.junit.Before)5 Test (org.junit.Test)5 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 ExecutorService (java.util.concurrent.ExecutorService)4 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 Slf4j (lombok.extern.slf4j.Slf4j)4 ZKPaths (org.apache.curator.utils.ZKPaths)4 Preconditions (com.google.common.base.Preconditions)3 StreamImpl (io.pravega.client.stream.impl.StreamImpl)3 CompletableFuture (java.util.concurrent.CompletableFuture)3