Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
874 additions
and
892 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules | |
.idea | ||
.vscode | ||
jsconfig.json | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
benchmark | ||
examples | ||
jsconfig.json | ||
src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
var cote = require('../'); | ||
const cote = require('../'); | ||
|
||
new cote.Monitor({name: 'Monitor'}); | ||
new cote.Monitor({ name: 'Monitor' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
var cote = require('../'); | ||
const cote = require('../'); | ||
|
||
new cote.MonitoringTool(process.env.PORT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const EventEmitter = require('eventemitter2').EventEmitter2; | ||
const Discovery = require('./discovery'); | ||
|
||
module.exports = class Component extends EventEmitter { | ||
constructor(advertisement, discoveryOptions) { | ||
super({ | ||
wildcard: true, // should the event emitter use wildcards. | ||
delimiter: '::', // the delimiter used to segment namespaces, defaults to `.`. | ||
newListener: false, // if you want to emit the newListener event set to true. | ||
maxListeners: 2000, // the max number of listeners that can be assigned to an event, defaults to 10. | ||
}); | ||
|
||
advertisement.key = this.constructor.environment + '$$' + (advertisement.key || ''); | ||
|
||
this.advertisement = advertisement; | ||
this.advertisement.axon_type = this.type; | ||
|
||
this.discoveryOptions = discoveryOptions || {}; | ||
this.discoveryOptions.address = this.discoveryOptions.address || | ||
'0.0.0.0'; | ||
} | ||
|
||
startDiscovery() { | ||
this.discovery = new Discovery(this.advertisement, | ||
this.discoveryOptions); | ||
|
||
this.discovery.on('added', (obj) => { | ||
if ( | ||
obj.advertisement.axon_type != this.oppo || | ||
obj.advertisement.key != this.advertisement.key || | ||
this.advertisement.namespace != obj.advertisement.namespace | ||
) return; | ||
|
||
this.onAdded(obj); | ||
this.emit('cote:added', obj); | ||
}); | ||
this.discovery.on('removed', (obj) => { | ||
if ( | ||
obj.advertisement.axon_type != this.oppo || | ||
obj.advertisement.key != this.advertisement.key || | ||
this.advertisement.namespace != obj.advertisement.namespace | ||
) return; | ||
|
||
this.onRemoved(obj); | ||
this.emit('cote:removed', obj); | ||
}); | ||
} | ||
|
||
onAdded() { }; | ||
|
||
onRemoved() { }; | ||
|
||
close() { | ||
this.sock && this.sock.close(); | ||
this.discovery && this.discovery.stop(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
module.exports = (Base) => class Configurable extends Base { | ||
static get environment() { | ||
return this.constructor._environment || ''; | ||
} | ||
|
||
static setEnvironment(environment) { | ||
if (!environment) return; | ||
|
||
this.constructor._environment = environment + ':'; | ||
} | ||
|
||
|
||
static get useHostNames() { | ||
return this.constructor._useHostNames || false; | ||
} | ||
|
||
|
||
static setUseHostNames(useHostNames) { | ||
this.constructor._useHostNames = useHostNames; | ||
}; | ||
}; |
Oops, something went wrong.