happner-client
Advanced tools
Comparing version
@@ -55,2 +55,5 @@ (function (isBrowser) { | ||
this.__logger = opts.logger || Logger; | ||
this.log = this.__logger.createLogger('HappnerClient'); | ||
this.__connection = new ConnectionProvider(this); | ||
@@ -61,4 +64,2 @@ this.__implementors = new ImplementorsProvider(this, this.__connection); | ||
this.__responseTimeout = typeof opts.responseTimeout == 'number' ? opts.responseTimeout : 20 * 1000; | ||
this.__logger = opts.logger || Logger; | ||
this.log = this.__logger.createLogger('HappnerClient'); | ||
} | ||
@@ -80,4 +81,14 @@ | ||
HappnerClient.prototype.mount = function (orchestrator) { | ||
var _this = this; | ||
this.__connection.mount(orchestrator); | ||
this.__implementors.subscribeToPeerEvents(); | ||
this.__implementors.getDescriptions().catch(function (e) { | ||
// cannot make mount() async because plugins in happner load before component | ||
// so the description is not ready so get descriptions will fail to do so | ||
// indefinately | ||
// set to retry | ||
_this.__implementors.callersAwaitingDescriptions = []; | ||
_this.log.error(e); | ||
}); | ||
}; | ||
@@ -92,3 +103,3 @@ | ||
HappnerClient.prototype.construct = function (model, $happner) { | ||
HappnerClient.prototype.construct = function (model, $happn) { | ||
var _this = this; | ||
@@ -98,6 +109,6 @@ | ||
var api = $happner || { | ||
exchange: {}, | ||
event: {} | ||
}; | ||
var api = $happn || { | ||
exchange: {}, | ||
event: {} | ||
}; | ||
@@ -111,3 +122,3 @@ var componentNames = Object.keys(model); | ||
// $happner.event APIs are always replaced to become version aware | ||
// $happn.event APIs are always replaced to become version aware | ||
@@ -117,3 +128,3 @@ api.event[componentName] = {}; | ||
// $happner.exchange are only replaced if the existing local component is wrong version | ||
// $happn.exchange are only replaced if the existing local component is wrong version | ||
@@ -127,2 +138,6 @@ if (api.exchange[componentName]) { | ||
if ($happn) { | ||
this.__implementors.registerDependency($happn.name, componentName, component.version); | ||
} | ||
api.exchange[componentName] = { | ||
@@ -132,3 +147,3 @@ __version: component.version | ||
if ($happner) { | ||
if ($happn) { | ||
// used in happner._createElement() and _destroyElement() to not remove | ||
@@ -135,0 +150,0 @@ // this component when adding or removing elements from the local mesh |
@@ -18,3 +18,5 @@ (function (isBrowser) { | ||
Object.defineProperty(this, 'happnerClient', {value: happnerClient}); | ||
this.log = happnerClient.log; | ||
this.connection = connection; | ||
this.dependencies = {}; | ||
this.descriptions = []; | ||
@@ -37,2 +39,5 @@ this.maps = {}; | ||
// got all "starting" descriptions from peers already present at join time | ||
this.gotDescriptions = false; | ||
// pending list of descriptions we're waiting for | ||
@@ -110,2 +115,3 @@ this.awaitingDescriptions = {}; | ||
var onSuccess = function () { | ||
_this.logDependenciesMet(); | ||
}; | ||
@@ -122,2 +128,3 @@ var onFailure = function (e) { | ||
this.removeDescription(name); | ||
this.logDependenciesMet(); | ||
}; | ||
@@ -149,3 +156,5 @@ | ||
} | ||
_this.gotDescriptions = true; | ||
_this.callersAwaitingDescriptions = false; | ||
_this.logDependenciesMet(); | ||
}; | ||
@@ -283,2 +292,35 @@ | ||
ImplementorsProvider.prototype.registerDependency = function (dependorName, componentName, version) { | ||
if (!dependorName) return; // no $happn.name, not in cluster | ||
this.dependencies[dependorName] = this.dependencies[dependorName] || {}; | ||
this.dependencies[dependorName][componentName] = version; | ||
} | ||
ImplementorsProvider.prototype.logDependenciesMet = function () { | ||
if (!this.gotDescriptions) return; | ||
var _this = this; | ||
Object.keys(this.dependencies).forEach(function (dependorName) { | ||
Object.keys(_this.dependencies[dependorName]).forEach(function (componentName) { | ||
var version = _this.dependencies[dependorName][componentName]; | ||
var countMatches = _this.countDependencyMatches(componentName, version); | ||
(countMatches == 0 ? _this.log.error : _this.log.info)( | ||
'dependent %s has %d of %s %s', dependorName, countMatches, componentName, version | ||
); | ||
}); | ||
}); | ||
}; | ||
ImplementorsProvider.prototype.countDependencyMatches = function (componentName, version) { | ||
var count = 0; | ||
this.descriptions.forEach(function (description) { | ||
if (!description.components[componentName]) return; | ||
var gotVersion = description.components[componentName].version; | ||
if (!semver.satisfies(gotVersion, version)) return; | ||
count++; | ||
}); | ||
return count; | ||
} | ||
})(typeof module !== 'undefined' && typeof module.exports !== 'undefined' ? false : true); |
{ | ||
"name": "happner-client", | ||
"version": "4.0.0-prerelease4.2", | ||
"version": "4.0.0-prerelease4.3", | ||
"description": "The client for happner-2 and happner cluster services", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -26,8 +26,12 @@ 1.1.6 2017-03-21 | ||
3.0.0. 2017-11-27 | ||
----------------- | ||
3.0.0 2017-11-27 | ||
---------------- | ||
- bumped happn-3 to ^5.1.1 | ||
3.0.1 2018-01-08 | ||
---------------- | ||
- log dependencies met and unmet | ||
4.0.0 2017-12-20 | ||
---------------- | ||
- updated happner/happn |
148393
1.52%4205
1.15%