zoukankan      html  css  js  c++  java
  • curator zookeeper监控。SpiderWatcher

    import java.util.List;
    
    import org.apache.curator.RetryPolicy;
    import org.apache.curator.framework.CuratorFramework;
    import org.apache.curator.framework.CuratorFrameworkFactory;
    import org.apache.curator.retry.ExponentialBackoffRetry;
    import org.apache.zookeeper.WatchedEvent;
    import org.apache.zookeeper.Watcher;
    
    public class SpiderWatcher implements Watcher {
        CuratorFramework client = null;
        List<String> list1 = null;
    
        public SpiderWatcher() {
            String connectString = "192.168.14.139:2181";
            int sessionTimeoutMs = 30000;
            int connectionTimeoutMs = 30000;
            RetryPolicy retryPolicy = new ExponentialBackoffRetry(5000, 3);
            client = CuratorFrameworkFactory.newClient(connectString, sessionTimeoutMs, connectionTimeoutMs, retryPolicy);
            client.start();
            try {
                list1 = client.getChildren().usingWatcher(this).forPath("/dddd");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        @Override
        public void process(WatchedEvent arg0) {
            try {
                List<String> list2 = client.getChildren().usingWatcher(this).forPath("/dddd");
                for (String znode : list1) {
                    if (!list2.contains(znode)) {
                        System.out.println("删除");
                    }
                }
                for (String znode : list2) {
                    if (!list1.contains(znode)) {
                        System.out.println("新增");
                    }
                }
                list1 = list2;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public void stayAlive() {
            for (;;) {
            }
        }
    
        public static void main(String[] args) throws Exception {
            SpiderWatcher spiderWatcher = new SpiderWatcher();
            spiderWatcher.stayAlive();
        }
    }
  • 相关阅读:
    6.金额中带有逗号不能直接parseFloat
    5-不要在ajax中return false不会生效的
    4.xx is not defined at HTMLAnchorElement.onclick 的问题
    3.git更新地址也更改
    2.文件上传后没有权限不够
    第三章
    oracle-sql
    华为杯 数模
    Learning Dynamic Context Graphs for Predicting Social Events
    图神经网络
  • 原文地址:https://www.cnblogs.com/sysout/p/5463498.html
Copyright © 2011-2022 走看看