use of org.apache.curator.framework.recipes.cache.NodeCacheListener 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;
}
use of org.apache.curator.framework.recipes.cache.NodeCacheListener in project iris by chicc999.
the class MetaManager method doStart.
@Override
public void doStart() throws Exception {
zkClient.start();
//注册broker存活
zkClient.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath(BROKER_LIVE_PATH + System.getProperty(ServerType.Broker.nameKey()) + "_", System.getProperty(ServerType.Broker.nameKey()).getBytes("utf-8"));
//检测并初始化topic路径
if (null == this.zkClient.checkExists().forPath(this.TOPIC_PATH)) {
this.zkClient.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(this.TOPIC_PATH, "[]".getBytes("utf-8"));
}
//注册监听器
if (topicCache == null) {
topicCache = new NodeCache(this.zkClient, this.TOPIC_PATH, false);
topicCache.getListenable().addListener(new NodeCacheListener() {
@Override
public void nodeChanged() {
try {
updateTopic(topicCache.getCurrentData().getData());
//添加topic更新事件
clusterEventManager.add(new TopicUpdateEvent());
} catch (IOException e) {
clusterEventManager.add(new UpdateExceptionEvent(e));
}
}
});
}
//启动监听器
topicCache.start();
//检测并初始化broker路径
if (null == this.zkClient.checkExists().forPath(this.BROKER_PATH)) {
this.zkClient.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(this.BROKER_PATH, "[]".getBytes("utf-8"));
}
//注册监听器
if (brokerCache == null) {
brokerCache = new NodeCache(this.zkClient, this.BROKER_PATH, false);
brokerCache.getListenable().addListener(new NodeCacheListener() {
@Override
public void nodeChanged() {
try {
updateBroker(brokerCache.getCurrentData().getData());
//集群事件管理器添加broker更新事件
clusterEventManager.add(new AllBrokerUpdateEvent());
} catch (IOException e) {
clusterEventManager.add(new UpdateExceptionEvent(e));
}
}
});
}
//启动监听器
brokerCache.start();
clusterEventManager.start();
}
Aggregations