lib/openwfe/engine/engine.rb in openwferu-0.9.6 vs lib/openwfe/engine/engine.rb in openwferu-0.9.7
- old
+ new
@@ -45,10 +45,11 @@
require 'openwfe/workitem'
require 'openwfe/rudefinitions'
require 'openwfe/service'
require 'openwfe/util/scheduler'
require 'openwfe/util/schedulers'
+require 'openwfe/expool/wfidgen'
require 'openwfe/expool/expressionpool'
require 'openwfe/expool/expstorage'
require 'openwfe/expressions/expressionmap'
require 'openwfe/participants/participantmap'
@@ -80,24 +81,45 @@
build_scheduler()
build_expression_map()
+ build_wfid_generator()
build_expression_pool()
build_expression_storage()
build_participant_map()
- #
- # engine components are ready for operation, it's time to
- # check persisted expressions (if any) to see if something
- # has to be rescheduled (like a long time sleep expression or
- # a cron)
+ #get_expression_pool.reschedule()
+ linfo { "new() --- engine started --- #{self.object_id}" }
+ end
+
+ #
+ # Call this method once the participant for a persisted engine
+ # have been [re]added.
+ # If you call this method too soon, missing participants will
+ # cause troubles... Call this method after all the participants
+ # have been added.
+ #
+ def reschedule
get_expression_pool.reschedule()
+ end
- linfo { "new() --- engine started --- #{self.object_id}" }
+ alias :reload :reschedule
+
+ #
+ # When 'parameters' are used at the top of a process definition, this
+ # method can be used to assert a launchitem before launch.
+ # An expression will get raised if the parameters do not match the
+ # requirements.
+ #
+ # Note that the launch method will raise those exceptions as well.
+ # This method can be useful in some scenarii though.
+ #
+ def pre_launch_check (launchitem)
+ get_expression_pool.prepare_raw_expression(launchitem)
end
#
# Launches a [business] process.
# The 'launch_object' param may contain either a LaunchItem instance,
@@ -136,20 +158,10 @@
get_expression_pool.launch(launchitem, async)
end
#
- # Returns the list of applied expressions belonging to a given
- # workflow instance.
- # May be used to determine where a process instance currently is.
- #
- def get_flow_position (workflow_instance_id)
-
- get_expression_pool.get_flow_position(workflow_instance_id)
- end
-
- #
# This method is used to feed a workitem back to the engine (after
# it got sent to a worklist or wherever by a participant).
# Participant implementations themselves do call this method usually.
#
# This method also accepts LaunchItem instances.
@@ -280,31 +292,111 @@
def stop
linfo { "stop() stopping engine '#{@service_name}'" }
@application_context.each do |name, service|
+
next if name == self.service_name
+
#service.stop if service.respond_to? :stop
+
if service.kind_of? ServiceMixin
service.stop
linfo do
"stop() stopped service '#{service.service_name}' "+
"(#{service.class})"
end
end
end
end
+ #
+ # METHODS FROM THE EXPRESSION POOL
+ #
+ # These methods are 'proxy' to method found in the expression pool.
+ # They are made available here for a simpler model.
+ #
+
+ #
+ # Returns the list of applied expressions belonging to a given
+ # workflow instance.
+ # May be used to determine where a process instance currently is.
+ #
+ def get_flow_position (workflow_instance_id)
+ get_expression_pool.get_flow_position(workflow_instance_id)
+ end
+ alias :get_process_position :get_flow_position
+
+ #
+ # Lists all workflows (processes) currently in the expool (in
+ # the engine).
+ # This method will return a list of "process-definition" expressions
+ # (root of flows).
+ #
+ # If consider_subprocesses is set to true, "process-definition"
+ # 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)
+
+ get_expression_pool.list_workflows(
+ consider_subprocesses, wfid_prefix)
+ end
+ alias :list_processes :list_workflows
+
+ #
+ # Given any expression of a process, cancels the complete process
+ # instance.
+ #
+ def cancel_flow (exp_or_wfid)
+ get_expression_pool.cancel_flow(exp_or_wfid)
+ end
+ alias :cancel_process :cancel_flow
+
+ #
+ # Cancels the given expression (and its children if any)
+ # (warning : advanced method)
+ #
+ def cancel_expression (exp_or_fei)
+ get_expression_pool.cancel(exp_or_fei)
+ end
+
+ #
+ # Forgets the given expression (make it an orphan)
+ # (warning : advanced method)
+ #
+ def forget_expression (exp_or_fei)
+ get_expression_pool.forget(exp_or_fei)
+ end
+
protected
#
# the following methods may get overridden upon extension
# see for example file_persisted_engine.rb
#
def build_expression_map ()
- init_service(S_EXPRESSION_MAP, ExpressionMap)
+ @application_context[S_EXPRESSION_MAP] = ExpressionMap.new
+ #
+ # the expression map is not a Service anymore,
+ # it's a simple instance (that will be reused in other
+ # OpenWFEru components)
+
+ #ldebug do
+ # "build_expression_map() :\n" +
+ # get_expression_map.to_s
+ #end
+ end
+
+ def build_wfid_generator ()
+
+ #init_service(S_WFID_GENERATOR, DefaultWfidGenerator)
+ #init_service(S_WFID_GENERATOR, UuidWfidGenerator)
+ init_service(S_WFID_GENERATOR, KotobaWfidGenerator)
end
def build_expression_pool ()
init_service(S_EXPRESSION_POOL, ExpressionPool)