 fromIipId = (id) ->
   return id.split ' '
 
+participantsByRole = (participants, role) ->
+  matchRole = (id) =>
+    part = participants[id]
+    return part.role == role
+
+  m = Object.keys(participants).filter matchRole
+  return m
+
+# XXX: there is now a mixture of participant id and role used here
+findQueue = (participants, partId, dir, portName) =>
+  part = participants[partId]
+  part = participants[participantsByRole(participants, partId)] if not part?
+  for port in part[dir]
+    return port.queue if port.id == portName
 
 waitForParticipant = (coordinator, role, callback) ->
-  existing = coordinator.participantsByRole role
+  existing = participantsByRole coordinator.participants, role
   return callback null, coordinator.participants[existing[0]] if existing.length
 
   onTimeout = () =>

        @processes = proc
        setup.bindings options, callback

  participantsByRole: (role) ->
    matchRole = (id) =>
      part = @participants[id]
      return part.role == role

    m = Object.keys(@participants).filter matchRole
    return m


exports.Coordinator = Coordinator

    callback = defaultCallback if not callback

    part = @participants[participantId]
    part = @participants[participantsByRole(@participants, participantId)] if not part?
    port = findPort part, 'inport', inport
    return @broker.sendTo 'inqueue', port.queue, message, callback

