<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      ZooKeeper server &&client

      寫了一個關于zookeepeer應用的簡單demo

      服務端定時的向zookeeper集群注冊,客戶端監聽zookeeper服務節點變化,一旦變化,立刻響應,更新服務端列表

      服務端代碼:

      #include <zookeeper/zookeeper.h>
      #include <zookeeper/zookeeper_log.h>
      #include <iostream>
      
      using namespace std;
      
       zhandle_t* zkhandle = NULL;
       const char* host = "10.7.18.31:2181,10.7.18.199:2181";
       int timeout = 20000;
       
      void InitWatch(zhandle_t* zh, int type, int state, const char* path, void* watcher) {
        if (type == ZOO_SESSION_EVENT) {
          if (state == ZOO_CONNECTED_STATE) {
            cout << "build connection ok" << endl;
          } else if (state == ZOO_EXPIRED_SESSION_STATE) {
            cout << "connection disconnect" << endl;
            zkhandle = zookeeper_init(host, InitWatch, timeout, 0, const_cast<char*>("TODO"), 0);
          }
        }
      }
      
      void CreateWatch(int rc, const char *name, const void *data) {
        if (rc == ZNODEEXISTS || rc == ZOK) {
          if (rc == ZOK) {
            cout << "registry ok" << endl;
          } else {
            cout << "node exist" << endl;
          }
        } else {
          cout << "registry error" << endl;
        }
      }
      
      int main(int argc, char* argv[]) {
        zoo_set_debug_level(ZOO_LOG_LEVEL_WARN);
        zhandle_t* zkhandle = NULL;
        zkhandle = zookeeper_init(host, InitWatch, timeout, 0, const_cast<char*>("TODO"), 0);
        if (NULL == zkhandle) {
          cout << "zookeeper init error" << endl;
          return 0;
        }
       while (1) {
        int ret = zoo_acreate(zkhandle, "/cluster/index+endpoint", "", 8, &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL, CreateWatch, "create");
        if (ret) {
          cout << "zoo_acreate error :" << ret << endl;
        }
        sleep(5);
       }
      
       zookeeper_close(zkhandle);
       
       return 0;
      }

      client

      #include <zookeeper/zookeeper.h>
      #include <zookeeper/zookeeper_log.h>
      #include <iostream>
      
      using namespace std;
      
      const char* host = "10.7.18.31:2181,10.7.18.199:2181";
      const int timeout = 2000;
      zhandle_t* zkhandle = NULL;
      
      void InitWatch(zhandle_t* zh, int type, int state, const char* path, void* watcher) {
        if (type == ZOO_SESSION_EVENT) {
          if (state == ZOO_CONNECTED_STATE) {
            cout << "build connection ok" << endl;
          } else if (state == ZOO_EXPIRED_SESSION_STATE) {
            cout << "connection disconnect" << endl;
            zkhandle = zookeeper_init(host, InitWatch, timeout, 0, const_cast<char*>("TODO"), 0);
          }
        }
      }
      
      
      void ChildWatch(zhandle_t* zh, int type, int state, const char* path, void* watcher) {
        if (type == ZOO_CHILD_EVENT) {
          struct String_vector str_vec;
          int ret = zoo_wget_children(zh, "/cluster", ChildWatch, 0, &str_vec);
          if (ret) {
            cout << "zoo_wget_children error :" << ret << endl;
          }
          cout << "endpoint change: " << endl;
          for (int i = 0; i < str_vec.count; ++i) {
            string endpoint = str_vec.data[i]; 
            cout << endpoint << endl;
          }
        }
      }
      
      int main(int argc, char* argv[]) {
        zoo_set_debug_level(ZOO_LOG_LEVEL_WARN);
        if (zkhandle) {
          zookeeper_close(zkhandle);
        }
        zkhandle = zookeeper_init(host, InitWatch, timeout, 0, const_cast<char*>("TODO"), 0);
        if (NULL == zkhandle) {
          cout << "zookeeper init error" << endl;
          return 0;
        }
        while (1) {
          struct String_vector str_vec;
          int ret = zoo_wget_children(zkhandle, "/cluster", ChildWatch, const_cast<char*>(""), &str_vec);
          if (ret) {
            cout << "zoo_wget_children error :" << ret << endl;
          }
          for (int i = 0; i < str_vec.count; ++i) {
            string endpoint = str_vec.data[i]; 
            cout << "init endpoint :" << endpoint << endl;
          }
          sleep(120);
        }
      
        zookeeper_close(zkhandle);
      }

       

      posted @ 2017-05-08 00:20  柳下_MBX  閱讀(852)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 杭锦后旗| 国产老妇伦国产熟女老妇高清| 黄频在线播放观看免费| 国产一区二区日韩经典| 色综合久久天天综线观看| 国产精品十八禁在线观看| 久久久久久亚洲精品a片成人| 一区二区中文字幕av| 亚洲国产精品综合久久网络| 午夜DY888国产精品影院| 国产精品无码一区二区在线| 乱码午夜-极品国产内射| 一区二区不卡国产精品| 亚洲情A成黄在线观看动漫尤物| 久久爱在线视频在线观看| 日韩精品亚洲专在线电影| 厨房与子乱在线观看| 亚洲日韩AV秘 无码一区二区| 久久精品国产亚洲av亚| 国产老女人免费观看黄A∨片| 97人洗澡人人澡人人爽人人模| 北条麻妃42部无码电影| 熟女系列丰满熟妇AV| 国产精品午夜福利免费看| 最近中文字幕日韩有码| 自拍偷在线精品自拍偷99| 91福利视频一区二区| 精品人妻无码一区二区三区| 亚洲精品tv久久久久久久久久| 丁香婷婷无码不卡在线| 无码任你躁久久久久久久| 成人午夜免费无码视频在线观看| 99久久精品看国产一区| 自偷自拍亚洲综合精品| 日韩深夜视频在线观看| 五级黄高潮片90分钟视频| 思思热在线视频精品| 国产伦一区二区三区久久| 亚洲国产成人无码av在线影院| 亚洲欧美日韩成人综合一区| 亚洲国产一区二区精品专|