Usage of Flow and Links
Objective
This sample explains the usage of flows and links.
Introducing Flows and Links
Usually, the activities defined inside a <flow/> element can be performed concurrently, but there can be dependencies in-between activities. <links/>, <sources/> and <targets/> are used to define synchronization dependencies in-between these activities. Let's understand what's meant by <links/>, <sources/> and <targets/>.
In the <flow/>, we define <links/> as follows. The link names can be sources or targets of the activities inside <flow/>.
<bpel:flowname="EndlessRunningFlowOfPain"> <bpel:links><bpel:linkname="transition1"/></bpel:links> <bpel:sequencename="Seq1"> <bpel:sources> <bpel:sourcelinkName="transition1"/> </bpel:sources> <bpel:empty/> </bpel:sequence> <bpel:ifname="IfDependOnSeq1"> <bpel:targets> <bpel:targetlinkName="transition1"/> </bpel:targets> ....... </bpel:if> </bpel:flow>
The link names can be sources or targets of the activities inside <flow/>. Using <sources/> and <targets/>, user can specify "IfDependOnSeq1" activity that should be executed after Seq1. Which means the Source activity should be executed before Target activity.
There are optional constructs to mimic conditional behavior for the <source/> and <target/> as follows:
<transactionCondition/>
- used in <source/>
- initializes a logical condition for the source link based on a logical condition. For example,
<invoke...><sources><sourcelinkName="Link1"><transitionCondition> $tmpVar=1 </transitionCondition></source></sources> ... </invoke>
<joinCondition/>
- used in <targets/>
- evaluates a logical condition
- if the logical condition is true, then all the incoming sources for the defined <target/> should be true.
- if the logical condition is
false
, ajoinFailure
exception will be thrown (Unless the target activity hasn'tsuppressJoinFailure=true
). For example,
<invoke...> <targets> <joinCondition> $Link1 and $Link2 </joinCondition> <targetlinkName="Link1"/> <targetlinkName="Link2"/> </targets> </invoke>
Deploying the Sample
WSO2 BPS provides a sample, which can be deployed and executed to understand the constructs. Follow the instructions below to deploy and trigger the process.
1. Log in into BPS server management console and select "Processes -> Add" under the "Main" menu.
2. Upload the TestFlowLinks.zip. (Samples are located at our sample repository).
3. In the "Deployed Processes" window, click the "Process ID" to access its "Process Information" window.
4. Under the "WSDL Details" widget, trigger the process using the "TryIt" link to create an instance of it.
Example Usage
Refer to TestFlowLinks.zip. The following diagram depicts its usage:
The sample implements a sequence of activities inside a <flow/> element, where there can be 3 execution paths based on the conditions defined in 2 and 5 in the diagram. Some of the possible execution paths are as follows.
- If
TransitionResolver
's if condition istrue
andTransitionResolver2
's if condition istrue
- 1 -> 2 -> 4 -> 5 -> 6
- 3
- If
TransitionResolver
's elseIf condition istrue
andTransitionResolver2
's if condition istrue
- 1 -> 2 -> 3
- 4 -> 5 -> 6
- If
TransitionResolver
/s if condition istrue
andTransitionResolver2
's if condition isfalse
- 1 -> 2 -> 4 -> 5
- 3
- 6