use of pers.cy.iris.commons.cluster.event.UpdateExceptionEvent 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