代码拉取完成,页面将自动刷新
同步操作将从 java龙/dubbozoo 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/**
* Created by Corey600 on 2016/6/15.
*/
'use strict';
// require core modules
var url = require('url');
var querystring = require('querystring');
// require thirdpart modules
var zookeeper = require('node-zookeeper-client');
// require custom modules
var Provider = require('./lib/provider');
/**
* Expose `ZD`.
*
* @type {ZD}
*/
module.exports = ZD;
/**
* Constructor of ZD.
*
* @param {Object} conf
* {
* dubbo: String // dubbo version information
*
* // The following content could reference:
* // https://github.com/alexguan/node-zookeeper-client#client-createclientconnectionstring-options
*
* conn: String, // Comma separated host:port pairs, each represents a ZooKeeper server
* sessionTimeout: Number, // Session timeout in milliseconds, defaults to 30 seconds.
* spinDelay: Number, // The delay (in milliseconds) between each connection attempts.
* retries: Number // The number of retry attempts for connection loss exception.
* }
* @returns {ZD}
* @constructor
*/
function ZD(conf) {
if (!(this instanceof ZD)) return new ZD(conf);
conf = conf || {};
this._dubbo = conf.dubbo;
this._conn = conf.conn;
this._client = this.client = zookeeper.createClient(this._conn, {
sessionTimeout: conf.sessionTimeout,
spinDelay: conf.spinDelay,
retries: conf.retries
});
this._cache = this.cache = {};
}
/**
* Connect zookeeper.
*
* @public
*/
ZD.prototype.connect = function () {
if (!this._client || !this._client.connect) {
return;
}
this._client.connect();
};
/**
* Close connection.
*
* @public
*/
ZD.prototype.close = function () {
if (!this._client || !this._client.close) {
return;
}
this._client.close();
};
/**
* Get a provider from the registry.
*
* @param {String} path
* @param {String} version
* @param {Function} cb
* @returns {*}
* @public
*/
ZD.prototype.getProvider = function (path, version, cb) {
var self = this;
var _path = '/dubbo/' + path + '/providers';
var provider = self._cache[path];
if (provider) {
return cb(false, provider);
} else {
return self._client.getChildren(_path, function (err, children) {
var child, parsed, provider, i, l;
if (err) {
return cb(err);
}
if (children && !children.length) {
return cb('Can\'t find children from the node: ' + _path +
' ,please check the path!');
}
try {
for (i = 0, l = children.length; i < l; i++) {
var fullUrl = decodeURIComponent(children[i]);
var dduri = fullUrl.split('?')[0];
var queryStr = fullUrl.split('?')[1];
parsed = url.parse(dduri);
child = querystring.parse(queryStr);
if (parsed.protocol == "hessian:"){
dduri = dduri.replace("hessian:","http:");
}
child.uri = dduri;
if (child.version === version) {
break;
}
}
var providerCfg = {
uri: child.uri,
host: parsed.hostname,
port: parsed.port,
methods: child.methods.split(','),
protocol: parsed.protocol
};
provider = new Provider(providerCfg);
self._cache[path] = provider;
} catch (err) {
return cb(err);
}
return cb(false, provider);
});
}
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。