lib/openwfe/participants/participantmap.rb in openwferu-0.9.13 vs lib/openwfe/participants/participantmap.rb in openwferu-0.9.14
- old
+ new
@@ -49,11 +49,11 @@
#
# A very simple directory of participants
#
class ParticipantMap < Service
- include Observable
+ include OwfeObservable
attr_accessor \
:participants
def initialize (service_name, application_context)
@@ -63,10 +63,18 @@
@observers = {}
end
#
+ # Returns how many participants are currently registered here.
+ #
+ def size
+
+ @participants.size
+ end
+
+ #
# Adds a participant to this map.
# This method is called by the engine's own register_participant()
# method.
#
# The participant instance is returned by this method call
@@ -119,11 +127,11 @@
participant.application_context = @application_context \
if participant.respond_to? :application_context=
@participants << [ regex, participant ]
- return participant
+ participant
end
#
# Looks up a participant given a participant_name.
# Will return the first participant whose name matches.
@@ -135,10 +143,11 @@
participant_name = participant_name.to_s
@participants.each do |tuple|
return tuple[1] if tuple[0].match(participant_name)
end
+
nil
end
#
# Deletes the first participant matching the given name.
@@ -156,22 +165,25 @@
pos > -1
end
#
- # Dispatches to the given participant.
+ # Dispatches to the given participant (participant name (string) or
# The workitem will be fed to the consume() method of that participant.
# If it's a cancelitem and the participant has a cancel() method,
# it will get called instead.
#
- def dispatch (participant_name, workitem)
+ def dispatch (participant, participant_name, workitem)
- participant = lookup_participant(participant_name)
+ unless participant
- raise "Didn't find participant named '#{participant_name}'" \
- if not participant
+ participant = lookup_participant participant_name
+ raise "there is no participant named '#{participant_name}'" \
+ unless participant
+ end
+
workitem.participant_name = participant_name
if (workitem.kind_of?(CancelItem) and
participant.respond_to?(:cancel))
@@ -181,9 +193,11 @@
return
end
onotify :dispatch, :before_consume, workitem
+
+ workitem.dispatch_time = Time.now
participant.consume(workitem)
onotify :dispatch, :after_consume, workitem
end