Java Reference
In-Depth Information
Preventing some children from executing
Sometimes you want to prevent some of the child activities in a loop from executing. To speci-
fy this, you can optionally use a <completionCondition> child in your <forEach> . A <com-
pletionCondition> lets you indicate that you only need to perform N number of branches of
a number of M possible branches. The process will ignore any remaining branches after N is
reached. That is how <completionCondition> is used in the sequential version of the loop.
We'll look at what it means for parallel executions in a moment. Here's the basic construct:
<forEach parallel="yes|no">
....
<completionCondition>
<branches>...
</completionCondition>
<scope>...
The completion condition is evaluated before the loop starts. Once the condition is met, pro-
cessing breaks out of the loop. It evaluates to an xs:unsignedInt that represents the value
for N.
If you want to count only the iterations that have completed normally, you can set the
<branches successfulBranchesOnly="yes"> attribute.
NOTE
To make your branches run in parallel, simply set the parallel attribute of the loop to “yes”.
The <completionCondition> can be used in the parallel version of the loop to indicate that
you want to terminate some of the child activities early.
Let's look at an example that runs in parallel and supplies a <completionCondition> that
limits the number of successful executions that need to be completed before the loop is al-
lowed to quit. In this example, you are processing invitations to a seminar. You will go ahead
and book a room if a requisite number of people are going to come; otherwise, you might just
cancel. So in this scenario, you've sent out 300 invitations, and once you receive 50 confirm-
ations, you'll break out of the loop and go on with the process:
<forEach counterName="i" parallel="yes">
<startCounterValue>1</startCounterValue>
<finalCounterValue>300</finalCounterValue>
<completionCondition>
<branches successfulBranchesOnly="yes">50</branches>
</completionCondition>
Search WWH ::




Custom Search