lib/openwfe/expool/expressionpool.rb in openwferu-0.9.11 vs lib/openwfe/expool/expressionpool.rb in openwferu-0.9.12

- old
+ new

@@ -62,48 +62,10 @@ include OpenWFE module OpenWFE - # - # a small help class for storing monitors provided on demand - # to expressions that need them - # - class MonitorProvider - include MonitorMixin, Logging - - MAX_MONITORS = 10000 - - def initialize (application_context=nil) - super() - @application_context = application_context - @monitors = LruHash.new(MAX_MONITORS) - end - - def [] (key) - synchronize do - #ldebug { "[] caller :\n" + OpenWFE::caller_to_s(8) } - mon = @monitors[key] - if not mon - #ldebug { "[] creating new Monitor for #{key}" } - mon = Monitor.new - @monitors[key] = mon - else - #ldebug { "[] already had Monitor for #{key}" } - end - return mon - end - end - - def delete (key) - synchronize do - #ldebug { "delete() removing Monitor for #{key}" } - @monitors.delete(key) - end - end - end - GONE = "gone" # # This special flow expression id is used by the forget() method # (which is used by the forget expression and the concurrence @@ -382,21 +344,43 @@ inflowitem end # + # Cancels the given expression and makes sure to resume the flow + # if the expression or one of its children were active. + # + # If the cancelled branch was not active, this method will take + # care of removing the cancelled expression from the parent + # expression. + # + def cancel_expression (exp) + + exp = fetch_expression(exp) + + wi = cancel(exp) + + if wi + reply_to_parent(exp, wi, false) + else + parent_exp = fetch_expression(exp.parent_id) + parent_exp.remove_child(exp.fei) if parent_exp + end + end + + # # Given any expression of a process, cancels the complete process # instance. # - def cancel_flow (exp_or_wfid) + def cancel_process (exp_or_wfid) - #ldebug { "cancel_flow() from #{exp_or_wfid}" } + ldebug { "cancel_process() from #{exp_or_wfid}" } root = fetch_root(exp_or_wfid) cancel(root) end - alias :cancel_process :cancel_flow + alias :cancel_flow :cancel_process # # Forgets the given expression (makes sure to substitute its # parent_id with the GONE_PARENT_ID constant) # @@ -513,31 +497,32 @@ fei = exp #ldebug { "fetch() exp is of kind #{exp.class}" } - if exp.kind_of? FlowExpression + if exp.kind_of?(FlowExpression) fei = exp.fei - elsif not exp.kind_of? FlowExpressionId + elsif not exp.kind_of?(FlowExpressionId) raise \ "Cannot fetch expression with key : "+ "'#{fei}' (#{fei.class})" end #ldebug { "fetch() for #{fei.to_debug_s}" } - return get_expression_storage()[fei], fei + [ get_expression_storage()[fei], fei ] end end # # Fetches a FlowExpression (returns only the FlowExpression instance) # # The param 'exp' may be a FlowExpressionId or a FlowExpression that # has to be reloaded. # def fetch_expression (exp) + exp, _fei = fetch(exp) exp end # @@ -549,10 +534,12 @@ return fetch_expression_with_wfid(exp_or_wfid) \ if exp_or_wfid.is_a?(String) exp = fetch_expression(exp_or_wfid) + raise "did not find root for expression #{exp_or_wfid}" unless exp + return exp unless exp.parent_id fetch_root(fetch_expression(exp.parent_id)) end @@ -632,57 +619,61 @@ # There is only one such environment in an engine, hence this # 'singleton' method. # def engine_environment_id () synchronize do + return @eei if @eei + @eei = FlowExpressionId.new @eei.owfe_version = OPENWFERU_VERSION @eei.engine_id = get_engine.service_name @eei.initial_engine_id = @eei.engine_id @eei.workflow_definition_url = 'ee' @eei.workflow_definition_name = 'ee' @eei.workflow_definition_revision = '0' @eei.workflow_instance_id = '0' @eei.expression_name = EN_ENVIRONMENT @eei.expression_id = '0' - return @eei + @eei end end # # Returns the list of applied expressions belonging to a given # workflow instance. # - def get_flow_position (wfid) + def get_process_stack (wfid) raise "please provide a non-nil workflow instance id" \ unless wfid + wfid = to_wfid wfid + result = [] get_expression_storage.real_each do |fei, fexp| next if fexp.kind_of?(Environment) next if fexp.kind_of?(RawExpression) next unless fexp.apply_time - pi = fei.parent_wfid + next if fei.parent_wfid != wfid - next if pi != wfid - result << fexp end ldebug do - "get_flow_position() " + + "process_stack() " + "found #{result.size} exps for flow #{wfid}" end result end + alias :get_flow_stack :get_process_stack + # # Lists all workflows (processes) currently in the expool (in # the engine). # This method will return a list of "process-definition" expressions # (root of flows). @@ -691,35 +682,36 @@ # expressions of subprocesses will be returned as well. # # "wfid_prefix" allows your to query for specific workflow instance # id prefixes. # - def list_workflows (consider_subprocesses=false, wfid_prefix=nil) + def list_processes (consider_subprocesses=false, wfid_prefix=nil) result = [] - get_expression_storage.real_each do |fei, fexp| + # collect() would look better + get_expression_storage.real_each(wfid_prefix) do |fei, fexp| + next unless fexp.is_a? DefineExpression next if not consider_subprocesses and fei.wfid.index(".") - next unless fei.wfid.match("^#{wfid_prefix}") if wfid_prefix + #next unless fei.wfid.match("^#{wfid_prefix}") if wfid_prefix result << fexp end result end - alias :list_processes :list_workflows # # Returns the first expression found with the given wfid. # def fetch_expression_with_wfid (wfid) - list_workflows(false, wfid)[0] + list_processes(false, wfid)[0] end protected # @@ -953,10 +945,47 @@ #puts procdef.raw_expression_class.public_methods procdef.raw_expression_class.new( fei, nil, nil, @application_context, procdef) end + end + # + # a small help class for storing monitors provided on demand + # to expressions that need them + # + class MonitorProvider + include MonitorMixin, Logging + + MAX_MONITORS = 10000 + + def initialize (application_context=nil) + super() + @application_context = application_context + @monitors = LruHash.new(MAX_MONITORS) + end + + def [] (key) + synchronize do + #ldebug { "[] caller :\n" + OpenWFE::caller_to_s(8) } + mon = @monitors[key] + if not mon + #ldebug { "[] creating new Monitor for #{key}" } + mon = Monitor.new + @monitors[key] = mon + else + #ldebug { "[] already had Monitor for #{key}" } + end + return mon + end + end + + def delete (key) + synchronize do + #ldebug { "delete() removing Monitor for #{key}" } + @monitors.delete(key) + end + end end end