Search in sources :

Example 1 with UpdateExceptionEvent

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();
}
Also used : UpdateExceptionEvent(pers.cy.iris.commons.cluster.event.UpdateExceptionEvent) NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) AllBrokerUpdateEvent(pers.cy.iris.commons.cluster.event.AllBrokerUpdateEvent) TopicUpdateEvent(pers.cy.iris.commons.cluster.event.TopicUpdateEvent) NodeCacheListener(org.apache.curator.framework.recipes.cache.NodeCacheListener) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 NodeCache (org.apache.curator.framework.recipes.cache.NodeCache)1 NodeCacheListener (org.apache.curator.framework.recipes.cache.NodeCacheListener)1 AllBrokerUpdateEvent (pers.cy.iris.commons.cluster.event.AllBrokerUpdateEvent)1 TopicUpdateEvent (pers.cy.iris.commons.cluster.event.TopicUpdateEvent)1 UpdateExceptionEvent (pers.cy.iris.commons.cluster.event.UpdateExceptionEvent)1