Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* // Event types
* var TYPES = {
* NODE_CREATED : 1,
* NODE_DELETED : 2,
* NODE_DATA_CHANGED : 3,
* NODE_CHILDREN_CHANGED : 4
* };
*/
var _ = require('lodash'),
zookeeper = require('node-zookeeper-client'),
CreateMode = zookeeper.CreateMode,
Event = zookeeper.Event;
var zk,
eventCache = {},
bindsEvent = {},
ZKROOT = '/npm_cache_share';
module.exports = {
Event: Event,
/**
* 创建zookeeper clinet
* @param {String} zkConfig zookeeper的链接,如host:port
* @param {String} zkRoot zookeeper上根路径节点名称
* @return {void}
*/
init: function(zkConfig, zkRoot) {
zk = zookeeper.createClient(zkConfig, {
this._zkClient.getData(path, function (event) {
log('Zookeeper getData event emit: %o', event);
// Retrieve node data when node data changes
// Result is: getData will listen for NODE_DELETE event when node is deleted,
// at the same time getChildren will also listen to the NODE_CHILDREN_CHANGED event.
// Prevent confusion
if (event.type === zookeeper.Event.NODE_DATA_CHANGED) {
_this._state = RECONNECTED;
_this._getData(path, cb);
}
}, function (err, data) {
if (err) {
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;
var zookeeper = require('node-zookeeper-client');
var CreateMode = zookeeper.CreateMode;
var Event = zookeeper.Event;
var util = require('util');
var EventEmitter = require('events').EventEmitter;
var logger = require('pomelo-logger').getLogger(__filename);
var zookeeperClient = null;
function getClient(app){
if(!zookeeperClient){
zookeeperClient = new Zookeeper(app);
}
return zookeeperClient;
}
function Zookeeper(app, opts){
this.app = app;
let watcher = (event) => {
if (event.getType() === zookeeper.Event.NODE_CHILDREN_CHANGED) {
this._zk.getChildren(path, watcher, (error, childrens) => {
if (error && error.getCode() !== 0) {
callback(error, []);
} else {
callback(null, childrens);
}
});
}
};
this._zk.getChildren(path, watcher, () => {
event => {
if (event.type ===
NodeZookeeperClient.Event.NODE_CHILDREN_CHANGED) {
this.log.debug('WEDSQP: children changed');
this._updateFilterDescriptors();
}
}, err => {
if (err) {