lib/openwfe/engine/engine.rb in openwferu-0.9.2 vs lib/openwfe/engine/engine.rb in openwferu-0.9.3
- old
+ new
@@ -38,10 +38,12 @@
#
# John Mettraux at openwfe.org
# Nicolas Modrzyk at openwfe.org
#
+require 'logger'
+
require 'openwfe/workitem'
require 'openwfe/rudefinitions'
require 'openwfe/service'
require 'openwfe/util/schedulers'
require 'openwfe/expool/expressionpool'
@@ -63,55 +65,96 @@
super(S_ENGINE, {})
@application_context[@service_name] = self
+ build_scheduler()
+
build_expression_map()
- build_expression_pool()
build_expression_storage()
+ build_expression_pool()
+
build_participant_map()
- build_scheduler()
- init_default_logging('engine.log')
+ $OWFE_LOG = Logger.new("engine.log") unless $LOG
end
#
# Launches a [business] process.
- # The 'object' param may contain either a LaunchItem instance,
+ # The 'launch_object' param may contain either a LaunchItem instance,
# either a String containing the URL of the process definition
# to launch (with an empty LaunchItem created on the fly).
#
- def launch (object)
+ def launch (launch_object)
launchitem = nil
- #ldebug { "launch() param is #{object.class}" }
-
- if object.kind_of? OpenWFE::LaunchItem
- launchitem = object
- #elsif object.kind_of? REXML::Element
- #nada
- elsif object.kind_of? String
+ if launch_object.kind_of? OpenWFE::LaunchItem
+ launchitem = launch_object
+ elsif launch_object.kind_of? Class
+ launchitem = LaunchItem.new(launch_object)
+ elsif launch_object.kind_of? String
launchitem = OpenWFE::LaunchItem.new
- if object[0] == '<'
+ if launch_object[0] == '<'
launchitem.workflowDefinitionUrl = "field:__definition"
- launchitem['definition'] = object
+ launchitem['definition'] = launch_object
else
- launchitem.workflowDefinitionUrl = object
+ launchitem.workflowDefinitionUrl = launch_object
end
end
get_expression_pool.launch(launchitem)
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.
+ #
+ def reply (workitem)
+
+ get_expression_pool.reply(workitem.last_expression_id, workitem)
+ end
+
+ #
# Registers a participant in this [embedded] engine.
# This method is a shortcut to the ParticipantMap method
# with the same name.
#
def register_participant (regex, participant=nil, &block)
get_participant_map.register_participant(regex, participant, &block)
+ end
+
+ #
+ # Given a participant name, returns the participant in charge
+ # of handling workitems for that name.
+ # May be useful in some embedded contexts.
+ #
+ def get_participant (participant_name)
+
+ get_participant_map.lookup_participant(participant_name)
+ end
+
+ #
+ # Stopping the engine will stop all the services in the
+ # application context.
+ #
+ 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
protected
#