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);
}
}
}
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);
}
}
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);
}
}
}
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);
}
}
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);
}
}
Aggregations