lib/openwfe/expressions/fe_participant.rb in ruote-0.9.19 vs lib/openwfe/expressions/fe_participant.rb in ruote-0.9.20

- old
+ new

@@ -1,54 +1,36 @@ -# #-- -# Copyright (c) 2006-2008, John Mettraux, OpenWFE.org -# All rights reserved. +# Copyright (c) 2006-2009, John Mettraux, jmettraux@gmail.com # -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: # -# . Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. # -# . Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. # -# . Neither the name of the "OpenWFE" nor the names of its contributors may be -# used to endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. +# Made in Japan. #++ -# -# -# "made in Japan" -# -# John Mettraux at openwfe.org -# require 'openwfe/utils' require 'openwfe/rudefinitions' require 'openwfe/expressions/filter' require 'openwfe/expressions/timeout' -# -# The participant expression, in its own file -# - module OpenWFE # # Participants sit at the edge between the engine and the external # world. The participant expression transmit the workitem applied @@ -123,96 +105,79 @@ names :participant attr_accessor :participant_name attr_accessor :applied_workitem - def apply (workitem) - conditional = eval_condition :if, workitem, :unless + conditional = eval_condition(:if, workitem, :unless) - return super_reply_to_parent(workitem) \ - if conditional == false - # - # skip expression - # <participant ref="x" if="y" /> (where y evals to false) + return super_reply_to_parent(workitem) if conditional == false + # + # skip expression + # <participant ref="x" if="y" /> (where y evals to false) - @participant_name = lookup_ref workitem + @participant_name ||= self.respond_to?(:hint) ? hint : nil + @participant_name ||= lookup_ref(workitem) || fetch_text_content(workitem) - @participant_name = fetch_text_content workitem \ - unless @participant_name + participant = get_participant_map.lookup_participant(@participant_name) - participant = - get_participant_map.lookup_participant @participant_name - - raise "No participant named '#{@participant_name}'" \ + raise "pexp : no participant named #{@participant_name.inspect}" \ unless participant - remove_timedout_flag workitem + workitem.unset_result + remove_timedout_flag(workitem) @applied_workitem = workitem.dup - schedule_timeout + schedule_timeout(workitem) - filter_in workitem + filter_in(workitem) store_itself - workitem.params = lookup_attributes workitem + workitem.params = lookup_attributes(workitem) - # - # threading AFTER the store_itself() - # - Thread.new do - begin + # after the store_itself() - # these two pmap calls were combined, but with the :reply - # notification in reply_to_parent() it feels more - # elegant like that + get_participant_map.dispatch( + participant, @participant_name, workitem) - get_participant_map.dispatch( - participant, @participant_name, workitem) - - get_participant_map.onotify( - @participant_name, :apply, workitem) - - rescue Exception => e - - get_expression_pool.notify_error( - e, fei, :apply, workitem) - end - end + get_participant_map.onotify( + @participant_name, :apply, workitem) end alias :super_reply_to_parent :reply_to_parent def reply_to_parent (workitem) - get_participant_map.onotify @participant_name, :reply, workitem + get_participant_map.onotify(@participant_name, :reply, workitem) # # for 'listen' expressions waiting for replies - unschedule_timeout() + unschedule_timeout(workitem) - workitem.attributes.delete "params" + workitem.attributes.delete('params') - filter_out workitem + filter_out(workitem) - super workitem + super(workitem) end # # The cancel() method of a ParticipantExpression is particular : it # will emit a CancelItem instance towards the participant itself # to notify it of the cancellation. # def cancel - unschedule_timeout + unschedule_timeout(nil) cancel_participant + trigger_on_cancel # if any + @applied_workitem end # # Upon timeout, the ParticipantExpression will cancel itself and @@ -228,42 +193,39 @@ # # so that cancel won't unschedule without need cancel_participant - set_timedout_flag @applied_workitem + set_timedout_flag(@applied_workitem) - reply_to_parent @applied_workitem + reply_to_parent(@applied_workitem) rescue - lerror do - "trigger() problem while timing out\n"+ - OpenWFE::exception_to_s($!) - end + lerror { + "trigger() problem while timing out\n#{OpenWFE::exception_to_s($!)}" + } end end protected - # - # Have to cancel the workitem on the participant side - # - def cancel_participant + # + # Have to cancel the workitem on the participant side + # + def cancel_participant - return unless @applied_workitem - # - # if there is an applied workitem, it means there - # is a participant to cancel... + return unless @applied_workitem + # + # if there is an applied workitem, it means there + # is a participant to cancel... - participant = \ - get_participant_map.lookup_participant(@participant_name) + participant = get_participant_map.lookup_participant(@participant_name) - cancelitem = CancelItem.new(@applied_workitem) + cancelitem = CancelItem.new(@applied_workitem) - get_participant_map.dispatch( - participant, @participant_name, cancelitem) - end + get_participant_map.dispatch(participant, @participant_name, cancelitem) + end end end