msgflo
Version:
Polyglot FBP runtime based on message queues
50 lines (37 loc) • 1.58 kB
text/coffeescript
debug = require('debug')('msgflo:manager')
async = require 'async'
participant = require './participant'
transport = require './transport'
startProcesses = (library, address, runtime, processes, callback) ->
# Loading participants, mostly for testing
# one type could allow definiton a component library (in JSON),
# where each component has a command for starting an executable
# taking the broker address and participant identifier
start = (processId, cb) =>
component = processes[processId].component
client = transport.getClient address
participant.startParticipant library, client, component, processId, (err, part) ->
return cb err, part
debug 'starting participants', processes
async.map Object.keys(processes), start, (err, parts) ->
debug 'participants started', err, parts.length
return callback err, parts
class ParticipantManager
constructor: (, =null, ={}) ->
= []
start: (callback) ->
runtime = .properties?.environment?.runtime
return callback null if runtime != 'msgflo' # no-op
startProcesses , , runtime, .processes, (err, parts) =>
= parts
return callback err
stop: (callback) ->
stopParticipant = (part, callback) =>
part.stop (err) =>
return callback err if err
return callback null
async.map , stopParticipant, (err) ->
return callback err if err
= []
return callback null
exports.ParticipantManager = ParticipantManager