How to use zookeeper - 10 common examples

To help you get started, we’ve selected a few zookeeper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github howech / gestalt / examples / zookeeper_election.js View on Github external
zkc.zookeeper( function(zk) {
    console.log("creating temp node");
    zk.a_create("/chh/temp/node","stuff", ZooKeeper.ZOO_SEQUENCE + ZooKeeper.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("================== %s", path );
	    var me = path.match(/[^\/]+$/)[0];
	    console.log("My name is: %s", me);
	    var dir = "/chh/temp";
	    election(zk,dir,me);
	}
    });
});
github howech / gestalt / examples / zookeeper_election.js View on Github external
var lw = function(type, state, p){
	if( type == ZooKeeper.ZOO_CHANGED_EVENT ) {
	    zk.aw_get( path, lw, function() {} );
	} else if( type == ZooKeeper.ZOO_DELETED_EVENT ) {	    
	    // Our sentinal disappeared - this could mean that 
	    // we are now the leader, or it could mean that we
	    // need to watch someone else.
	    election(zk,dir,me);
	} else if( type == ZooKeeper.ZOO_SESSION_EVENT ) {
	    //console.log("Session problem!");
	    // zk will keep our callback around - no need to re-establish.
	} else {
	    console.log( "Unkown type: " + type );
	    //zk.aw_get( path, lw, function() {} );
	} 
    };
    zk.aw_get( path, lw, function() {} );
github howech / gestalt / examples / cluster.js View on Github external
var lw = function(type, state, p){
	if( type == ZooKeeper.ZOO_CHANGED_EVENT ) {
	    zk.aw_get( path, lw, function() {} );
	} else if( type == ZooKeeper.ZOO_DELETED_EVENT ) {	    
	    // Our sentinal disappeared - this could mean that 
	    // we are now the leader, or it could mean that we
	    // need to watch someone else.
	    zk_election(zk,dir,me,cb);
	} else if( type == ZooKeeper.ZOO_SESSION_EVENT ) {
	    //console.log("Session problem!");
	    // zk will keep our callback around - no need to re-establish.
	} else {
	    console.log( "Unkown type: " + type );
	    throw new Error("Unknown change type");
	} 
    };
    zk.aw_get( path, lw, function() {} );
github howech / gestalt / examples / zookeeper_election.js View on Github external
var lw = function(type, state, p){
	if( type == ZooKeeper.ZOO_CHANGED_EVENT ) {
	    zk.aw_get( path, lw, function() {} );
	} else if( type == ZooKeeper.ZOO_DELETED_EVENT ) {	    
	    // Our sentinal disappeared - this could mean that 
	    // we are now the leader, or it could mean that we
	    // need to watch someone else.
	    election(zk,dir,me);
	} else if( type == ZooKeeper.ZOO_SESSION_EVENT ) {
	    //console.log("Session problem!");
	    // zk will keep our callback around - no need to re-establish.
	} else {
	    console.log( "Unkown type: " + type );
	    //zk.aw_get( path, lw, function() {} );
	} 
    };
    zk.aw_get( path, lw, function() {} );
github howech / gestalt / examples / cluster.js View on Github external
var lw = function(type, state, p){
	if( type == ZooKeeper.ZOO_CHANGED_EVENT ) {
	    zk.aw_get( path, lw, function() {} );
	} else if( type == ZooKeeper.ZOO_DELETED_EVENT ) {	    
	    // Our sentinal disappeared - this could mean that 
	    // we are now the leader, or it could mean that we
	    // need to watch someone else.
	    zk_election(zk,dir,me,cb);
	} else if( type == ZooKeeper.ZOO_SESSION_EVENT ) {
	    //console.log("Session problem!");
	    // zk will keep our callback around - no need to re-establish.
	} else {
	    console.log( "Unkown type: " + type );
	    throw new Error("Unknown change type");
	} 
    };
    zk.aw_get( path, lw, function() {} );
github howech / gestalt / examples / cluster.js View on Github external
var lw = function(type, state, p){
	if( type == ZooKeeper.ZOO_CHANGED_EVENT ) {
	    zk.aw_get( path, lw, function() {} );
	} else if( type == ZooKeeper.ZOO_DELETED_EVENT ) {	    
	    // Our sentinal disappeared - this could mean that 
	    // we are now the leader, or it could mean that we
	    // need to watch someone else.
	    zk_election(zk,dir,me,cb);
	} else if( type == ZooKeeper.ZOO_SESSION_EVENT ) {
	    //console.log("Session problem!");
	    // zk will keep our callback around - no need to re-establish.
	} else {
	    console.log( "Unkown type: " + type );
	    throw new Error("Unknown change type");
	} 
    };
    zk.aw_get( path, lw, function() {} );
github howech / gestalt / examples / zookeeper_election.js View on Github external
var lw = function(type, state, p){
	if( type == ZooKeeper.ZOO_CHANGED_EVENT ) {
	    zk.aw_get( path, lw, function() {} );
	} else if( type == ZooKeeper.ZOO_DELETED_EVENT ) {	    
	    // Our sentinal disappeared - this could mean that 
	    // we are now the leader, or it could mean that we
	    // need to watch someone else.
	    election(zk,dir,me);
	} else if( type == ZooKeeper.ZOO_SESSION_EVENT ) {
	    //console.log("Session problem!");
	    // zk will keep our callback around - no need to re-establish.
	} else {
	    console.log( "Unkown type: " + type );
	    //zk.aw_get( path, lw, function() {} );
	} 
    };
    zk.aw_get( path, lw, function() {} );
github geisbruch / varnish-storm-collector / collector / collector.js View on Github external
process.on('SIGINT',function(){
    console.log("Exiting")
    if(zk != undefined && zk != null)
        zk.close();

        zk = new ZooKeeper({
          connect: process.argv[2],
          timeout: 22000,
          debug_level: ZooKeeper.ZOO_LOG_LEVEL_WARN,
          host_order_deterministic: false
        })

    zk.connect(function(err){
        zk.a_get(zkPath,false,function(rc,error,stat,data){
            zk.a_delete_(zkPath, stat.version,function(rc,error){
               zk.close()  
            })
        })
    })
    setTimeout(function(){
        process.exit(0)
    },1000)
   })
}
github howech / gestalt / examples / zookeeper_election.js View on Github external
function become_leader(zk,me) {
    console.log(">>>>>>>>>>>>>>>>>>>>> I AM THE LEADER <<<<<<<<<<<<<<<<<<<<<<<<<<<");
    zk.a_create("/chh/xxx/leader", me, ZooKeeper.ZOO_EPHEMERAL ,function (rc, error, path)  {
    });
}
github killme2008 / node-zk-browser / zk.js View on Github external
function new_zk(hosts,zkclient){
    var zk = new ZK();
    zk.init ({connect:hosts, timeout:20000, debug_level:ZK.ZOO_LOG_LEVEL_WARNING, host_order_deterministic:false});
    zk.on (ZK.on_connected, function (zkk) {
        console.log ("zk session established, id=%s", zkk.client_id);
    });
    zk.on(ZK.on_closed,function(zkk){
        //re-initialize
        console.log("zk session close,re-init it");
        zkclient.zk=new_zk(hosts,zkclient);
    });
    return zk;
}