lib/openwfe/expressions/environment.rb in openwferu-0.9.16 vs lib/openwfe/expressions/environment.rb in openwferu-0.9.17

- old
+ new

@@ -1,8 +1,8 @@ # #-- -# Copyright (c) 2006-2007, John Mettraux, OpenWFE.org +# Copyright (c) 2006-2008, John Mettraux, OpenWFE.org # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # @@ -35,36 +35,60 @@ # "made in Japan" # # John Mettraux at openwfe.org # +require 'rufus/scheduler' require 'openwfe/utils' -require 'openwfe/util/scheduler' require 'openwfe/expressions/flowexpression' module OpenWFE # # An environment is a store for variables. # It's an expression thus it's storable in the expression pool. # class Environment < FlowExpression - include Schedulable + include Rufus::Schedulable names :environment + V_PAUSED = VAR_PAUSED[1..-1] + + # + # the variables stored in this environment. + # attr_accessor :variables - def initialize \ - (fei, parent, environment_id, application_context, attributes) + #def initialize ( + # fei, parent, environment_id, application_context, attributes) + # super(fei, parent, environment_id, application_context, attributes) + # @variables = {} + #end - super(fei, parent, environment_id, application_context, attributes) + def initialize + super + @variables = {} end + def self.new_env ( + fei, parent_id, environment_id, app_context, attributes) + + env = self.new + + env.fei = fei + env.parent_id = parent_id + env.environment_id = environment_id + env.application_context = app_context + env.attributes = attributes + + env + end + # # Looks up for the value of a variable in this environment. # def [] (key) @@ -89,11 +113,11 @@ #end synchronize do @variables[key] = value - store_itself() + store_itself end end # # Removes a variable from this environment. @@ -102,11 +126,11 @@ synchronize do ldebug { "#{fei.to_debug_s} delete() '#{key}'" } @variables.delete key - store_itself() + store_itself end end # # This method is usually called before the environment gets wiped @@ -120,15 +144,15 @@ @variables.each do |key, value| #ldebug { "unbind() '#{key}' => #{value.class}" } - if value.kind_of? FlowExpressionId + if value.kind_of?(FlowExpressionId) - get_expression_pool().remove(value) + get_expression_pool.remove value - elsif value.kind_of? FlowExpression + elsif value.kind_of?(FlowExpression) value.cancel end end end @@ -136,11 +160,11 @@ # # Returns true if this environment is the engine environment # def is_engine_environment? - (@fei == get_expression_pool().engine_environment_id) + (@fei == get_expression_pool.engine_environment_id) end # # Should never get used, only the reschedule() method is relevant # for the Schedulable aspect of an environment expression. @@ -159,16 +183,20 @@ @variables.each do |key, value| #ldebug { "reschedule() - item of class #{value.class}" } - next unless value.kind_of? Schedulable + get_expression_pool.paused_instances[@fei.wfid] = true \ + if key == V_PAUSED + + next unless value.kind_of?(Rufus::Schedulable) + value.application_context = @application_context value.reschedule(scheduler) end - store_itself() + store_itself end # # Returns the top environment for the process instance (the # environment just before the engine environment). @@ -180,21 +208,23 @@ return self unless @parent_id get_parent.get_root_environment end + #-- #def get_subprocess_environment # return self if not @parent_id # return self if @parent_id.sub_instance_id != @fei.sub_instance_id # get_parent.get_subprocess_environment #end + #++ # # Returns a deep copy of this environment. # def dup - env = Environment.new( + env = Environment.new_env( @fei.dup, @parent_id, @environment_id, @application_context, OpenWFE::fulldup(@attributes))