Flowable getting started series article 39 - gateway 01

Keywords: Java Flowable oa bpm

The gateway is used to control the execution process (or the execution token described in BPMN 2.0). The gateway can consume or generate tokens.

A gateway is graphically displayed as a diamond with an icon inside. This icon displays the type of gateway.

1. Exclusive gateway

describe

Exclusive gateways (also known as XOR gateways or more specialized data-based gateways) are used to model decisions in the process. When the execution reaches the gateway, all outgoing sequence flows will be evaluated in the order they are defined. The first sequence flow with the selection condition evaluated as true (or no condition set, conceptually defined as "true" in the sequence flow) is selected to continue the process.

Note that in this case, the semantics of the output sequence flow is different from the general situation in BPMN 2.0. In general, all sequence streams evaluated as true are selected to continue in parallel, while only one sequence stream is selected when using a dedicated gateway. If multiple sequence streams have a condition that evaluates to true, select the first (and only that!) defined in the XML to continue the process. If there is no sequential process to choose from, an exception will be thrown.

Graphical representation

The exclusive gateway is regarded as a typical gateway (diamond). There is an X icon in it, which refers to XOR semantics. Note that gateways without icons default to exclusive gateways. The BPMN 2.0 specification does not allow diamond blocks with and without x to be used in the same process definition.

XML representation

The XML representation of the exclusive gateway is straightforward: a line defines the gateway and conditional expressions defined on the outbound sequence stream. Review the section on the conditional order process to see which options are available for such expressions.

Take the following model as an example:

It is expressed in XML as follows:

<exclusiveGateway id="exclusiveGw"name="Exclusive Gateway"/>
<sequenceFlow id="flow2"sourceRef="exclusiveGw"targetRef="theTask1">
<conditionExpression xsi:type="tFormalExpression">${input==1}</conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow3"sourceRef="exclusiveGw"targetRef="theTask2">
<conditionExpression xsi:type="tFormalExpression">${input==2}</conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow4"sourceRef="exclusiveGw"targetRef="theTask3">
<conditionExpression xsi:type="tFormalExpression">${input==3}</conditionExpression>
</sequenceFlow>

2. Parallel gateway

describe

Gateways can also be used to simulate concurrency in processes. The most direct process model in the gateway introduces concurrency. It is a parallel gateway, which allows you to cross into multiple execution paths or join multiple incoming paths for execution.

The functions of the parallel gateway are based on input and output sequence streams:

  • fork: execute all outgoing sequence flows in parallel, and create a concurrent execution for each sequence flow.
  • Connection: all concurrent executions arriving at the parallel gateway wait in the gateway until the execution of each incoming sequence flow is completed. The process then continues through the joined gateway.

Note that if a parallel gateway has multiple incoming and outgoing sequence flows, the parallel gateway can have both bifurcation and connection behavior. In this case, the gateway will first join all incoming sequence flows, and then decompose them into multiple concurrent execution paths.

An important difference from other gateway types is that parallel gateways do not evaluate conditions. If conditions are defined on the sequential flow connected to the parallel gateway, they are simply ignored.

Graphical representation

A parallel gateway is visualized as a gateway with a plus sign (diamond shape), referencing AND semantics.

XML representation

One line of XML is required to define the parallel gateway:

<parallelGateway id="myParallelGateway" />

The actual behavior (fork, join, or both) is defined by the sequence flow connected to the parallel gateway.

For example, the above model boils down to the following XML:

<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" />

In the above example, after the process starts, two tasks will be created:

ProcessInstance pi=runtimeService.startProcessInstanceByKey("forkJoin");
        TaskQuery query=taskService.createTaskQuery()
        .processInstanceId(pi.getId())
        .orderByTaskName()
        .asc();
        List<Task> tasks=query.list();
        assertEquals(2,tasks.size());
        Task task1=tasks.get(0);
        assertEquals("Receive Payment",task1.getName());
        Task task2=tasks.get(1);
        assertEquals("Ship Order",task2.getName());

When the two tasks are completed, the second parallel gateway will join the two executions. Since there is only one output sequence flow, no concurrent execution path will be created, and only the archive command task is active.

Note that parallel gateways do not need to be balanced (the matching number of input / output sequence streams of the corresponding parallel gateway). The parallel gateway will simply wait for all incoming sequence flows and create a concurrent execution path for each outgoing sequence flow, independent of other constructs in the process model. Therefore, the following process is legal in BPMN 2.0:

The above article is from Pangu BPM Research Institute: http://vue.pangubpm.com/
Article translation submission: https://github.com/qiudaoke/flowable-userguide
For more articles, you can focus on WeChat official account:

Posted by cs.punk on Thu, 28 Oct 2021 16:10:45 -0700