Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var ZK = require ("zookeeper").ZooKeeper;
- var my_poll = function(zkk, path) {
- zkk.a_get( path , null, function(rc, error, stat, data) {
- if(!rc) {
- console.log("data " + data);
- setTimeout(my_poll, 5000, zkk, path);
- }
- else {
- console.log('zoo error ' + rc);
- zkk.close();
- }
- });
- };
- zk_session = function() {
- var zk = new ZK();
- zk.init ({connect:"192.168.7.33:2181", timeout:2000, debug_level:ZK.ZOO_LOG_LEVEL_DEBUG, host_order_deterministic:false});
- zk.on (ZK.on_connected, function (zkk) {
- console.log ("zk session established, id=%s", zkk.client_id);
- zkk.a_create ("/node.js1", "some value", ZK.ZOO_SEQUENCE | ZK.ZOO_EPHEMERAL, function (rc, error, path) {
- if (rc != 0)
- console.log ("zk node create result: %d, error: '%s', path=%s", rc, error, path);
- else {
- console.log ("created zk node %s", path);
- process.nextTick(function () {
- my_poll(zkk, path);
- });
- }
- });
- });
- zk.on (ZK.on_closed, function (zkk) {
- console.log ("ZK CLOSED");
- setTimeout(zk_session, 5000);
- });
- zk.on (ZK.on_event_changed, function () {
- console.log ("ZK CHANGED");
- //setTimeout(zk_session, 5000);
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement