Doing
things Parallely
Doing things Conditionally
Doing things in a Loop
Pick and OnAlarm
Lesson
Objectives
nAfter completing this Lesson, you should be
able to do the following:
qAdd parallel flows using the Flow activity
qAdd conditional logic using Switch activity
qExecute loops using While activity
qCreating a web service bottom up
qUnderstand the use cases for Events
qHandle events using pick activity
qUsing a wait activity
qAdding OnAlarm branch to a scope
Processing
with Parallel Flows
nA parallel flow:
qIs implemented in a BPEL <flow> structure
qContains one or more activity
sequences processed concurrently (in parallel)
qEnables synchronization of
dependencies between activities
qCompletes when all sequences in
the flow are finished
Parallel flows implement processing of concurrent
sequences of activities. In BPEL the <flow> element implements the flow structure. The <flow> element may contain
one or more activities to be processed simultaneously, that is, in parallel.
Typically, a sequence of activities are processed in
parallel. Sequences of concurrent processing are enabled by nesting one or more
activities within a <sequence> element, each of
which are contained within the flow.Synchronization of activities is realized because the
flow does not complete until all activities or sequences of activities are
finished processing.
Parallel
Flow Example
nCreate
a process that takes in a string and returns its translation in French, German
and Russian languages.
qFor example, if input is Hello (English), then output is
Bonjour in French, Hallo in German
nIt
uses a translation service to do the job
n
nHowever,
as each of the translations are independent, this can be done parallely
Parallel Flow ExampleCreate
a process that takes in a string and returns its translation in French, German
and Russian languages.For
example, if input is Hello (English), then output is Bonjour in French, Hallo
in German and .. in Russian
Creating
the Translation Service
nWe
want to create a simple web service that takes a string and translates it into
another language.
nThe
web service internally uses Google APIs to get the work done.
nThis
is an example of creating a web service bottom up – create the implementation
first and then generate the WSDL file
nCreate
the java file
nThen
use New > BusinessTier
> Web Services > Java Web Services to create the web service
nDeploy
to Application server
Adding
a Parallel Flow to the Process
Drag a Flow activity from the
Component Palette and drop it into your process
nNote: The flow initially contains two
concurrent sequences.
Adding a Parallel Flow to the ProcessThe Component Palette contains a Flow activity. To add and
configure a parallel flow in your process:1. Drag a Flow activity and drop it
into the Diagram View. For example drop the flow after the AssignRating activity.2. Double-click
the Flow activity to configure it. In the General tab, change the Name to GetPriceQuote. Click OK.Note: The flow is initially created with two branches. Each
branch represents a sequence of activities to be processed in parallel. If you
click the blue down-arrow icon, on the left of the diamond shape representing
the flow, you can add additional branch sequences to the flow.
Conditional
Branching with Switch
nIn BPEL a conditional branch:
qIs implemented by a <switch> element
qConsists of one or more ordered <case> branches, which
nSpecify a condition to be
evaluated
nAre processed in their order of
appearance, and the first branch with a true condition is processed
nContain a sequence of activities
qMay have one <otherwise> branch, which
nIs processed if all <case> conditions are false
nIs optional
nContains a sequence of activities
Conditional Branching with SwitchA conditional branch is structure used
to take different processing paths based on some condition determined by the
data values passed between activities in the process.BPEL implements conditional branching
with the <switch> element, represented by the Switch activity in the Component
Palette. A <switch> element can contain:One or more ordered <case>
branches, each with a condition to be evaluated. The first <case> branch
returning a true result is processed.Optionally, a <otherwise> branch,
which is processed if no <case> branch is processed. If omitted the BPEL
logic assumes an empty activity exists for the otherwise branch.In JDeveloper, when
you drag a Switch activity from the Component Palette and drop it into the
Diagram View the following two conditional branches are created:One <case> branch
An <otherwise> branchYou may add additional <case> branches
as needed. Double-clicking the <case> branch
allows you to specify a comment and a Boolean expression to be evaluated for
the branch. All conditional branches contain a sequence of activities that can
be processed when the branch is select for execution.
Adding
Conditional Branching Logic
Using
While for looping
nDrag a while activity into the process
nSpecify a condition. As long as condition is true, loop will
continue.
Use
cases
nI call a process, and expect it to return
different kinds of responses
nI call a DocumentService, that can return me either a PurchaseOrder or an Invoice or a Receipt
nI want multiple kinds of messages to be able
to initiate my BPEL process.
nI call a asynchronous process, but do not
want to wait indefinitely.
nI want to wait only for a certain
amount of time (say 5 minutes)
Hmm..so whats the common pattern?
nRealize that the first two scenarios can be
dealt with if I have an option to do different things depending upon the
message I receive
nThe third scenario is also similar if I
perceive the indication the system sends me when a particular amount of time
has passed as a message
nThe common pattern, hence, is event driven
processing
Taxonomy
of Events
BPEL supports two types of events:
nMessage events are triggered by incoming messages
nAlarm events are time-related and are triggered either
after a certain duration or at a specific time.
Pick
Activity
nThe
Pick activity is an excellent technique to use to implement a Receive activity
(wait for a message) with a timeout. This is accomplished by using both of the
following:
nAn onMessage branch to receive a specific
message from an operation exposed by a service through a PartnerLink
nAn onAlarm branch that implements a wait
time
nThe
Pick activity terminates when a message or an alarm event occurs, whichever
occurs first.
nPick
activity can be configured with multiple onMessage and onAlarm branches
Suspending
a Process with a Wait Activity
nThe
Wait activity pauses for a specified amount of time or until a specified time
period.
nWaiting
for specified amount of time
q<wait name="Wait_1" for="'PT2M'"/>
qP1Y2M3DT4H5M6S – Wait for 1 year, 2 months, 3 days, 4 hours, 5
minutes and 6 seconds
nWaiting
until a certain time
q<wait name="Wait_2"
until="'2007-02-28T12:43:59'"/>
Raise
the alarm, but still keep waiting
nWhile
I want to raise an alarm if the process doesn’t return after certain interval,
I still want to wait for the response
nUse
the On Alarm branch available to a scope.
nIf
any activity in a scope has to wait for more than the time configured in the On
Alarm branch, an alarm is raised.
Pick vs OnAlarm
nPick is a activity, OnAlarm is a
branch that can be added to any scope
nIn Pick, after the alarm, one of the paths
will be chosen. In OnAlarm,
after the alarm, just an alarm is raised, but no other action is done.
Notes
The Oracle BPEL Process Manager uses the open
source Quartz Scheduler Library to implement the schedule expiration events for
the wait and onAlarm
branch of pick activities