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

- old
+ new

@@ -1,43 +1,29 @@ -# #-- -# 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 'rufus/otime' require 'openwfe/expressions/timeout' @@ -97,24 +83,24 @@ if @scheduler_job_id end protected - # - # looks up potential scheduler tags in the expression - # attributes - # - def determine_scheduler_tags + # + # looks up potential scheduler tags in the expression + # attributes + # + def determine_scheduler_tags - @scheduler_tags = lookup_array_attribute( - :scheduler_tags, @applied_workitem) || [] + @scheduler_tags = lookup_array_attribute( + :scheduler_tags, @applied_workitem) || [] - @scheduler_tags << self.class.name + @scheduler_tags << self.class.name - @scheduler_tags << fei.to_short_s - @scheduler_tags << fei.parent_wfid - end + @scheduler_tags << fei.to_short_s + @scheduler_tags << fei.parent_wfid + end end # # A parent class for WhenExpression and WaitExpression. # @@ -125,17 +111,17 @@ include ConditionMixin include TimeoutMixin attr_accessor :frequency - uses_template + #uses_template # # By default, classes extending this class do poll for their # condition every 10 seconds. # - DEFAULT_FREQUENCY = "10s" + DEFAULT_FREQUENCY = '10s' # # Don't go under 300 milliseconds. # MIN_FREQUENCY = 0.300 @@ -165,11 +151,11 @@ @frequency = Rufus::parse_time_string( @frequency) @frequency = MIN_FREQUENCY \ if @frequency < MIN_FREQUENCY - determine_timeout + determine_timeout(workitem) determine_scheduler_tags condition_attribute = determine_condition_attribute( self.class.condition_attributes) @@ -182,41 +168,42 @@ consequence = nil if consequence.is_a?(String) get_expression_pool.tprepare_child( self, consequence, - 0, - true, # please register child - nil # no vars + 0, # sub_id + :register_child => true, + :dont_store_parent => true ) if consequence # # go east... store_itself + # as :dont_store_parent => true ... trigger end def reply (workitem) result = workitem.get_result if result - apply_consequence workitem + apply_consequence(workitem) else - reschedule get_scheduler + reschedule(get_scheduler) end end # # Cancels this expression (takes care of unscheduling a timeout # if there is one). # def cancel - unschedule_timeout + unschedule_timeout(nil) super() end def trigger (params={}) @@ -224,12 +211,12 @@ if params[:do_timeout!] # # do timeout... # - set_timedout_flag @applied_workitem - reply_to_parent @applied_workitem + set_timedout_flag(@applied_workitem) + reply_to_parent(@applied_workitem) return end @scheduler_job_id = nil @@ -253,76 +240,75 @@ end def reply_to_parent (workitem) unschedule - unschedule_timeout + unschedule_timeout(workitem) - super workitem + super(workitem) end protected - # - # The code for the condition evalution is here. - # - # This method is overriden by the WhenExpression. - # - def evaluate_condition + # + # The code for the condition evalution is here. + # + # This method is overriden by the WhenExpression. + # + def evaluate_condition - condition_attribute = determine_condition_attribute( - self.class.condition_attributes) + condition_attribute = determine_condition_attribute( + self.class.condition_attributes) - if condition_attribute + if condition_attribute - c = eval_condition condition_attribute, @applied_workitem + c = eval_condition(condition_attribute, @applied_workitem) - do_reply c - return - end + do_reply(c) + return + end - # else, condition is nested as a child + # else, condition is nested as a child - #if @children.size < 1 - if raw_children.size < 1 - # - # no condition attribute and no child attribute, - # simply reply to parent - # - reply_to_parent @applied_workitem - return - end + if has_no_expression_child + # + # no condition attribute and no child attribute, + # simply reply to parent + # + reply_to_parent(@applied_workitem) + return + end - # trigger the first child (the consequence child) + # trigger the first child (the consequence child) - get_expression_pool.tlaunch_child( - self, - raw_children.first, - (Time.new.to_f * 1000).to_i, - @applied_workitem.dup, - false) # not registering as a child - end + get_expression_pool.tlaunch_child( + self, + raw_children.first, + (Time.new.to_f * 1000).to_i, + @applied_workitem.dup, + :register_child => false) + end - # - # Used when replying to self after an attribute condition - # got evaluated - # - def do_reply (result) + # + # Used when replying to self after an attribute condition + # got evaluated + # + def do_reply (result) - @applied_workitem.set_result result - reply @applied_workitem - end + @applied_workitem.set_result(result) + reply(@applied_workitem) + end - # - # This method is overriden by WhenExpression. WaitExpression - # doesn't override it. - # This default implementation simply directly replies to - # the parent expression. - # - def apply_consequence (workitem) + # + # This method is overriden by WhenExpression. WaitExpression + # doesn't override it. + # This default implementation simply directly replies to + # the parent expression. + # + def apply_consequence (workitem) - reply_to_parent workitem - end + reply_to_parent(workitem) + end end end