Gateways
网关
A gateway is used to control the flow of execution (or as the BPMN 2.0 describes, the tokens of execution). A gateway is capable ofconsuming or generating tokens.
网关用来控制流程的执行(或者像BPMN2.0所描述:执行的令牌)。一个网关是可以销毁或产生令牌的。
A gateway is graphically visualized as a diamond shape, with an icon inside. The icon shows the type of gateway.
网关通常使用一个带有内部图标菱形图形进行表示。内部图标则表示网关的类型。
Exclusive gateway
唯一网关
描述
An exclusive gateway (also called the XOR gateway or more technical the exclusive data-based gateway), is used to model a decision in the process. When the execution arrives at this gateway, all outgoing sequence flow are evaluated in the order in which they are defined. The sequence flow which condition evaluates to true (or which doesn't have a condition set, conceptually having a 'true' defined on the sequence flow) is selected for continuing the process.
唯一网关(也称之为XOR 网关,或更技术一点的:基于数据的唯一网关),常用来为流程判断来建模。当执行到达了该网关时,所有的外出顺序流将按照定义的顺序被求值,被求值为真(或者没有设置条件的,我们默认为true)的顺序流将被用来继续流程执行。
Note that the semantics of outgoing sequence flow is different to that of the general case in BPMN 2.0. While in general all sequence flow which condition evaluates to true are selected to continue in a parallel way, only one sequence flow is selected when using the exclusive gateway. In case multiple sequence flow have a condition that evaluates to true, the first one defined in the XML (and only that one!) is selected for continuing the process. If no sequence flow can be selected, an exception will be thrown.
需要注意的是这里外出顺序流的语义是与BPMN2.0中一般例子中的有些区别的。在一般的情况下所有被求值为真的顺序流都会被以并行的方式执行,而在唯一网关中只有一个顺序流被执行。如果多个顺序被求值为真,那么在XML中定义的第一个(也只有这个)会被选中并继续执行。如果没有顺序流被选择,那么就是抛出一个异常。
图形符号
An exclusive gateway is visualized as a typical gateway (i.e. a diamond shape) with an 'X' icon inside, referring to the XOR semantics. Note that a gateway without an icon inside defaults to an exclusive gateway. The BPMN 2.0 specification does not allow mixing the diamond with and without an X in the same process definition.
唯一网关的图形表示是在标准的网关符号(菱形)中增加一个’X’图标,用来表示XOR的意思。注意如果网关符号中没有内部的小图标缺省也表示为唯一网关。在BPMN2.0标准中是不允许在一个流程定义中混合使用这两种符号的。
XML representation
XML 表示
The XML representation of an exclusive gateway is straight-forward: one line defining the gateway and condition expressions defined on the outgoing sequence flow. See the section on conditional sequence flow to see which options are available for such expressions.
唯一网关的XML表示是比较容易理解的:一行用来定义网关,条件表达式则定义的顺序流中。请参考条件顺序流章节了解表达式中那些选项可以使用。
Take for example the following model:
接下来是一个样例:
Which is represented in XML as follows:
XML表示如下:
<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>
Parallel Gateway
并行网关
描述
Gateways can also be used to model concurrency in a process. The most straightforward gateway to introduce concurrency in a process model, is the Parallel Gateway, which allows to fork into multiple paths of execution or join multiple incoming paths of execution.
网关也可以用来为流程并发建模。流程模型中用来进行并发控制的最常用的网关就是并行网关,并行网关可以用来将执行拆分成多个并行的路径,也可以用来汇总执行的多个到达路径。
The functionality of the parallel gateway is based on the incoming and outgoing sequence flow:
并行网关的功能依赖于进入或流出的顺序流:
Note that a parallel gateway can have both fork and join behavior, if there are multiple incoming and outgoing sequence flow for the same parallel gateway. In that case, the gateway will first join all incoming sequence flow, before splitting into multiple concurrent paths of executions.
需要注意的是并行网关可以同时拥有fork和join功能,如果该并行网关同时拥有多个进入顺序流和多个外出顺序流。此时,并行网关在将流程分成多个并行路径执行之前会先合并所有进入顺序流。
An important difference with other gateway types is that the parallel gateway does not evaluate conditions. If conditions are defined on the sequence flow connected with the parallel gateway, they are simply neglected.
与其它类型的网关不同的是并行网关不会对顺序流中所定义的条件进行求值。连接到并行网关的顺序流如果定义了条件,网关会简单的忽略它。
图形符号
A parallel gateway is visualized as a gateway (diamond shape) with the 'plus' symbol inside, referring to the 'AND' semantics.
并行网关的图形符号是在网关(菱形)符号中增加一个带+号的内部图标来表示,表示“与”的意思。
XML representation
XML表示
Defining a parallel gateway needs one line of XML:
定义一个并行网关仅需要一行XML:
<parallelGateway id="myParallelGateway" />The actual behavior (fork, join or both), is defined by the sequence flow connected to the parallel gateway.
实际行为(fork、join还是同时),则依赖于与并行网关相连接的顺序流。
For example, the model above comes down to the following XML:
上面的模型可以用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 is started, two tasks will be created:
在上面的示例中,当流程启动后会有两个任务被创建:
ProcessInstance pi = runtimeService.startProcessInstanceByKey("forkJoin"); TaskQuery query = taskService.createTaskQuery() .processInstanceId(pi.getId()) .orderAsc(TaskQuery.PROPERTY_NAME); 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 these two tasks are completed, the second parallel gateway will join the two executions and since there is only one outgoing sequence flow, no concurrent paths of execution will be created, and only the Archive Order task will be active.
当这两个任务完成时,第二个并行网关就会把这两个执行进行合并,因为之后只有一个外出顺序流,所以不会创建并行流程执行,只有一个Archive Order任务被激活。
Note that a parallel gateway does not need to be 'balanced' (i.e. a matching number of incoming/outgoing sequence flow for corresponding parallel gateways). A parallel gateway will simply wait for all incoming sequence flow and create a concurrent path of execution for each outgoing sequence flow, not influenced by other constructs in the process model. So, the following process is legal in BPMN 2.0:
注意,并行网关不需要进行“平衡”(也就是说进入/流出的顺序流数目不需要一致)。并行网关只是简单的等待所有进入顺序流,并为所有外出顺序流创建并行执行路径,不要受其它流程建模构件的影响。因此,下面这个流程在BPMN2.0中是合法的: