Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.client.on("state", function(state) {
// automatically reconnect
if(self.clientStatus !== ZK_STATUS.NOT_CONNECTED &&
state === zookeeper.State.EXPIRED) {
setTimeout(self.connect, 1, callback, -1);
}
});
Configure.prototype.setConfigOnce = function (key, value, cb) {
var self = this;
var newPath = this.basePath + '/' + key;
if (self.zkClient.getState() != zookeeper.State.SYNC_CONNECTED) {
return self._beforeConnected.push({method: "setOnce", cb: cb, k: key, v: value});
}
self.zkClient.exists(
newPath,
function (error, stat) {
if (error) {
console.log(error.stack);
return;
}
if (!stat) {
self._createZnodeWithData(newPath, JSON.stringify(value), function (err) {
if (cb) cb(err);
});
} else {
self.zkClient.setData(newPath, new Buffer(JSON.stringify(value)), -1,
this.client.on("state", function(state) {
if(self.clientStatus !== ZK_STATUS.NOT_CONNECTED &&
state === zookeeper.State.EXPIRED) {
setTimeout(self.connect, 100, function(err) {
console.error(
"Illyria zookeeper failed to reconnect when expired: " +
err.message);
});
}
});
this.client.on("state", function(state) {
if(self.clientStatus !== ZK_STATUS.NOT_CONNECTED &&
state === zookeeper.State.EXPIRED) {
setTimeout(self.connect, 100, function(err) {
console.error(
"Illyria zookeeper failed to reconnect when expired: " +
err.message);
});
}
});
ZD.prototype.close = function () {
var self = this;
if (!self._client || !self._client.close) {
return;
}
var state = self._client.getState();
if (state == zookeeper.State.CONNECTED
|| state == zookeeper.State.CONNECTED_READ_ONLY) {
this._client.close();
}
};
'use strict';
const zookeeper = require('node-zookeeper-client');
const ZookeeperClient = require('./api_client');
exports.createClient = (connectionString, options) => {
options = options || {};
options.connectionString = connectionString || 'localhost:2181';
return new ZookeeperClient(options);
};
exports.ACL = zookeeper.ACL;
exports.Id = zookeeper.Id;
exports.Permission = zookeeper.Permission;
exports.CreateMode = zookeeper.CreateMode;
exports.State = zookeeper.State;
exports.Event = zookeeper.Event;
exports.Exception = zookeeper.Exception;
this.zookeeper.on('state', function (state) {
switch (state) {
case zookeeper.State.SYNC_CONNECTED:
if (!self.initialized) {
self.initialized = true;
self.onconnected(callback);
}
else
self.onconnected(function () {
});
break;
case zookeeper.State.DISCONNECTED:
self.ondisconnected();
break;
case zookeeper.State.EXPIRED:
self.onexpired();
break;
default:
break;
}
});
healthServer.onReadyCheck(() => {
const state = ingestionPopulator.zkStatus();
if (state.code === zookeeper.State.SYNC_CONNECTED.code) {
return true;
}
log.error(`Zookeeper is not connected! ${state}`);
return false;
});
log.info('Starting health probe server');
isReady() {
const state = this._zkClient && this._zkClient.getState();
return this._producer && this._producer.isReady() && state &&
state.code === zookeeper.State.SYNC_CONNECTED.code;
}
}
ZD.prototype.close = function () {
var self = this;
if (!self._client || !self._client.close) {
return;
}
var state = self._client.getState();
if (state == zookeeper.State.CONNECTED
|| state == zookeeper.State.CONNECTED_READ_ONLY) {
this._client.close();
}
};