use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project pravega by pravega.
the class ZKStreamMetadataStore method unregisterBucketListener.
@Override
public void unregisterBucketListener(int bucket) {
PathChildrenCache cache = bucketCacheMap.remove(bucket);
if (cache != null) {
try {
cache.clear();
cache.close();
} catch (IOException e) {
log.warn("unable to close watch on bucket {} with exception {}", bucket, e);
}
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project pravega by pravega.
the class ZKStreamMetadataStore method registerBucketChangeListener.
@Override
@SneakyThrows
public void registerBucketChangeListener(int bucket, BucketChangeListener listener) {
Preconditions.checkNotNull(listener);
PathChildrenCacheListener bucketListener = (client, event) -> {
StreamImpl stream;
switch(event.getType()) {
case CHILD_ADDED:
stream = getStreamFromPath(event.getData().getPath());
listener.notify(new StreamNotification(stream.getScope(), stream.getStreamName(), NotificationType.StreamAdded));
break;
case CHILD_REMOVED:
stream = getStreamFromPath(event.getData().getPath());
listener.notify(new StreamNotification(stream.getScope(), stream.getStreamName(), NotificationType.StreamRemoved));
break;
case CHILD_UPDATED:
stream = getStreamFromPath(event.getData().getPath());
listener.notify(new StreamNotification(stream.getScope(), stream.getStreamName(), NotificationType.StreamUpdated));
break;
case CONNECTION_LOST:
listener.notify(new StreamNotification(null, null, NotificationType.ConnectivityError));
break;
default:
log.warn("Received unknown event {} on bucket", event.getType(), bucket);
}
};
String bucketRoot = String.format(ZKStoreHelper.BUCKET_PATH, bucket);
bucketCacheMap.put(bucket, new PathChildrenCache(storeHelper.getClient(), bucketRoot, true));
PathChildrenCache pathChildrenCache = bucketCacheMap.get(bucket);
pathChildrenCache.getListenable().addListener(bucketListener);
pathChildrenCache.start(PathChildrenCache.StartMode.NORMAL);
log.info("bucket {} change notification listener registered", bucket);
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project turbo-rpc by hank-whu.
the class ZooKeeperRegister method addRegisterWatcher.
/**
* 当断掉连接又重新连接上时起作用
*
* @param group
* @param app
* @param protocol
* @param serverAddress
* @param serverWeight
*/
private synchronized void addRegisterWatcher(String group, String app, Protocol protocol, HostPort serverAddress, int serverWeight) {
final String path = "/turbo/" + group + "/" + app + "/" + protocol + "/" + HexUtils.toHex(serverAddress.toString().getBytes(StandardCharsets.UTF_8));
if (watcherMap.containsKey(path)) {
return;
}
PathChildrenCache watcher = new PathChildrenCache(client, path, false);
PathChildrenCacheListener pathChildrenCacheListener = new PathChildrenCacheListener() {
private volatile boolean waitForInitializedEvent = true;
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
switch(event.getType()) {
case INITIALIZED:
waitForInitializedEvent = false;
break;
case CONNECTION_RECONNECTED:
if (waitForInitializedEvent) {
return;
}
if (logger.isInfoEnabled()) {
logger.info("获得zk连接尝试重新注册, " + path + ", " + serverAddress + "@" + serverWeight);
}
ZooKeeperRegister.this.register(group, app, protocol, serverAddress, serverWeight);
break;
default:
break;
}
}
};
watcher.getListenable().addListener(pathChildrenCacheListener);
try {
watcher.start(StartMode.POST_INITIALIZED_EVENT);
watcherMap.put(path, watcher);
} catch (Exception e) {
if (logger.isErrorEnabled()) {
logger.error("zk监听失败, " + path, e);
}
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project coprhd-controller by CoprHD.
the class DistributedDataManagerImpl method ensureCacheStarted.
/**
* Use the double-check algorithm to initialize the child path cache for use in limit checking
*/
private void ensureCacheStarted() {
if (_basePathCache == null) {
synchronized (this) {
if (_basePathCache == null) {
try {
_basePathCache = new PathChildrenCache(_zkClient, _basePath, false);
_basePathCache.start();
} catch (Exception ex) {
_basePathCache = null;
_log.error(String.format("%s: error initializing cache; will re-attempt", _basePath), ex);
}
}
}
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project Mycat_plus by coderczp.
the class ZktoXmlMain method runCommandWatch.
/**
* 进行命令的监听操作
* 方法描述
* @param zkConn zk的连接信息
* @param path 路径信息
* @param ZKLISTENER 监控路径信息
* @throws Exception
* @创建日期 2016年9月20日
*/
@SuppressWarnings("resource")
private static void runCommandWatch(final CuratorFramework zkConn, final String path) throws Exception {
PathChildrenCache children = new PathChildrenCache(zkConn, path, true);
CommandPathListener commandListener = new CommandPathListener();
// 移除原来的监听再进行添加
children.getListenable().addListener(commandListener);
children.start();
}
Aggregations