观察者模式,定义添加修改删除对应的操做数据库
系统不少Monitor/Listener都是相似ide
Monitor内含listener,调用再触发spa
public synchronized void start() { super.start(); try { processStart(); if (zkClient != null) { // 若是须要尽量释放instance资源,不须要监听running节点,否则即便stop了这台机器,另外一台机器立马会start String path = ZookeeperPathUtils.getDestinationServerRunning(destination); zkClient.subscribeDataChanges(path, dataListener); initRunning(); } else { processActiveEnter();// 没有zk,直接启动 } } catch (Exception e) { logger.error("start failed", e); // 没有正常启动,重置一下状态,避免干扰下一次start stop(); } }
private void processStop() { if (listener != null) { try { listener.processStop(); } catch (Exception e) { logger.error("processStop failed", e); } } }
对生命周期中运行态的判断线程
protected volatile boolean running = false; // 是否处于运行中 public boolean isStart() { return running; }
数据库时间对齐 记录下 str_to_date(concat(date_format(DATE_SUB(now(),interval 1 DAY), '%Y-%m-%d'), ' 23:59:59.999'), '%Y-%m-%d %H:%i:%s.%f')代理
单例code
private static class SingletonHolder { private static final CanalServerWithEmbedded CANAL_SERVER_WITH_EMBEDDED = new CanalServerWithEmbedded(); } public CanalServerWithEmbedded(){ // 但愿也保留用户new单独实例的需求,兼容历史 } public static CanalServerWithEmbedded instance() { return SingletonHolder.CANAL_SERVER_WITH_EMBEDDED; }
代理模式?CanalServerWithNetty起始就是CanalServerWithEmbedded套了个壳orm
捕获并处理一个线程对象中抛出的未检测异常,以免程序终止对象
private static void setGlobalUncaughtExceptionHandler() { Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { logger.error("UnCaughtException", e); } }); }