ivaneeo's blog

          自由的力量,自由的生活。

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks

          常用鏈接

          留言簿(34)

          我參與的團隊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          1. private void buildZK() {  
          2.         System.out.println("Build zk client");  
          3.         try {  
          4.             zk = new ZooKeeper(zookeeperConnectionString, 10000, this);  
          5.             Stat s = zk.exists(rootPath, false);  
          6.             if (s == null) {  
          7.                 zk.create(rootPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);  
          8.                 zk.create(rootPath + "/ELECTION", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);  
          9.             }  
          10.             String value = zk.create(rootPath + "/ELECTION/n_", hostAddress, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);  
          11.         } catch (Exception e) {  
          12.             e.printStackTrace();  
          13.             System.err.println("Error connect to zoo keeper");  
          14.         }  
          15.     }  
          16.   
          17.   
          18.     public void process(WatchedEvent event) {  
          19.         System.out.println(event);  
          20.         if (event.getState() == Event.KeeperState.Disconnected || event.getState() == Event.KeeperState.Expired) {  
          21.             System.out.println("Zookeeper connection timeout.");  
          22.             buildZK();  
          23.         }  
          24.   
          25.     }  
          26.  
          posted on 2011-06-09 13:38 ivaneeo 閱讀(455) 評論(0)  編輯  收藏 所屬分類: java魔力
          主站蜘蛛池模板: 双柏县| 信宜市| 湘西| 萨嘎县| 武威市| 佳木斯市| 南华县| 丰镇市| 长泰县| 定结县| 荃湾区| 定州市| 衡东县| 个旧市| 锦屏县| 沐川县| 治县。| 泉州市| 保定市| 越西县| 饶平县| 赣州市| 壶关县| 天气| 平凉市| 绍兴市| 玉门市| 长武县| 黄冈市| 安国市| 寻乌县| 千阳县| 沙河市| 长沙县| 丽江市| 曲阳县| 运城市| 定襄县| 敖汉旗| 河东区| 兴安盟|