觀察者模式,定義添加修改刪除對應的操做數據庫
系統不少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); } }); }