lib/openwfe/participants/participants.rb in openwferu-0.9.12 vs lib/openwfe/participants/participants.rb in openwferu-0.9.12.863
- old
+ new
@@ -28,12 +28,10 @@
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#++
#
-# $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $
-#
#
# "made in Japan"
#
# John Mettraux at openwfe.org
@@ -66,11 +64,11 @@
# The constructor expects as a unique optional param either the
# application_context either the 'output' dir for the participant.
#
def initialize (context_or_dir=nil)
- @workdir = OpenWFE::get_work_directory(context_or_dir) + "/out/"
+ @workdir = get_work_directory(context_or_dir) + "/out/"
@reply_anyway = false
end
#
@@ -188,10 +186,11 @@
#
# Simply discards the incoming workitem
#
def consume (workitem)
+ # does nothing and does not reply to the engine.
end
end
#
# The NoOperationParticipant immediately replies to the engine upon
@@ -208,11 +207,11 @@
end
end
#
# The PrintParticipant will just emit its name to the
- # test tracer if any or to stdout else.
+ # test tracer if any or to the stdout else.
# Used by some unit tests.
#
class PrintParticipant
include LocalParticipant
@@ -226,9 +225,101 @@
else
puts workitem.participant_name
end
reply_to_engine(workitem)
+ end
+ end
+
+ #
+ # Links a process under a participant [name].
+ #
+ # Turns top level processes into participants
+ #
+ # Some examples :
+ #
+ # require 'engine/participants/participants'
+ #
+ # engine.register_participant(
+ # "transmit_to_accounting",
+ # "http://company.process.server.ie/processes/acc0.xml")
+ #
+ # engine.register_participant(
+ # "hr_resume_review_process",
+ # "file:/var/processes/hr_resume_review_process.rb")
+ #
+ # Some more examples :
+ #
+ # class RegistrationProcess < OpenWFE::ProcessDefinition
+ # sequence do
+ # participant :ref => "Alice"
+ # participant :ref => "Bob"
+ # end
+ # end
+ #
+ # # later in the code ...
+ #
+ # engine.register_participant("registration", RegistrationProcess)
+ #
+ # Or directly with some XML string :
+ #
+ # engine.register_participant("registration", '''
+ # <process-definition name="registration" revision="0.1">
+ # <sequence>
+ # <participant ref="Alice" />
+ # <participant ref="Bob" />
+ # </sequence>
+ # </process-definition>
+ # '''.strip)
+ #
+ # It's then easy to call the subprocess as if it were a participant :
+ #
+ # sequence do
+ # participant :ref => "registration"
+ # # or
+ # participant "registration"
+ # # or simply
+ # registration
+ # end
+ #
+ # Note that the 'subprocess' expression may be used as well :
+ #
+ # sequence do
+ # subprocess ref => "http://dms.company.org/processes/proc1.rb"
+ # end
+ #
+ # But you can't use the URL as an expression name for writing nice,
+ # concise, process definitions.
+ #
+ class ProcessParticipant
+ include LocalParticipant
+
+ #
+ # The 'object' may be the URL of a process definition or the process
+ # definition itself as an XML string or a Ruby process definition
+ # (as a class or in a String).
+ #
+ def initialize (object)
+
+ super()
+
+ template_uri = OpenWFE::parse_known_uri object
+
+ @template = template_uri || object
+ end
+
+ #
+ # This is the method called by the engine when it has a workitem
+ # for this participant.
+ #
+ def consume (workitem)
+
+ get_expression_pool.launch_template(
+ get_flow_expression(workitem),
+ 0, #sub_id
+ @template,
+ workitem)
+ #params)
end
end
end