Object
Tracking participants to [business] processes.
The methods here are mostly called via the engine (registering / unregistering participants) and via the dispatch_pool (when handing workitems to participants).
Returns an instance of a participant
# File lib/ruote/part/participant_list.rb, line 198 def instantiate (pinfo, opts={}) irt = opts[:if_respond_to?] pinfo = @instantiated_participants[pinfo] if pinfo.is_a?(String) if pinfo.respond_to?(:consume) return (pinfo.respond_to?(irt) ? pinfo : nil) if irt return pinfo end return nil unless pinfo pa_class_name, options = pinfo if rp = options['require_path'] require(rp) end if lp = options['load_path'] load(lp) end pa_class = Ruote.constantize(pa_class_name) pa_m = pa_class.instance_methods if irt && ! (pa_m.include?(irt.to_s) || pa_m.include?(irt.to_sym)) return nil end pa = if pa_class.instance_method(:initialize).arity > 0 pa_class.new(options) else pa_class.new end pa.context = @context if pa.respond_to?(:context=) pa end
Used by Engine#participant_list
Returns a representation of this participant list as an array of ParticipantEntry instances.
# File lib/ruote/part/participant_list.rb, line 259 def list get_list['list'].collect { |e| ParticipantEntry.new(e) } end
Used by Engine#participant_list=
Takes as input an array of ParticipantEntry instances and updates this participant list with it.
# File lib/ruote/part/participant_list.rb, line 271 def list= (pl) list = get_list list['list'] = pl.collect { |pe| pe.to_a } if r = @context.storage.put(list) # # put failed, have to redo it # list= (pl) end end
Returns a participant instance, or nil if there is no participant for the given participant name.
Mostly a combination of lookup_info and instantiate.
# File lib/ruote/part/participant_list.rb, line 162 def lookup (participant_name, workitem, opts={}) pinfo = participant_name if participant_name.is_a?(String) && participant_name[0, 5] != 'inpa_' pinfo = lookup_info(participant_name, workitem) end pinfo ? instantiate(pinfo, opts) : nil end
Given a participant name, returns
Returns nil if there is no participant registered that covers the given participant name.
# File lib/ruote/part/participant_list.rb, line 178 def lookup_info (pname, workitem) get_list['list'].each do |regex, pinfo| next unless pname.match(regex) pa = instantiate(pinfo, :if_respond_to? => :accept?) return pinfo unless pa return pinfo if pa.accept?( Ruote::Workitem.new(workitem.merge('participant_name' => pname)) ) end nil end
Return a list of names (regex) for the registered participants
# File lib/ruote/part/participant_list.rb, line 239 def names get_list['list'].collect { |re, pa| re } end
Registers a participant. Called by Engine#register_participant.
# File lib/ruote/part/participant_list.rb, line 50 def register (name, participant, options, block) options = options.inject({}) { |h, (k, v)| h[k.to_s] = v.is_a?(Symbol) ? v.to_s : v h } entry = if participant.is_a?(Class) || participant.is_a?(String) [ participant.to_s, options ] else "inpa_#{name.inspect}" # INstantiated PArticipant end key = (name.is_a?(Regexp) ? name : Regexp.new("^#{name}$")).source entry = [ key, entry ] list = get_list list['list'].delete_if { |e| e.first == key } position = options['position'] || 'last' case position when 'last' then list['list'] << entry when 'first' then list['list'].unshift(entry) when Fixnum then list['list'].insert(position, entry) else raise "cannot insert participant at position '#{position}'" end if r = @context.storage.put(list) # # if put returns something it means the put failed, have to redo the # work... # return register(name, participant, options, block, r) end if entry.last.is_a?(String) participant = BlockParticipant.new(block, options) if block participant.context = @context if participant.respond_to?(:context=) @instantiated_participants[entry.last] = participant #participant else if entry.last.first == 'Ruote::StorageParticipant' return Ruote::StorageParticipant.new(@context) end nil end end
Shuts down the 'instantiated participants' (engine worker participants) if they respond to shutdown.
# File lib/ruote/part/participant_list.rb, line 247 def shutdown @instantiated_participants.each { |re, pa| pa.shutdown if pa.respond_to?(:shutdown) } end
Removes a participant, given via its name or directly from this participant list.
Called usually by Engine#unregister_participant.
# File lib/ruote/part/participant_list.rb, line 111 def unregister (name_or_participant) code = nil entry = nil list = get_list if name_or_participant.is_a?(Symbol) name_or_participant = name_or_participant.to_s end if name_or_participant.is_a?(String) entry = list['list'].find { |re, pa| name_or_participant.match(re) } return nil unless entry code = entry.last if entry.last.is_a?(String) else # we've been given a participant instance code = @instantiated_participants.find { |k, v| v == name_or_participant } return nil unless code code = code.first entry = list['list'].find { |re, pa| pa == code } end list['list'].delete(entry) if r = @context.storage.put(list) # # put failed, have to redo it # return unregister(name_or_participant, r) end @instantiated_participants.delete(code) if code entry.first end
Fetches and returns the participant list in the storage.
# File lib/ruote/part/participant_list.rb, line 288 def get_list @context.storage.get_configuration('participant_list') || { 'type' => 'configurations', '_id' => 'participant_list', 'list' => [] } end
Returns an array of all the classes in the ObjectSpace that include the Ruote::LocalParticipant module.
# File lib/ruote/part/participant_list.rb, line 299 def local_participant_classes ObjectSpace.each_object(Class).inject([]) { |a, c| a << c if c.include?(Ruote::LocalParticipant) a } end
Generated with the Darkfish Rdoc Generator 2.