Advertisement
Guest User

Untitled

a guest
Apr 26th, 2011
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var ZK = require ("zookeeper").ZooKeeper;
  2.  
  3. var my_poll = function(zkk, path) {
  4.   zkk.a_get( path , null, function(rc, error, stat, data) {
  5.       if(!rc) {
  6.           console.log("data " + data);
  7.           setTimeout(my_poll, 5000, zkk, path);
  8.       }
  9.       else {
  10.         console.log('zoo error ' + rc);
  11.         zkk.close();
  12.       }
  13.   });
  14. };
  15.  
  16. zk_session = function() {
  17.   var zk = new ZK();
  18.   zk.init ({connect:"192.168.7.33:2181", timeout:2000, debug_level:ZK.ZOO_LOG_LEVEL_DEBUG, host_order_deterministic:false});
  19.   zk.on (ZK.on_connected, function (zkk) {
  20.       console.log ("zk session established, id=%s", zkk.client_id);
  21.       zkk.a_create ("/node.js1", "some value", ZK.ZOO_SEQUENCE | ZK.ZOO_EPHEMERAL, function (rc, error, path)  {
  22.           if (rc != 0)
  23.               console.log ("zk node create result: %d, error: '%s', path=%s", rc, error, path);
  24.           else {
  25.               console.log ("created zk node %s", path);
  26.               process.nextTick(function () {
  27.                   my_poll(zkk, path);
  28.               });
  29.           }
  30.       });
  31.   });
  32.   zk.on (ZK.on_closed, function (zkk) {
  33.     console.log ("ZK CLOSED");
  34.     setTimeout(zk_session, 5000);
  35.   });
  36.   zk.on (ZK.on_event_changed, function () {
  37.     console.log ("ZK CHANGED");
  38.     //setTimeout(zk_session, 5000);
  39.   });
  40.  
  41. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement