mirror of
https://github.com/openstf/stf
synced 2025-10-04 18:29:17 +02:00
Rename "roles" to "units". Put units in their own folders.
This commit is contained in:
parent
7d9d64ddcb
commit
3a9b193f68
63 changed files with 105 additions and 105 deletions
44
lib/units/triproxy/index.js
Normal file
44
lib/units/triproxy/index.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
var zmq = require('zmq')
|
||||
|
||||
var logger = require('../../util/logger')
|
||||
var lifecycle = require('../../util/lifecycle')
|
||||
|
||||
module.exports = function(options) {
|
||||
var log = logger.createLogger('triproxy')
|
||||
|
||||
if (options.name) {
|
||||
logger.setGlobalIdentifier(options.name)
|
||||
}
|
||||
|
||||
function proxy(to) {
|
||||
return function() {
|
||||
to.send([].slice.call(arguments))
|
||||
}
|
||||
}
|
||||
|
||||
// App/device output
|
||||
var pub = zmq.socket('pub')
|
||||
pub.bindSync(options.endpoints.pub)
|
||||
log.info('PUB socket bound on', options.endpoints.pub)
|
||||
|
||||
// Coordinator input/output
|
||||
var dealer = zmq.socket('dealer')
|
||||
dealer.bindSync(options.endpoints.dealer)
|
||||
dealer.on('message', proxy(pub))
|
||||
log.info('DEALER socket bound on', options.endpoints.dealer)
|
||||
|
||||
// App/device input
|
||||
var pull = zmq.socket('pull')
|
||||
pull.bindSync(options.endpoints.pull)
|
||||
pull.on('message', proxy(dealer))
|
||||
log.info('PULL socket bound on', options.endpoints.pull)
|
||||
|
||||
lifecycle.observe(function() {
|
||||
try {
|
||||
pub.close()
|
||||
dealer.close()
|
||||
pull.close()
|
||||
}
|
||||
catch (err) {}
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue