Search in sources :

Example 1 with InstanceConfigMonitor

use of com.alibaba.otter.canal.deployer.monitor.InstanceConfigMonitor 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)

Example 2 with InstanceConfigMonitor

use of com.alibaba.otter.canal.deployer.monitor.InstanceConfigMonitor in project canal by alibaba.

the class CanalController method stop.

public void stop() throws Throwable {
    canalServer.stop();
    if (autoScan) {
        for (InstanceConfigMonitor monitor : instanceConfigMonitors.values()) {
            if (monitor.isStart()) {
                monitor.stop();
            }
        }
    }
    for (ServerRunningMonitor runningMonitor : ServerRunningMonitors.getRunningMonitors().values()) {
        if (runningMonitor.isStart()) {
            runningMonitor.stop();
        }
    }
    // 释放canal的工作节点
    releaseCid(ZookeeperPathUtils.getCanalClusterNode(ip + ":" + port));
    logger.info("## stop the canal server[{}:{}]", ip, port);
}
Also used : ServerRunningMonitor(com.alibaba.otter.canal.common.zookeeper.running.ServerRunningMonitor) ManagerInstanceConfigMonitor(com.alibaba.otter.canal.deployer.monitor.ManagerInstanceConfigMonitor) SpringInstanceConfigMonitor(com.alibaba.otter.canal.deployer.monitor.SpringInstanceConfigMonitor) InstanceConfigMonitor(com.alibaba.otter.canal.deployer.monitor.InstanceConfigMonitor)

Aggregations

ServerRunningMonitor (com.alibaba.otter.canal.common.zookeeper.running.ServerRunningMonitor)2 InstanceConfigMonitor (com.alibaba.otter.canal.deployer.monitor.InstanceConfigMonitor)2 ManagerInstanceConfigMonitor (com.alibaba.otter.canal.deployer.monitor.ManagerInstanceConfigMonitor)2 SpringInstanceConfigMonitor (com.alibaba.otter.canal.deployer.monitor.SpringInstanceConfigMonitor)2 CanalException (com.alibaba.otter.canal.common.CanalException)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