Search in sources :

Example 1 with IZkStateListener

use of org.I0Itec.zkclient.IZkStateListener in project canal by alibaba.

the class CanalController method start.

public void start() throws Throwable {
    logger.info("## start the canal server[{}:{}]", ip, port);
    // 创建整个canal的工作节点
    final String path = ZookeeperPathUtils.getCanalClusterNode(ip + ":" + port);
    initCid(path);
    if (zkclientx != null) {
        this.zkclientx.subscribeStateChanges(new IZkStateListener() {

            public void handleStateChanged(KeeperState state) throws Exception {
            }

            public void handleNewSession() throws Exception {
                initCid(path);
            }
        });
    }
    // 优先启动embeded服务
    embededCanalServer.start();
    // 尝试启动一下非lazy状态的通道
    for (Map.Entry<String, InstanceConfig> entry : instanceConfigs.entrySet()) {
        final String destination = entry.getKey();
        InstanceConfig config = entry.getValue();
        // 创建destination的工作节点
        if (!embededCanalServer.isStart(destination)) {
            // HA机制启动
            ServerRunningMonitor runningMonitor = ServerRunningMonitors.getRunningMonitor(destination);
            if (!config.getLazy() && !runningMonitor.isStart()) {
                runningMonitor.start();
            }
        }
        if (autoScan) {
            instanceConfigMonitors.get(config.getMode()).register(destination, defaultAction);
        }
    }
    if (autoScan) {
        instanceConfigMonitors.get(globalInstanceConfig.getMode()).start();
        for (InstanceConfigMonitor monitor : instanceConfigMonitors.values()) {
            if (!monitor.isStart()) {
                monitor.start();
            }
        }
    }
    // 启动网络接口
    canalServer.start();
}
Also used : IZkStateListener(org.I0Itec.zkclient.IZkStateListener) ServerRunningMonitor(com.alibaba.otter.canal.common.zookeeper.running.ServerRunningMonitor) KeeperState(org.apache.zookeeper.Watcher.Event.KeeperState) Map(java.util.Map) MigrateMap(com.google.common.collect.MigrateMap) ManagerInstanceConfigMonitor(com.alibaba.otter.canal.deployer.monitor.ManagerInstanceConfigMonitor) SpringInstanceConfigMonitor(com.alibaba.otter.canal.deployer.monitor.SpringInstanceConfigMonitor) InstanceConfigMonitor(com.alibaba.otter.canal.deployer.monitor.InstanceConfigMonitor) CanalServerException(com.alibaba.otter.canal.server.exception.CanalServerException) ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) CanalException(com.alibaba.otter.canal.common.CanalException) ZkNodeExistsException(org.I0Itec.zkclient.exception.ZkNodeExistsException)

Aggregations

CanalException (com.alibaba.otter.canal.common.CanalException)1 ServerRunningMonitor (com.alibaba.otter.canal.common.zookeeper.running.ServerRunningMonitor)1 InstanceConfigMonitor (com.alibaba.otter.canal.deployer.monitor.InstanceConfigMonitor)1 ManagerInstanceConfigMonitor (com.alibaba.otter.canal.deployer.monitor.ManagerInstanceConfigMonitor)1 SpringInstanceConfigMonitor (com.alibaba.otter.canal.deployer.monitor.SpringInstanceConfigMonitor)1 CanalServerException (com.alibaba.otter.canal.server.exception.CanalServerException)1 MigrateMap (com.google.common.collect.MigrateMap)1 Map (java.util.Map)1 IZkStateListener (org.I0Itec.zkclient.IZkStateListener)1 ZkNoNodeException (org.I0Itec.zkclient.exception.ZkNoNodeException)1 ZkNodeExistsException (org.I0Itec.zkclient.exception.ZkNodeExistsException)1 KeeperState (org.apache.zookeeper.Watcher.Event.KeeperState)1