Gateways
Gateways in BPMN are used to control the divergence and convergence of the process flow. They provide a mechanism to split or merge multiple paths, controlling the flow logic. In tSM, the following gateway types are supported, each with its own unique semantics:
- Exclusive Gateway (XOR)
- Parallel Gateway
- Inclusive Gateway
- Event-based Gateway
tSM processes rely on the standard BPMN 2.0 semantics for gateways. This means that the underlying behavior, conditions, and XML notations are consistent with BPMN 2.0.
Exclusive Gateway (XOR)
Concept:
An Exclusive Gateway models a decision within the process. When the flow arrives at an exclusive gateway, all outgoing sequence flows are evaluated in the order they are defined. The process will follow the first sequence flow whose condition evaluates to true
. If multiple conditions evaluate to true
, only the first one is used. If no condition matches and no default flow is defined, a runtime exception is thrown.
Key Points:
- Only one outgoing sequence flow is selected.
- Conditions are defined on the outgoing sequence flows, not on the gateway itself.
- A default flow can be specified to handle cases where no condition matches.
Example Conditions:
- Condition expressions use SpEL scripting for evaluation.
- A default sequence flow can act like an
else
clause.
XML Example:
<exclusiveGateway id="exclusiveGw" name="Exclusive Gateway" default="flow4" />
<sequenceFlow id="flow2" sourceRef="exclusiveGw" targetRef="theTask1" name="${x==1}">
<conditionExpression xsi:type="tFormalExpression">${x == 1}</conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow3" sourceRef="exclusiveGw" targetRef="theTask2" name="${x==2}">
<conditionExpression xsi:type="tFormalExpression">${x == 2}</conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow4" sourceRef="exclusiveGw" targetRef="theTask3" name="else" />
Parallel Gateway
Concept:
A Parallel Gateway is used to model concurrency. It can both split one flow into multiple parallel paths and join multiple parallel paths into one. When forking, all outgoing flows are triggered without condition. When joining, the gateway waits until a token has arrived from each of its incoming flows before proceeding.
Key Points:
- No conditions are evaluated on outgoing flows.
- When forking, all outgoing paths are executed in parallel.
- When joining, it synchronizes multiple incoming flows, waiting for all required tokens.
XML Example:
<startEvent id="theStart" />
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="fork" />
<parallelGateway id="fork" />
<sequenceFlow sourceRef="fork" targetRef="receivePayment" />
<sequenceFlow sourceRef="fork" targetRef="shipOrder" />
<userTask id="receivePayment" name="Receive Payment" />
<sequenceFlow sourceRef="receivePayment" targetRef="join" />
<userTask id="shipOrder" name="Ship Order" />
<sequenceFlow sourceRef="shipOrder" targetRef="join" />
<parallelGateway id="join" />
<sequenceFlow sourceRef="join" targetRef="archiveOrder" />
<userTask id="archiveOrder" name="Archive Order" />
<sequenceFlow sourceRef="archiveOrder" targetRef="theEnd" />
<endEvent id="theEnd" />
Inclusive Gateway
Concept:
An Inclusive Gateway is a combination of the characteristics of Exclusive and Parallel Gateways. Similar to the Exclusive Gateway, conditions on outgoing flows determine which paths are taken. However, unlike the Exclusive Gateway, more than one path can be taken if multiple conditions evaluate to true
. When joining, the Inclusive Gateway waits for all tokens from the activated incoming paths before proceeding.
Key Points:
- Evaluates all outgoing conditions; any flow whose condition evaluates to
true
is followed. - If multiple conditions are
true
, multiple paths are taken in parallel. - When joining, it only waits for those incoming paths that have been activated.
- A default sequence flow can prevent exceptions if no conditions match.
XML Example:
<startEvent id="theStart" />
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="fork" />
<inclusiveGateway id="fork" />
<sequenceFlow sourceRef="fork" targetRef="receivePayment">
<conditionExpression xsi:type="tFormalExpression">${paymentReceived == false}</conditionExpression>
</sequenceFlow>
<sequenceFlow sourceRef="fork" targetRef="shipOrder">
<conditionExpression xsi:type="tFormalExpression">${shipOrder == true}</conditionExpression>
</sequenceFlow>
<userTask id="receivePayment" name="Receive Payment" />
<sequenceFlow sourceRef="receivePayment" targetRef="join" />
<userTask id="shipOrder" name="Ship Order" />
<sequenceFlow sourceRef="shipOrder" targetRef="join" />
<inclusiveGateway id="join" />
<sequenceFlow sourceRef="join" targetRef="archiveOrder" />
<userTask id="archiveOrder" name="Archive Order" />
<sequenceFlow sourceRef="archiveOrder" targetRef="theEnd" />
<endEvent id="theEnd" />
Event-based Gateway
Concept:
An Event-based Gateway is used to model a wait state in the process until one of several possible events occurs. The sequence flows coming out of an Event-based Gateway must connect to intermediate catching events. The process execution pauses at the gateway until one of the connected events is triggered. When one event fires, the other event subscriptions are canceled.
Key Points:
- Outgoing flows must connect to intermediate catching events (e.g., signal, timer).
- The gateway subscribes to all these events and proceeds along the sequence flow of the first event that occurs.
- This approach enables processes to branch based on external triggers or timeouts rather than internal conditions.
XML Example:
<definitions>
<signal id="alertSignal" name="alert" />
<process id="catchSignal">
<startEvent id="start" />
<sequenceFlow sourceRef="start" targetRef="gw1" />
<eventBasedGateway id="gw1" />
<sequenceFlow sourceRef="gw1" targetRef="signalEvent" />
<sequenceFlow sourceRef="gw1" targetRef="timerEvent" />
<intermediateCatchEvent id="signalEvent" name="Alert">
<signalEventDefinition signalRef="alertSignal" />
</intermediateCatchEvent>
<intermediateCatchEvent id="timerEvent" name="Alert">
<timerEventDefinition>
<timeDuration>PT10M</timeDuration>
</timerEventDefinition>
</intermediateCatchEvent>
<sequenceFlow sourceRef="timerEvent" targetRef="exGw1" />
<sequenceFlow sourceRef="signalEvent" targetRef="task" />
<userTask id="task" name="Handle alert"/>
<exclusiveGateway id="exGw1" />
<sequenceFlow sourceRef="task" targetRef="exGw1" />
<sequenceFlow sourceRef="exGw1" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
Default and Conditional Sequence Flows
Concept:
Sequence flows can have conditions defined using formal expressions. At runtime, these conditions are evaluated to determine the path the process should follow. A default sequence flow can be specified to handle situations where no conditions match. Default sequence flows are ignored when evaluating conditions.
Example:
-
Conditional flows:
<sequenceFlow id="flow" sourceRef="theStart" targetRef="theTask">
<conditionExpression xsi:type="tFormalExpression">
<![CDATA[${order.price > 100 && order.price < 250}]]>
</conditionExpression>
</sequenceFlow> -
Default flow (specified by the
default
attribute on the gateway/activity):<exclusiveGateway id="exclusiveGw" default="flow4" />
<sequenceFlow id="flow4" sourceRef="exclusiveGw" targetRef="theTask3" name="else" />