Activiti entry 3 exclusive gateway, parallel network management, including gateway and event Gateway

Source: Internet
Author: User

The gateway is used to control the flow of the process. The Gateway can consume or generate a token.

The gateway is displayed as a diamond graph with a small internal icon. The icon indicates the type of the gateway.

Basic Branch

First, use process variables to write a basic process with branches

Flowchart:




Deployment process file:

// Obtain the Process Engine processengine = processengines. getdefaprocesprocessengine (); @ testpublic void deployflow () {// obtain the repository service object repositoryservice = processengine. getrepositoryservice (); inputstream in = This. getclass (). getresourceasstream ("/myprocess11.zip"); zipinputstream = new zipinputstream (in); deployment dm = repositoryservice. createdeployment (). name ("Student leave "). addzipinputstream (zipinputstream ). deploy (); system. out. println ("ID:" + DM. GETID () + ", name:" + DM. getname ());}
Start the process and set the leave days to 3 days for process variable submission

/*** Start the process and complete the submission */@ testpublic void startprocessandcomp () {runtimeservice = processengine. getruntimeservice (); processinstance Pi = runtimeservice. startprocessinstancebykey ("leave"); system. out. println ("ID:" + pi. GETID () + ", process instance id:" + pi. getprocessinstanceid () + ", process definition ID:" + pi. getprocessdefinitionid (); taskservice = processengine. gettaskservice (); // obtain the task object task = taskser by the process instance id Vice. createtaskquery (). processinstanceid (Pi. getprocessinstanceid ()). singleresult (); system. out. println ("taskid:" + task. GETID () + ", name:" + task. getname (); Map <string, Object> parammap = new hashmap <string, Object> (); // set the flow variable day = 3parammap. put ("day", 3); // input the process variable taskservice when submitting the task. complete (task. GETID (), parammap); // query task = taskservice. createtaskquery (). processinstanceid (Pi. getprocessinstanceid ()). singl Eresult (); // if the task object is empty, the process execution ends if (task! = NULL) {system. out. println ("taskid:" + task. GETID () + ", name:" + task. getname ();} else {system. out. println ("task completed ");}}

The final running result is as follows:

ID: 1501, process instance id: 1501, process definition ID: Leave: 2: 1404 taskid: 1504, name: the class teacher has completed the task.

We can check it in the database:





Deploy another process file and set the leave days of the Process Variables to 10 days when submitting the task.


Final running result

ID: 1701, process instance id: 1701, process definition ID: Leave: 3: 1604 taskid: 1704, name: class teacher taskid: 1707, name: grade Director

Now the process goes to another line.


Approved by the senior director:

/*** Submit the task */@ testpublic void completetask () {taskservice = processengine. gettaskservice (); taskservice. Complete ("1707 ");}

Process Execution completed

Exclusive gateway:

Exclusive gateway description

Exclusive gateway (also calledExclusive or (XOR) Gateway, Or more technicallyData-based exclusive gateway) To be implemented in the process.Decision Making. When the process is executed to this gateway, all outgoing sequential streams are processed. The condition is resolved to a true sequence stream (or if no condition is set,'True') Will be selected for the process to continue running.

Note that the concept of outbound sequential flow is different from that of BPMN 2.0. Generally, all ordered streams with true conditions are selected and executed in parallel. However, exclusive gateway selects only one ordered stream for execution. That is to say, although the condition result of multiple sequential streams is true, the first Sequential stream (only this one) in XML will be selected and used to continue the process. If no Sequential stream is selected, an exception is thrown.

Exclusive gateway graphics

The exclusive gateway is displayed as a common gateway (for example, a diamond figure), which is represented by an "X" iconExclusive or (XOR)Semantics. Note: The exclusive gateway is used by default for gateways without internal icons. The BPMN 2.0 specification does not allow simultaneous use of diamond images without X and X in the same process definition.

Process file:



Exclusive gateway has a default flow option. When the default flow is set, no expression is required. If all the conditions fail, the default flow is executed.


Grade Director approval and principal approval



First, deploy the file

// Obtain the Process Engine processengine = processengines. getdefaprocesprocessengine (); @ testpublic void deployflow2 () {// get the repository service object repositoryservice = processengine. getrepositoryservice (); inputstream in = This. getclass (). getresourceasstream ("/exclusivegateway.zip"); zipinputstream = new zipinputstream (in); deployment dm = repositoryservice. createdeployment (). name ("Student leave "). addzipinputstream (zipinputstream ). deploy (); system. out. println ("ID:" + DM. GETID () + ", name:" + DM. getname ());}


Start the process and submit the result of setting the leave days to 10 days

ID: 2001, process instance id: 2001, process definition ID: exclusivegateway: 1: 1904 taskid: 2004, name: Student leave taskid: 2008, name: grade Director approval

Re-deploy a process file and start submission. Set the number of days for leave to 30 days.

ID: 2201, name: Student leave
ID: 2301, process instance id: 2301, process definition ID: exclusivegateway: 2: 2204 taskid: 2304, name: Student leave taskid: 2308, name: Principal approval
Finally, deploy the application. Set the number of days for leave to 3.

ID: 2501, name: Student leave
ID: 2601, process instance id: 2601, process definition ID: exclusivegateway: 3: 2504 taskid: 2604, name: Student leave taskid: 2608, name: class teacher approval

Here the process goes to the original default settings class teacher approval



When we set the default configuration, the default configuration will be executed even if the flow conditions of the expressions are not met.

Parallel Gateway

Parallel gateway description

The gateway can also represent parallel conditions in the process. The simplest parallel gateway isParallel GatewayIt allows the process to be divided into multiple branches, or multiple branches can be aggregated together. Of execution.

The function of the parallel gateway is based on the inbound and outbound sequential streams:

  • Branch:For all outbound sequential streams after parallelism, a concurrent branch is created for each Sequential stream.

  • Aggregation:All branches that arrive at the parallel gateway are waiting to enter the branch until all the branches that enter the ordered stream arrive, and the process passes through the aggregation gateway.

Note: If the same parallel gateway has multiple inbound and outbound sequential streams, it also hasBranch and aggregation functions. In this case, the gateway aggregates all inbound sequential streams and then splits them into multiple parallel branches.

The main difference with Other gateways is that parallel gateways do not parse the conditions. Even if conditions are defined in the ordered stream, they are ignored.

Parallel gateway graphics

The parallel gateway is displayed as a common gateway (diamond) with a "plus sign" icon, indicating the semantics of "and.

First, draw a simple parallel process



Note that there must be two parallel gateways:BranchOneAggregation

Start deployment

@ Testpublic void deployflow3 () {// obtain the repository service object repositoryservice = processengine. getrepositoryservice (); inputstream in = This. getclass (). getresourceasstream ("/parallel.zip"); zipinputstream = new zipinputstream (in); deployment dm = repositoryservice. createdeployment (). name ("parallel Gateway "). addzipinputstream (zipinputstream ). deploy (); system. out. println ("ID:" + DM. GETID () + ", name:" + DM. getname (); runtimeservice = processengine. getruntimeservice (); processinstance Pi = runtimeservice. startprocessinstancebykey ("Parallel"); system. out. println ("ID:" + pi. GETID () + ", process instance id:" + pi. getprocessinstanceid () + ", process definition ID:" + pi. getprocessdefinitionid ());}


ID: 2801, name: Parallel Gateway
ID: 2901, process instance id: 2901, process definition ID: parallel: 1: 2804
In this case, the process enters the START project stage and the process instance id is used to view the progress of the current process.

/*** Start the process and complete the submission */@ testpublic void startprocessandcomp3 () {taskservice = processengine. gettaskservice (); // query task = taskservice. createtaskquery (). processinstanceid ("2901 "). singleresult (); // if the task object is empty, the process execution ends if (task! = NULL) {system. out. println ("taskid:" + task. GETID () + ", name:" + task. getname ();} else {system. out. println ("task execution completed");} // obtain the task object task = taskservice through the process instance id. createtaskquery (). processinstanceid ("2901 "). singleresult (); system. out. println ("taskid:" + task. GETID () + ", name:" + task. getname (); // submit the task taskservice. complete (task. GETID ());}
Taskid: 2904, name: Project startup taskid: 2904, name: Project startup
After the task is submitted, the process goes to the parallel stage and executes function module 1 and function module 2 at the same time.


Here we can see that the process instance id and the execution Object ID are already different.

This is the data in the act_ru_execution table.


We first submit a task of Function Module 1.

In the act_ru_task table


In this case, the task table only has function module 2.

We are looking at the act_ru_execution table, which is still the execution process of 3 data functional modules 1. It is blocked in the parallel gateway and is not in the test release stage.


Submit task in function module 2

View the two tables



The process has entered the next step.

The entire process of submitting the last person is completed. We are viewing the history activity table act_hi_actinst.


The entire process is divided into two parts



Include Gateway

Includes gateway description

Include GatewayIt can be seen as a combination of exclusive gateway and parallel gateway. Like exclusive gateway, you can define conditions on the outbound sequential flow, including the conditions that the gateway will parse. However, the main difference is that the gateway can select more than one Sequential stream, which is the same as that of the parallel gateway.

The functions of the gateway are based on inbound and outbound sequential streams:

  • Branch:All outbound sequential flow conditions are parsed. If the result is true, the sequential flow continues in parallel and creates a branch for each sequential flow.

  • Aggregation:When all parallel branches arrive at the included gateway, they enter the waiting platform until each branch that contains the process token enters the sequential flow arrives. This is the biggest difference from the parallel gateway. In other words, the gateway will only wait for the selected execution to enter the sequential flow. After the aggregation, the process continues to run through the gateway.

Note: If the same containing node has multiple inbound and outbound sequential streams, it will simultaneouslyBranch and aggregation functions. In this case, the gateway first aggregates all outgoing sequential flows with process tokens, and then generates multiple parallel branches for them based on the outgoing sequential flows with true results.

Including gateway graphics

The parallel gateway is displayed as a common gateway (diamond) with a circle icon.


When the result returned by the expression condition in main config is true, the parallel gateway is executed.

Execute the exclusive task when the result is false.

The specific process is not described here


Event Gateway

Event gateway description

Event gateway allows you to determine the flow direction based on the event. Each outbound sequential flow of the gateway must be connected to an intermediate capture event. When a process arrives at an event-based gateway, the gateway enters the waiting state and stops running. At the same time, an event subscription is created for each outbound Sequential stream.

Note that the outgoing sequential streams Based on Event gateway are different from normal sequential flows. These sequential streams are not actually "executed ". Instead, they allow the process engine to decide which events need to be subscribed to when the process is executed based on the event gateway. Consider the following conditions:

  • The event-based gateway must have two or more outgoing sequential streams.

  • OnlyintermediateCatchEventType. (Activiti does not support connecting to deleetask after event gateway .)

  • Connect to the event gateway-basedintermediateCatchEventYou can enter only one Sequential stream.

Event gateway graphics

The event gateway and other BPMN gateways are displayed as a diamond with a specified icon.


If there are too many events here, we will first go to here 0.0.














Activiti entry 3 exclusive gateway, parallel network management, including gateway and event Gateway

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.