lib/openwfe/expool/expressionpool.rb in openwferu-0.9.8 vs lib/openwfe/expool/expressionpool.rb in openwferu-0.9.9

- old
+ new

@@ -181,21 +181,21 @@ wfdurl = launchitem.workflow_definition_url definition = if wfdurl.match "^field:" wfdfield = wfdurl[6..-1] - launchitem.attributes.delete(wfdfield) + launchitem.attributes.delete wfdfield else read_uri(wfdurl) end raise "didn't find process definition at '#{wfdurl}'" \ unless definition - raw_expression = build_raw_expression(launchitem, definition) + raw_expression = build_raw_expression launchitem, definition - raw_expression.check_parameters(launchitem) + raw_expression.check_parameters launchitem # # will raise an exception if there are requirements # and one of them is not met raw_expression @@ -244,14 +244,18 @@ return fei #return fei, Thread.current end # - # launches a subprocess + # Prepares a raw expression from a template. + # Returns that raw expression. # - def launch_template ( - requesting_expression, sub_id, template, workitem, params=nil) + # Used in the concurrent-iterator when building up the children list + # and of course used by the launch_template() method. + # + def prepare_from_template ( + requesting_expression, sub_id, template, params=nil) rawexp = if template.is_a? RawExpression template elsif template.is_a? FlowExpressionId fetch_expression(template) @@ -292,54 +296,54 @@ rawexp.fei.workflow_instance_id = \ "#{requesting_expression.fei.workflow_instance_id}.#{sub_id}" end #ldebug do - # p = "" - # p = rawexp.parent_id.to_debug_s if rawexp.parent_id - # "launch_template()\n"+ - # " rawexp.fei is #{rawexp.fei.to_debug_s}\n"+ - # " rawexp.parent_id is #{p}" - #end - - #ldebug do # "launch_template() spawning wfid " + # "#{rawexp.fei.workflow_instance_id.to_s}" #end - env = rawexp.new_environment() + env = rawexp.new_environment(params) # - params.each { |k, v| env[k] = v } if params - # # the new scope gets its own environment rawexp.store_itself() - workitem.flow_expression_id = rawexp.fei + rawexp + end - fei = rawexp.fei + # + # launches a subprocess + # + def launch_template ( + requesting_expression, sub_id, template, workitem, params=nil) - apply(rawexp, workitem) + rawexp = prepare_from_template( + requesting_expression, sub_id, template, params) - return fei + workitem.flow_expression_id = rawexp.fei + + apply rawexp, workitem + + rawexp.fei end # # Evaluates a raw definition expression and # returns its body fei # def evaluate (rawExpression, workitem) - exp = rawExpression.instantiate_real_expression(workitem) - fei = exp.evaluate(workitem) + exp = rawExpression.instantiate_real_expression workitem + fei = exp.evaluate workitem #remove(rawExpression) # # not necessary, the raw expression gets overriden by # the real expression - return fei + fei end # # Applies a given expression (id or expression) # @@ -406,20 +410,27 @@ # # Forgets the given expression (makes sure to substitute its # parent_id with the GONE_PARENT_ID constant) # - def forget (exp) + def forget (parent_exp, exp) exp, fei = fetch(exp) + #ldebug { "forget() forgetting #{fei}" } + return if not exp onotify :forget, fei + parent_exp.children.delete(fei) + exp.parent_id = GONE_PARENT_ID + exp.dup_environment exp.store_itself() + + ldebug { "forget() forgot #{fei}" } end # # Replies to the parent of the given expression. # @@ -477,11 +488,11 @@ end # # parent still present, reply to it - reply(exp.parent_id, workitem) + reply exp.parent_id, workitem end # # Triggers the reply expression of the expression given by its id. # @@ -556,26 +567,27 @@ # The param 'exp' may be a FlowExpressionId or a FlowExpression that # has to be reloaded. # def fetch_expression (exp) exp, _fei = fetch(exp) - return exp + exp end # # Fetches the root expression of a process (given any of its # expressions or its wfid). # def fetch_root (exp_or_wfid) return fetch_expression_with_wfid(exp_or_wfid) \ - if exp_or_wfid.is_a? String + if exp_or_wfid.is_a?(String) exp = fetch_expression(exp_or_wfid) return exp unless exp.parent_id - return fetch_root(fetch_expression(exp.parent_id)) + + fetch_root(fetch_expression(exp.parent_id)) end # # Returns the engine environment (the top level environment) # @@ -589,22 +601,22 @@ ee = Environment\ .new(eei, nil, nil, @application_context, nil) ee.store_itself() end - return ee + ee end end # # Removes a flow expression from the pool # (This method is mainly called from the pool itself) # def remove (exp) exp, _fei = fetch(exp) \ - if exp.kind_of? FlowExpressionId + if exp.kind_of?(FlowExpressionId) return if not exp ldebug { "remove() fe #{exp.fei.to_debug_s}" } @@ -680,12 +692,12 @@ result = [] get_expression_storage.real_each do |fei, fexp| - next if fexp.kind_of? Environment - next if fexp.kind_of? RawExpression + next if fexp.kind_of?(Environment) + next if fexp.kind_of?(RawExpression) next unless fexp.apply_time pi = fei.parent_wfid next if pi != wfid @@ -754,11 +766,11 @@ ldebug { "remove_environment() #{environment_id.to_debug_s}" } env, fei = fetch(environment_id) - env.unbind() + env.unbind #get_expression_storage().delete(environment_id) onotify :remove, environment_id end @@ -767,15 +779,15 @@ # Prepares a new instance of InFlowWorkItem from a LaunchItem # instance. # def build_workitem (launchitem) - wi = InFlowWorkItem.new() + wi = InFlowWorkItem.new - wi.attributes = launchitem.attributes.dup() + wi.attributes = launchitem.attributes.dup - return wi + wi end # # This is the only point in the expression pool where an URI # is read, so this is where the :remote_definitions_allowed @@ -813,14 +825,16 @@ #ldebug do # "determine_representation() " + # "param of class #{param.class.name}" #end - return param if param.is_a? SimpleExpRepresentation - return param.make if param.is_a? ProcessDefinition - return param.do_make if param.is_a? Class + return param \ + if param.is_a?(SimpleExpRepresentation) + return param.do_make \ + if param.is_a?(ProcessDefinition) or param.is_a?(Class) + raise "cannot handle definition of class #{param.class.name}" \ unless param.is_a? String if param[0, 1] == "<" # @@ -842,12 +856,12 @@ # # else it's some ruby code to eval o = OpenWFE::eval_safely(param, SAFETY_LEVEL) - return o.make if o.is_a? ProcessDefinition - return o.do_make if o.kind_of? Class + return o.do_make \ + if o.is_a?(ProcessDefinition) or o.is_a?(Class) o end # @@ -871,11 +885,12 @@ fei.workflow_definition_name = OpenWFE::stu flow_name fei.workflow_definition_revision = OpenWFE::stu flow_revision fei.wfid = get_wfid_generator.generate launchitem fei.expression_id = "0" fei.expression_name = exp_name - return fei + + fei end # # Builds the RawExpression instance at the root of the flow # being launched. @@ -896,11 +911,11 @@ fei = new_fei(launchitem, flow_name, flow_revision, exp_name) #puts procdef.raw_expression_class #puts procdef.raw_expression_class.public_methods - return procdef.raw_expression_class\ - .new(fei, nil, nil, @application_context, procdef) + procdef.raw_expression_class.new( + fei, nil, nil, @application_context, procdef) end end end