Activiti结束事件(End Event)

 

       Activiti结束事件(End Event)

作者:Jesai -2017.08.03T01:03

曾经,黑夜多么漫长,八月雨扰眠,缘何?

声明:版权所有,如需引用请注明出处,如发现抄袭,必追究法律责任

1       前言:

Activiti工作流始于开始任务,止于结束任务。结束事件标志着(子)流程的(分支的)结束。结束事件总是抛出(型)事件。这意味着当流程执行到达结束事件时,会抛出一个结果。结果的类型由事件内部的黑色图标描绘。在XML表示中,类型由子元素声明给出。流程终结又可以分为4种情况:空结束任务、错误结束任务、取消结束任务、终结任务,其中空结束任务是最常见的结束任务。

2       结束任务的类型:

1)空结束任务(none end event)

2)错误结束事件(error end event)

3)取消结束任务(terminate end event)

4)终结任务(Cancel end event)

3       空结束任务(none end event)

空结束任务是最常见的一种结束任务,也是最简单的一种结束任务,只要把结束任务置于流程的最后节点,流程实例运行到该节点的时候,流程引擎就会结束该流程实例。并没有太多复杂的技术。所以不作太多的介绍。空事件的XML表示格式,为普通结束事件声明,没有任何子元素(其它种类的结束事件都有子元素,用于声明其类型)。

3.1   流程实例图标:

Activiti结束事件(End Event)_第1张图片

图3-1 空结束事件图标

3.2   代码:

1 <endEvent id="end" name="my end event" />

 

4       错误结束事件(error end event)

错误结束事件会在流程到达错误结束事件的时候抛出错误,并结束当前的流程分支。错误可以使用使用匹配的错误边界中间事件 intermediate boundary error event 捕获。如果找不到匹配的错误边界事件,将会抛出异常。

4.1   流程实例图标:

错误结束事件就是自流程或者流程实例的错误结束事件抛出一个bpmn错误。然后被工作流的错误边界事件获取。

Activiti结束事件(End Event)_第2张图片

图4-1 错误结束事件图标

错误结束事件,表示为结束事件,加上errorEventDefinition子元素:

1 <endEvent id="myErrorEndEvent">
2 <errorEventDefinition errorRef="myError" />
3 endEvent>

errorRef属性可以引用在流程外定义的error元素:

1 <error id="myError" errorCode="123" />
2 ...
3 <process id="myProcess">
4 ...

error的errorCode用于查找匹配的错误捕获边界事件。如果errorRef不匹配任何已定义的error,则该errorRef会用做errorCode的快捷方式。这个快捷方式是Activiti特有的。下面的代码片段在功能上是相同的。

1 <error id="myError" errorCode="error123" />
2 ...
3 <process id="myProcess">
4 ...
5 <endEvent id="myErrorEndEvent">
6 <errorEventDefinition errorRef="myError" />
7 endEvent>
8 ...

与下面的功能相同

1 <endEvent id="myErrorEndEvent">
2 <errorEventDefinition errorRef="error123" />
3 endEvent>

请注意errorRef必须遵从BPMN 2.0概要(schema),且必须是合法的QName。

 

4.2   流程图设计

流程图设计一个子流程,然后子流程里面有一个错误结束事件。外面的错误捕获边界任务就会捕获异常。捕获了异常后,由于是错误边界先去捕获异常,所以捕获错误事件分支会先执行,然后结束。正常结束事件节点所在的分支不会执行

 Activiti结束事件(End Event)_第3张图片

 

图4-2 错误结束事件流程设计

4.3   执行结果

图4-3 错误结束事件流程运行结果

4.4   流程代码

  1 xml version='1.0' encoding='UTF-8'?>
  2 
  3 <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">
  4 
  5   <process id="process" isExecutable="true">
  6 
  7     <subProcess id="sid-2669F680-71E9-4F43-9B2E-AF40435D9C74" name="subProcess">
  8 
  9       <startEvent id="sid-EB9804C4-9348-43F7-83DE-2E6640E52064" />
 10 
 11       <endEvent id="sid-507917BF-48BC-4A6E-A2C3-31DF0474F8FE">
 12 
 13         <errorEventDefinition errorRef="testError" />
 14 
 15       endEvent>
 16 
 17       <serviceTask id="sid-65F770DF-6797-4918-9BD6-21DDA3588804" name="子流程手工任务" activiti:class="light.mvc.workflow.serviceTask.SubErrorTestRunningTask" />
 18 
 19       <sequenceFlow id="sid-7A9F6A19-D24C-4719-8095-F76259D110AE" sourceRef="sid-EB9804C4-9348-43F7-83DE-2E6640E52064" targetRef="sid-65F770DF-6797-4918-9BD6-21DDA3588804" />
 20 
 21       <sequenceFlow id="sid-6203D605-402C-437D-A9A5-8E276AC8020B" sourceRef="sid-65F770DF-6797-4918-9BD6-21DDA3588804" targetRef="sid-507917BF-48BC-4A6E-A2C3-31DF0474F8FE" />
 22 
 23     subProcess>
 24 
 25     <startEvent id="sid-5E970179-3AD6-449F-962B-5CB88F49EE6B" />
 26 
 27     <sequenceFlow id="sid-BE4D16B9-9F0B-4793-B685-7E0F767F54EB" sourceRef="sid-5E970179-3AD6-449F-962B-5CB88F49EE6B" targetRef="sid-2669F680-71E9-4F43-9B2E-AF40435D9C74" />
 28 
 29     <endEvent id="sid-F37E4B4D-EBBA-40DD-A354-7549CCA62F7F" />
 30 
 31     <boundaryEvent id="sid-CE3D7798-F5CE-4C3D-8206-1EFF95BD0288" attachedToRef="sid-2669F680-71E9-4F43-9B2E-AF40435D9C74">
 32 
 33       <errorEventDefinition errorRef="testError" />
 34 
 35     boundaryEvent>
 36 
 37     <endEvent id="sid-EB951594-B88B-4C21-8C16-32A07B09D60A" />
 38 
 39     <serviceTask id="sid-2935E764-666C-4DB8-B1D0-8221936FE730" name="正常结束事件" activiti:class="light.mvc.workflow.serviceTask.NormalErrorTestRunningTask" />
 40 
 41     <sequenceFlow id="sid-C2B6D8DC-85C3-45F4-B47E-3839D025226A" sourceRef="sid-2669F680-71E9-4F43-9B2E-AF40435D9C74" targetRef="sid-2935E764-666C-4DB8-B1D0-8221936FE730" />
 42 
 43     <sequenceFlow id="sid-CE29790B-F67C-46AA-9E12-52B39952747F" sourceRef="sid-2935E764-666C-4DB8-B1D0-8221936FE730" targetRef="sid-F37E4B4D-EBBA-40DD-A354-7549CCA62F7F" />
 44 
 45     <serviceTask id="sid-7F82A593-A02E-484B-BC65-0AB3D23DE7D1" name="捕获错误事件" activiti:class="light.mvc.workflow.serviceTask.CacheErrorTestRunningTask" />
 46 
 47     <sequenceFlow id="sid-0CDB3258-E356-4A06-818B-A9C8EED3339A" sourceRef="sid-CE3D7798-F5CE-4C3D-8206-1EFF95BD0288" targetRef="sid-7F82A593-A02E-484B-BC65-0AB3D23DE7D1" />
 48 
 49     <sequenceFlow id="sid-688D53B8-63D2-43DF-AED6-D8234B4669D1" sourceRef="sid-7F82A593-A02E-484B-BC65-0AB3D23DE7D1" targetRef="sid-EB951594-B88B-4C21-8C16-32A07B09D60A" />
 50 
 51   process>
 52 
 53   <bpmndi:BPMNDiagram id="BPMNDiagram_process">
 54 
 55     <bpmndi:BPMNPlane bpmnElement="process" id="BPMNPlane_process">
 56 
 57       <bpmndi:BPMNShape bpmnElement="sid-2669F680-71E9-4F43-9B2E-AF40435D9C74" id="BPMNShape_sid-2669F680-71E9-4F43-9B2E-AF40435D9C74">
 58 
 59         <omgdc:Bounds height="179.0" width="521.0" x="315.0" y="75.5" />
 60 
 61       bpmndi:BPMNShape>
 62 
 63       <bpmndi:BPMNShape bpmnElement="sid-EB9804C4-9348-43F7-83DE-2E6640E52064" id="BPMNShape_sid-EB9804C4-9348-43F7-83DE-2E6640E52064">
 64 
 65         <omgdc:Bounds height="30.0" width="30.0" x="375.0" y="150.0" />
 66 
 67       bpmndi:BPMNShape>
 68 
 69       <bpmndi:BPMNShape bpmnElement="sid-507917BF-48BC-4A6E-A2C3-31DF0474F8FE" id="BPMNShape_sid-507917BF-48BC-4A6E-A2C3-31DF0474F8FE">
 70 
 71         <omgdc:Bounds height="28.0" width="28.0" x="720.0" y="151.0" />
 72 
 73       bpmndi:BPMNShape>
 74 
 75       <bpmndi:BPMNShape bpmnElement="sid-65F770DF-6797-4918-9BD6-21DDA3588804" id="BPMNShape_sid-65F770DF-6797-4918-9BD6-21DDA3588804">
 76 
 77         <omgdc:Bounds height="80.0" width="100.0" x="543.75" y="123.0" />
 78 
 79       bpmndi:BPMNShape>
 80 
 81       <bpmndi:BPMNShape bpmnElement="sid-5E970179-3AD6-449F-962B-5CB88F49EE6B" id="BPMNShape_sid-5E970179-3AD6-449F-962B-5CB88F49EE6B">
 82 
 83         <omgdc:Bounds height="30.0" width="30.0" x="154.75" y="150.0" />
 84 
 85       bpmndi:BPMNShape>
 86 
 87       <bpmndi:BPMNShape bpmnElement="sid-F37E4B4D-EBBA-40DD-A354-7549CCA62F7F" id="BPMNShape_sid-F37E4B4D-EBBA-40DD-A354-7549CCA62F7F">
 88 
 89         <omgdc:Bounds height="28.0" width="28.0" x="1024.75" y="144.0" />
 90 
 91       bpmndi:BPMNShape>
 92 
 93       <bpmndi:BPMNShape bpmnElement="sid-CE3D7798-F5CE-4C3D-8206-1EFF95BD0288" id="BPMNShape_sid-CE3D7798-F5CE-4C3D-8206-1EFF95BD0288">
 94 
 95         <omgdc:Bounds height="30.0" width="30.0" x="600.4320995601703" y="239.7819754816901" />
 96 
 97       bpmndi:BPMNShape>
 98 
 99       <bpmndi:BPMNShape bpmnElement="sid-EB951594-B88B-4C21-8C16-32A07B09D60A" id="BPMNShape_sid-EB951594-B88B-4C21-8C16-32A07B09D60A">
100 
101         <omgdc:Bounds height="28.0" width="28.0" x="851.75" y="327.0" />
102 
103       bpmndi:BPMNShape>
104 
105       <bpmndi:BPMNShape bpmnElement="sid-2935E764-666C-4DB8-B1D0-8221936FE730" id="BPMNShape_sid-2935E764-666C-4DB8-B1D0-8221936FE730">
106 
107         <omgdc:Bounds height="80.0" width="100.0" x="870.0" y="118.0" />
108 
109       bpmndi:BPMNShape>
110 
111       <bpmndi:BPMNShape bpmnElement="sid-7F82A593-A02E-484B-BC65-0AB3D23DE7D1" id="BPMNShape_sid-7F82A593-A02E-484B-BC65-0AB3D23DE7D1">
112 
113         <omgdc:Bounds height="80.0" width="100.0" x="707.75" y="306.25" />
114 
115       bpmndi:BPMNShape>
116 
117       <bpmndi:BPMNEdge bpmnElement="sid-CE29790B-F67C-46AA-9E12-52B39952747F" id="BPMNEdge_sid-CE29790B-F67C-46AA-9E12-52B39952747F">
118 
119         <omgdi:waypoint x="970.0" y="158.0" />
120 
121         <omgdi:waypoint x="1024.75" y="158.0" />
122 
123       bpmndi:BPMNEdge>
124 
125       <bpmndi:BPMNEdge bpmnElement="sid-688D53B8-63D2-43DF-AED6-D8234B4669D1" id="BPMNEdge_sid-688D53B8-63D2-43DF-AED6-D8234B4669D1">
126 
127         <omgdi:waypoint x="807.75" y="341.0" />
128 
129         <omgdi:waypoint x="851.75" y="341.0" />
130 
131       bpmndi:BPMNEdge>
132 
133       <bpmndi:BPMNEdge bpmnElement="sid-6203D605-402C-437D-A9A5-8E276AC8020B" id="BPMNEdge_sid-6203D605-402C-437D-A9A5-8E276AC8020B">
134 
135         <omgdi:waypoint x="643.75" y="165.0" />
136 
137         <omgdi:waypoint x="720.0" y="165.0" />
138 
139       bpmndi:BPMNEdge>
140 
141       <bpmndi:BPMNEdge bpmnElement="sid-7A9F6A19-D24C-4719-8095-F76259D110AE" id="BPMNEdge_sid-7A9F6A19-D24C-4719-8095-F76259D110AE">
142 
143         <omgdi:waypoint x="404.99927740552414" y="164.85276782914823" />
144 
145         <omgdi:waypoint x="543.75" y="163.4907975460123" />
146 
147       bpmndi:BPMNEdge>
148 
149       <bpmndi:BPMNEdge bpmnElement="sid-C2B6D8DC-85C3-45F4-B47E-3839D025226A" id="BPMNEdge_sid-C2B6D8DC-85C3-45F4-B47E-3839D025226A">
150 
151         <omgdi:waypoint x="836.0" y="159.7068214804064" />
152 
153         <omgdi:waypoint x="870.0" y="159.01596516690856" />
154 
155       bpmndi:BPMNEdge>
156 
157       <bpmndi:BPMNEdge bpmnElement="sid-BE4D16B9-9F0B-4793-B685-7E0F767F54EB" id="BPMNEdge_sid-BE4D16B9-9F0B-4793-B685-7E0F767F54EB">
158 
159         <omgdi:waypoint x="184.75" y="165.0" />
160 
161         <omgdi:waypoint x="315.0" y="165.0" />
162 
163       bpmndi:BPMNEdge>
164 
165       <bpmndi:BPMNEdge bpmnElement="sid-0CDB3258-E356-4A06-818B-A9C8EED3339A" id="BPMNEdge_sid-0CDB3258-E356-4A06-818B-A9C8EED3339A">
166 
167         <omgdi:waypoint x="615.4320995601703" y="269.7819754816901" />
168 
169         <omgdi:waypoint x="615.4320995601703" y="341.0" />
170 
171         <omgdi:waypoint x="707.75" y="341.0" />
172 
173       bpmndi:BPMNEdge>
174 
175     bpmndi:BPMNPlane>
176 
177   bpmndi:BPMNDiagram>
178 
179 definitions>

4.5   java监听类代码

4.5.1     子流程监听器:

 1 /**
 2 
 3  *
 4 
 5  */
 6 
 7 package light.mvc.workflow.serviceTask;
 8 
 9  
10 
11 import org.activiti.engine.delegate.DelegateExecution;
12 
13 import org.activiti.engine.delegate.JavaDelegate;
14 
15  
16 
17 /** 
18 
19  *  
20 
21  * 项目名称:lightmvc 
22 
23  * 类名称:ServiceTask 
24 
25  * 类描述: 
26 
27  * 创建人:邓家海 
28 
29  * 创建时间:2017年6月4日 下午6:18:11 
30 
31  * 修改人:deng 
32 
33  * 修改时间:2017年6月4日 下午6:18:11 
34 
35  * 修改备注: 
36 
37  * @version  
38 
39  *  
40 
41  */
42 
43  
44 
45 public class SubErrorTestRunningTask implements JavaDelegate{        
46 
47          //重写委托的提交方法
48 
49          @Override
50 
51          public void execute(DelegateExecution execution) throws Exception {
52 
53                    //receiveTaskprocess
54 
55                    System.out.println("SubErrorTestRunningTask is running!");
56 
57          }
58 
59 }

4.5.2     捕获事件监听器

 1 /**
 2 
 3  *
 4 
 5  */
 6 
 7 package light.mvc.workflow.serviceTask;
 8 
 9  
10 
11 import org.activiti.engine.delegate.DelegateExecution;
12 
13 import org.activiti.engine.delegate.JavaDelegate;
14 
15  
16 
17 /** 
18 
19  *  
20 
21  * 项目名称:lightmvc 
22 
23  * 类名称:ServiceTask 
24 
25  * 类描述: 
26 
27  * 创建人:邓家海 
28 
29  * 创建时间:2017年6月4日 下午6:18:11 
30 
31  * 修改人:deng 
32 
33  * 修改时间:2017年6月4日 下午6:18:11 
34 
35  * 修改备注: 
36 
37  * @version  
38 
39  *  
40 
41  */
42 
43  
44 
45 public class CacheErrorTestRunningTask implements JavaDelegate{
46 
47          //重写委托的提交方法
48 
49          @Override
50 
51          public void execute(DelegateExecution execution) throws Exception {
52 
53                    //receiveTaskprocess
54 
55                    System.out.println("CacheErrorTestRunningTask is running!");
56 
57          }
58 
59  
60 
61 }

4.5.3     正常结束事件监听器

 1 /**
 2 
 3  *
 4 
 5  */
 6 
 7 package light.mvc.workflow.serviceTask;
 8 
 9  
10 
11 import org.activiti.engine.delegate.DelegateExecution;
12 
13 import org.activiti.engine.delegate.JavaDelegate;
14 
15  
16 
17 /** 
18 
19  *  
20 
21  * 项目名称:lightmvc 
22 
23  * 类名称:ServiceTask 
24 
25  * 类描述: 
26 
27  * 创建人:邓家海 
28 
29  * 创建时间:2017年6月4日 下午6:18:11 
30 
31  * 修改人:deng 
32 
33  * 修改时间:2017年6月4日 下午6:18:11 
34 
35  * 修改备注: 
36 
37  * @version  
38 
39  *  
40 
41  */
42 
43 public class NormalErrorTestRunningTask implements JavaDelegate{
44 
45                   //重写委托的提交方法
46 
47          @Override
48 
49          public void execute(DelegateExecution execution) throws Exception {
50 
51                    //receiveTaskprocess
52 
53                    System.out.println("NormalErrorTestRunningTask is running!");
54 
55          }
56 
57 }
58 
59  

4.5.4     扩展1

下面我们改动一下流程,更清晰的看看这个工作的原理是怎么样的。

这一次我们是把错误事件的指向正常结束事件后面去了,可以看到,后面是正常执行的。

Activiti结束事件(End Event)_第4张图片

图4-3 错误结束事件流程设计

 

图4-4 错误结束事件运行结果

4.5.5     扩展2

再来改一下流程,可以看出,错误捕获边界是达到了终止主流程的效果的。主流程被中断了。不过错误捕获边界是否有终止事件,主流程都不会被继续往下执行。

 Activiti结束事件(End Event)_第5张图片

图4-5 错误结束事件流程图

 

图4-6 错误结束事件运行结果

 

5       取消结束任务(terminate end event)

当到达终止结束事件时,当前的流程实例或子流程会被终止。概念上说,当执行到达终止结束事件时,会判断第一个范围 scope(流程或子流程)并终止它。请注意在BPMN 2.0中,子流程可以是嵌入式子流程,调用活动,事件子流程,或事务子流程。有一条通用规则:当存在多实例的调用过程或嵌入式子流程时,只会终止一个实例,其他的实例与流程实例不会受影响。可以添加一个可选属性terminateAll。当其为true时,无论该终止结束事件在流程定义中的位置,也无论它是否在子流程(甚至是嵌套子流程)中,都会终止(根)流程实例。

 

5.1   流程实例图标:

 

图5-1 取消结束事件图标

终止结束事件,表示为结束事件,加上terminateEventDefinition子元素。
请注意terminateAll属性是可选的(默认为false)。

1 <endEvent id="myEndEvent >
2 true">terminateEventDefinition>
3 endEvent>

5.2   流程图设计

注意,这个流程的终止事件并没有设置成终止全部,可以看到,全部任务节点都被执行了。

 Activiti结束事件(End Event)_第6张图片

图5-2 取消结束事件流程图设计

5.3   运行结果

 

图5-3 取消结束事件流程执行结果

 

5.4   XML代码:

  1 xml version='1.0' encoding='UTF-8'?>
  2 
  3 <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">
  4 
  5   <process id="process" isExecutable="true">
  6 
  7     <subProcess id="sid-2669F680-71E9-4F43-9B2E-AF40435D9C74" name="subProcess">
  8 
  9       <startEvent id="sid-EB9804C4-9348-43F7-83DE-2E6640E52064" />
 10 
 11       <endEvent id="sid-507917BF-48BC-4A6E-A2C3-31DF0474F8FE">
 12 
 13         <extensionElements>
 14 
 15           <activiti:executionListener event="start" class="light.mvc.workflow.serviceTask.TestRunningTask" />
 16 
 17         extensionElements>
 18 
 19         <errorEventDefinition errorRef="testError" />
 20 
 21       endEvent>
 22 
 23       <serviceTask id="sid-65F770DF-6797-4918-9BD6-21DDA3588804" name="子流程手工任务" activiti:class="light.mvc.workflow.serviceTask.SubErrorTestRunningTask" />
 24 
 25       <sequenceFlow id="sid-7A9F6A19-D24C-4719-8095-F76259D110AE" sourceRef="sid-EB9804C4-9348-43F7-83DE-2E6640E52064" targetRef="sid-65F770DF-6797-4918-9BD6-21DDA3588804" />
 26 
 27       <sequenceFlow id="sid-6203D605-402C-437D-A9A5-8E276AC8020B" sourceRef="sid-65F770DF-6797-4918-9BD6-21DDA3588804" targetRef="sid-507917BF-48BC-4A6E-A2C3-31DF0474F8FE" />
 28 
 29     subProcess>
 30 
 31     <startEvent id="sid-5E970179-3AD6-449F-962B-5CB88F49EE6B" />
 32 
 33     <sequenceFlow id="sid-BE4D16B9-9F0B-4793-B685-7E0F767F54EB" sourceRef="sid-5E970179-3AD6-449F-962B-5CB88F49EE6B" targetRef="sid-2669F680-71E9-4F43-9B2E-AF40435D9C74" />
 34 
 35     <endEvent id="sid-F37E4B4D-EBBA-40DD-A354-7549CCA62F7F" />
 36 
 37     <boundaryEvent id="sid-CE3D7798-F5CE-4C3D-8206-1EFF95BD0288" attachedToRef="sid-2669F680-71E9-4F43-9B2E-AF40435D9C74">
 38 
 39       <errorEventDefinition errorRef="testError" />
 40 
 41     boundaryEvent>
 42 
 43     <endEvent id="sid-EB951594-B88B-4C21-8C16-32A07B09D60A" />
 44 
 45     <serviceTask id="sid-2935E764-666C-4DB8-B1D0-8221936FE730" name="正常结束事件" activiti:class="light.mvc.workflow.serviceTask.NormalErrorTestRunningTask" />
 46 
 47     <sequenceFlow id="sid-C2B6D8DC-85C3-45F4-B47E-3839D025226A" sourceRef="sid-2669F680-71E9-4F43-9B2E-AF40435D9C74" targetRef="sid-2935E764-666C-4DB8-B1D0-8221936FE730" />
 48 
 49     <sequenceFlow id="sid-CE29790B-F67C-46AA-9E12-52B39952747F" sourceRef="sid-2935E764-666C-4DB8-B1D0-8221936FE730" targetRef="sid-F37E4B4D-EBBA-40DD-A354-7549CCA62F7F" />
 50 
 51     <serviceTask id="sid-7F82A593-A02E-484B-BC65-0AB3D23DE7D1" name="捕获错误事件" activiti:class="light.mvc.workflow.serviceTask.CacheErrorTestRunningTask" />
 52 
 53     <sequenceFlow id="sid-0CDB3258-E356-4A06-818B-A9C8EED3339A" sourceRef="sid-CE3D7798-F5CE-4C3D-8206-1EFF95BD0288" targetRef="sid-7F82A593-A02E-484B-BC65-0AB3D23DE7D1" />
 54 
 55     <sequenceFlow id="sid-688D53B8-63D2-43DF-AED6-D8234B4669D1" sourceRef="sid-7F82A593-A02E-484B-BC65-0AB3D23DE7D1" targetRef="sid-EB951594-B88B-4C21-8C16-32A07B09D60A" />
 56 
 57   process>
 58 
 59   <bpmndi:BPMNDiagram id="BPMNDiagram_process">
 60 
 61     <bpmndi:BPMNPlane bpmnElement="process" id="BPMNPlane_process">
 62 
 63       <bpmndi:BPMNShape bpmnElement="sid-2669F680-71E9-4F43-9B2E-AF40435D9C74" id="BPMNShape_sid-2669F680-71E9-4F43-9B2E-AF40435D9C74">
 64 
 65         <omgdc:Bounds height="179.0" width="521.0" x="315.0" y="75.5" />
 66 
 67       bpmndi:BPMNShape>
 68 
 69       <bpmndi:BPMNShape bpmnElement="sid-EB9804C4-9348-43F7-83DE-2E6640E52064" id="BPMNShape_sid-EB9804C4-9348-43F7-83DE-2E6640E52064">
 70 
 71         <omgdc:Bounds height="30.0" width="30.0" x="375.0" y="150.0" />
 72 
 73       bpmndi:BPMNShape>
 74 
 75       <bpmndi:BPMNShape bpmnElement="sid-507917BF-48BC-4A6E-A2C3-31DF0474F8FE" id="BPMNShape_sid-507917BF-48BC-4A6E-A2C3-31DF0474F8FE">
 76 
 77         <omgdc:Bounds height="28.0" width="28.0" x="720.0" y="151.0" />
 78 
 79       bpmndi:BPMNShape>
 80 
 81       <bpmndi:BPMNShape bpmnElement="sid-65F770DF-6797-4918-9BD6-21DDA3588804" id="BPMNShape_sid-65F770DF-6797-4918-9BD6-21DDA3588804">
 82 
 83         <omgdc:Bounds height="80.0" width="100.0" x="543.75" y="123.0" />
 84 
 85       bpmndi:BPMNShape>
 86 
 87       <bpmndi:BPMNShape bpmnElement="sid-5E970179-3AD6-449F-962B-5CB88F49EE6B" id="BPMNShape_sid-5E970179-3AD6-449F-962B-5CB88F49EE6B">
 88 
 89         <omgdc:Bounds height="30.0" width="30.0" x="154.75" y="150.0" />
 90 
 91       bpmndi:BPMNShape>
 92 
 93       <bpmndi:BPMNShape bpmnElement="sid-F37E4B4D-EBBA-40DD-A354-7549CCA62F7F" id="BPMNShape_sid-F37E4B4D-EBBA-40DD-A354-7549CCA62F7F">
 94 
 95         <omgdc:Bounds height="28.0" width="28.0" x="1024.75" y="144.0" />
 96 
 97       bpmndi:BPMNShape>
 98 
 99       <bpmndi:BPMNShape bpmnElement="sid-CE3D7798-F5CE-4C3D-8206-1EFF95BD0288" id="BPMNShape_sid-CE3D7798-F5CE-4C3D-8206-1EFF95BD0288">
100 
101         <omgdc:Bounds height="30.0" width="30.0" x="600.4320995601703" y="239.7819754816901" />
102 
103       bpmndi:BPMNShape>
104 
105       <bpmndi:BPMNShape bpmnElement="sid-EB951594-B88B-4C21-8C16-32A07B09D60A" id="BPMNShape_sid-EB951594-B88B-4C21-8C16-32A07B09D60A">
106 
107         <omgdc:Bounds height="28.0" width="28.0" x="851.75" y="327.0" />
108 
109       bpmndi:BPMNShape>
110 
111       <bpmndi:BPMNShape bpmnElement="sid-2935E764-666C-4DB8-B1D0-8221936FE730" id="BPMNShape_sid-2935E764-666C-4DB8-B1D0-8221936FE730">
112 
113         <omgdc:Bounds height="80.0" width="100.0" x="870.0" y="118.0" />
114 
115       bpmndi:BPMNShape>
116 
117       <bpmndi:BPMNShape bpmnElement="sid-7F82A593-A02E-484B-BC65-0AB3D23DE7D1" id="BPMNShape_sid-7F82A593-A02E-484B-BC65-0AB3D23DE7D1">
118 
119         <omgdc:Bounds height="80.0" width="100.0" x="707.75" y="306.25" />
120 
121       bpmndi:BPMNShape>
122 
123       <bpmndi:BPMNEdge bpmnElement="sid-CE29790B-F67C-46AA-9E12-52B39952747F" id="BPMNEdge_sid-CE29790B-F67C-46AA-9E12-52B39952747F">
124 
125         <omgdi:waypoint x="970.0" y="158.0" />
126 
127         <omgdi:waypoint x="1024.75" y="158.0" />
128 
129       bpmndi:BPMNEdge>
130 
131       <bpmndi:BPMNEdge bpmnElement="sid-688D53B8-63D2-43DF-AED6-D8234B4669D1" id="BPMNEdge_sid-688D53B8-63D2-43DF-AED6-D8234B4669D1">
132 
133         <omgdi:waypoint x="807.75" y="341.0" />
134 
135         <omgdi:waypoint x="851.75" y="341.0" />
136 
137       bpmndi:BPMNEdge>
138 
139       <bpmndi:BPMNEdge bpmnElement="sid-6203D605-402C-437D-A9A5-8E276AC8020B" id="BPMNEdge_sid-6203D605-402C-437D-A9A5-8E276AC8020B">
140 
141         <omgdi:waypoint x="643.75" y="165.0" />
142 
143         <omgdi:waypoint x="720.0" y="165.0" />
144 
145       bpmndi:BPMNEdge>
146 
147       <bpmndi:BPMNEdge bpmnElement="sid-7A9F6A19-D24C-4719-8095-F76259D110AE" id="BPMNEdge_sid-7A9F6A19-D24C-4719-8095-F76259D110AE">
148 
149         <omgdi:waypoint x="404.99927740552414" y="164.85276782914823" />
150 
151         <omgdi:waypoint x="543.75" y="163.4907975460123" />
152 
153       bpmndi:BPMNEdge>
154 
155       <bpmndi:BPMNEdge bpmnElement="sid-C2B6D8DC-85C3-45F4-B47E-3839D025226A" id="BPMNEdge_sid-C2B6D8DC-85C3-45F4-B47E-3839D025226A">
156 
157         <omgdi:waypoint x="836.0" y="159.7068214804064" />
158 
159         <omgdi:waypoint x="870.0" y="159.01596516690856" />
160 
161       bpmndi:BPMNEdge>
162 
163       <bpmndi:BPMNEdge bpmnElement="sid-BE4D16B9-9F0B-4793-B685-7E0F767F54EB" id="BPMNEdge_sid-BE4D16B9-9F0B-4793-B685-7E0F767F54EB">
164 
165         <omgdi:waypoint x="184.75" y="165.0" />
166 
167         <omgdi:waypoint x="315.0" y="165.0" />
168 
169       bpmndi:BPMNEdge>
170 
171       <bpmndi:BPMNEdge bpmnElement="sid-0CDB3258-E356-4A06-818B-A9C8EED3339A" id="BPMNEdge_sid-0CDB3258-E356-4A06-818B-A9C8EED3339A">
172 
173         <omgdi:waypoint x="615.4320995601703" y="269.7819754816901" />
174 
175         <omgdi:waypoint x="615.4320995601703" y="341.0" />
176 
177         <omgdi:waypoint x="707.75" y="341.0" />
178 
179       bpmndi:BPMNEdge>
180 
181     bpmndi:BPMNPlane>
182 
183   bpmndi:BPMNDiagram>
184 
185 definitions>

5.5   扩展

这一次,我们把该流程的终止任务设置成终止全部,可以看到,子流程执行完了之后,主流程被终止了。由此可见,终止的只是主流程,子流程并没有终止。

Activiti结束事件(End Event)_第7张图片

图5-4 取消结束事件图标

5.6   运行结果

 

图5-5 取消结束事件执行结果

5.7   XML代码:

 

xml version='1.0' encoding='UTF-8'?>

<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">

  <process id="process" isExecutable="true">

    <subProcess id="sid-2669F680-71E9-4F43-9B2E-AF40435D9C74" name="subProcess">

      <startEvent id="sid-EB9804C4-9348-43F7-83DE-2E6640E52064" />

      <endEvent id="sid-507917BF-48BC-4A6E-A2C3-31DF0474F8FE">

        <errorEventDefinition errorRef="testError" />

      endEvent>

      <serviceTask id="sid-65F770DF-6797-4918-9BD6-21DDA3588804" name="子流程手工任务" activiti:class="light.mvc.workflow.serviceTask.SubErrorTestRunningTask" />

      <sequenceFlow id="sid-7A9F6A19-D24C-4719-8095-F76259D110AE" sourceRef="sid-EB9804C4-9348-43F7-83DE-2E6640E52064" targetRef="sid-65F770DF-6797-4918-9BD6-21DDA3588804" />

      <sequenceFlow id="sid-6203D605-402C-437D-A9A5-8E276AC8020B" sourceRef="sid-65F770DF-6797-4918-9BD6-21DDA3588804" targetRef="sid-507917BF-48BC-4A6E-A2C3-31DF0474F8FE" />

    subProcess>

    <startEvent id="sid-5E970179-3AD6-449F-962B-5CB88F49EE6B" />

    <sequenceFlow id="sid-BE4D16B9-9F0B-4793-B685-7E0F767F54EB" sourceRef="sid-5E970179-3AD6-449F-962B-5CB88F49EE6B" targetRef="sid-2669F680-71E9-4F43-9B2E-AF40435D9C74" />

    <endEvent id="sid-F37E4B4D-EBBA-40DD-A354-7549CCA62F7F" />

    <boundaryEvent id="sid-CE3D7798-F5CE-4C3D-8206-1EFF95BD0288" attachedToRef="sid-2669F680-71E9-4F43-9B2E-AF40435D9C74">

      <errorEventDefinition errorRef="testError" />

    boundaryEvent>

    <endEvent id="sid-EB951594-B88B-4C21-8C16-32A07B09D60A" />

    <serviceTask id="sid-2935E764-666C-4DB8-B1D0-8221936FE730" name="正常结束事件" activiti:class="light.mvc.workflow.serviceTask.NormalErrorTestRunningTask" />

    <sequenceFlow id="sid-C2B6D8DC-85C3-45F4-B47E-3839D025226A" sourceRef="sid-2669F680-71E9-4F43-9B2E-AF40435D9C74" targetRef="sid-2935E764-666C-4DB8-B1D0-8221936FE730" />

    <sequenceFlow id="sid-CE29790B-F67C-46AA-9E12-52B39952747F" sourceRef="sid-2935E764-666C-4DB8-B1D0-8221936FE730" targetRef="sid-F37E4B4D-EBBA-40DD-A354-7549CCA62F7F" />

    <serviceTask id="sid-7F82A593-A02E-484B-BC65-0AB3D23DE7D1" name="捕获错误事件" activiti:class="light.mvc.workflow.serviceTask.CacheErrorTestRunningTask" />

    <sequenceFlow id="sid-0CDB3258-E356-4A06-818B-A9C8EED3339A" sourceRef="sid-CE3D7798-F5CE-4C3D-8206-1EFF95BD0288" targetRef="sid-7F82A593-A02E-484B-BC65-0AB3D23DE7D1" />

    <sequenceFlow id="sid-688D53B8-63D2-43DF-AED6-D8234B4669D1" sourceRef="sid-7F82A593-A02E-484B-BC65-0AB3D23DE7D1" targetRef="sid-EB951594-B88B-4C21-8C16-32A07B09D60A" />

  process>

  <bpmndi:BPMNDiagram id="BPMNDiagram_process">

    <bpmndi:BPMNPlane bpmnElement="process" id="BPMNPlane_process">

      <bpmndi:BPMNShape bpmnElement="sid-2669F680-71E9-4F43-9B2E-AF40435D9C74" id="BPMNShape_sid-2669F680-71E9-4F43-9B2E-AF40435D9C74">

        <omgdc:Bounds height="179.0" width="521.0" x="315.0" y="75.5" />

      bpmndi:BPMNShape>

      <bpmndi:BPMNShape bpmnElement="sid-EB9804C4-9348-43F7-83DE-2E6640E52064" id="BPMNShape_sid-EB9804C4-9348-43F7-83DE-2E6640E52064">

        <omgdc:Bounds height="30.0" width="30.0" x="375.0" y="150.0" />

      bpmndi:BPMNShape>

      <bpmndi:BPMNShape bpmnElement="sid-507917BF-48BC-4A6E-A2C3-31DF0474F8FE" id="BPMNShape_sid-507917BF-48BC-4A6E-A2C3-31DF0474F8FE">

        <omgdc:Bounds height="28.0" width="28.0" x="720.0" y="151.0" />

      bpmndi:BPMNShape>

      <bpmndi:BPMNShape bpmnElement="sid-65F770DF-6797-4918-9BD6-21DDA3588804" id="BPMNShape_sid-65F770DF-6797-4918-9BD6-21DDA3588804">

        <omgdc:Bounds height="80.0" width="100.0" x="543.75" y="123.0" />

      bpmndi:BPMNShape>

      <bpmndi:BPMNShape bpmnElement="sid-5E970179-3AD6-449F-962B-5CB88F49EE6B" id="BPMNShape_sid-5E970179-3AD6-449F-962B-5CB88F49EE6B">

        <omgdc:Bounds height="30.0" width="30.0" x="154.75" y="150.0" />

      bpmndi:BPMNShape>

      <bpmndi:BPMNShape bpmnElement="sid-F37E4B4D-EBBA-40DD-A354-7549CCA62F7F" id="BPMNShape_sid-F37E4B4D-EBBA-40DD-A354-7549CCA62F7F">

        <omgdc:Bounds height="28.0" width="28.0" x="1024.75" y="144.0" />

      bpmndi:BPMNShape>

      <bpmndi:BPMNShape bpmnElement="sid-CE3D7798-F5CE-4C3D-8206-1EFF95BD0288" id="BPMNShape_sid-CE3D7798-F5CE-4C3D-8206-1EFF95BD0288">

        <omgdc:Bounds height="30.0" width="30.0" x="600.4320995601703" y="239.7819754816901" />

      bpmndi:BPMNShape>

      <bpmndi:BPMNShape bpmnElement="sid-EB951594-B88B-4C21-8C16-32A07B09D60A" id="BPMNShape_sid-EB951594-B88B-4C21-8C16-32A07B09D60A">

        <omgdc:Bounds height="28.0" width="28.0" x="851.75" y="327.0" />

      bpmndi:BPMNShape>

      <bpmndi:BPMNShape bpmnElement="sid-2935E764-666C-4DB8-B1D0-8221936FE730" id="BPMNShape_sid-2935E764-666C-4DB8-B1D0-8221936FE730">

        <omgdc:Bounds height="80.0" width="100.0" x="870.0" y="118.0" />

      bpmndi:BPMNShape>

      <bpmndi:BPMNShape bpmnElement="sid-7F82A593-A02E-484B-BC65-0AB3D23DE7D1" id="BPMNShape_sid-7F82A593-A02E-484B-BC65-0AB3D23DE7D1">

        <omgdc:Bounds height="80.0" width="100.0" x="707.75" y="306.25" />

      bpmndi:BPMNShape>

      <bpmndi:BPMNEdge bpmnElement="sid-CE29790B-F67C-46AA-9E12-52B39952747F" id="BPMNEdge_sid-CE29790B-F67C-46AA-9E12-52B39952747F">

        <omgdi:waypoint x="970.0" y="158.0" />

        <omgdi:waypoint x="1024.75" y="158.0" />

      bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge bpmnElement="sid-688D53B8-63D2-43DF-AED6-D8234B4669D1" id="BPMNEdge_sid-688D53B8-63D2-43DF-AED6-D8234B4669D1">

        <omgdi:waypoint x="807.75" y="341.0" />

        <omgdi:waypoint x="851.75" y="341.0" />

      bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge bpmnElement="sid-6203D605-402C-437D-A9A5-8E276AC8020B" id="BPMNEdge_sid-6203D605-402C-437D-A9A5-8E276AC8020B">

        <omgdi:waypoint x="643.75" y="165.0" />

        <omgdi:waypoint x="720.0" y="165.0" />

      bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge bpmnElement="sid-7A9F6A19-D24C-4719-8095-F76259D110AE" id="BPMNEdge_sid-7A9F6A19-D24C-4719-8095-F76259D110AE">

        <omgdi:waypoint x="404.99927740552414" y="164.85276782914823" />

        <omgdi:waypoint x="543.75" y="163.4907975460123" />

      bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge bpmnElement="sid-C2B6D8DC-85C3-45F4-B47E-3839D025226A" id="BPMNEdge_sid-C2B6D8DC-85C3-45F4-B47E-3839D025226A">

        <omgdi:waypoint x="836.0" y="159.7068214804064" />

        <omgdi:waypoint x="870.0" y="159.01596516690856" />

      bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge bpmnElement="sid-BE4D16B9-9F0B-4793-B685-7E0F767F54EB" id="BPMNEdge_sid-BE4D16B9-9F0B-4793-B685-7E0F767F54EB">

        <omgdi:waypoint x="184.75" y="165.0" />

        <omgdi:waypoint x="315.0" y="165.0" />

      bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge bpmnElement="sid-0CDB3258-E356-4A06-818B-A9C8EED3339A" id="BPMNEdge_sid-0CDB3258-E356-4A06-818B-A9C8EED3339A">

        <omgdi:waypoint x="615.4320995601703" y="269.7819754816901" />

        <omgdi:waypoint x="615.4320995601703" y="341.0" />

        <omgdi:waypoint x="707.75" y="341.0" />

      bpmndi:BPMNEdge>

    bpmndi:BPMNPlane>

  bpmndi:BPMNDiagram>

definitions>

5.8   java监听器代码:

 1 /**
 2 
 3  *
 4 
 5  */
 6 
 7 package light.mvc.workflow.serviceTask;
 8 
 9 import org.activiti.engine.delegate.DelegateExecution;
10 
11 import org.activiti.engine.delegate.JavaDelegate;
12 
13 /** 
14 
15  *  
16 
17  * 项目名称:lightmvc 
18 
19  * 类名称:ServiceTask 
20 
21  * 类描述: 
22 
23  * 创建人:邓家海 
24 
25  * 创建时间:2017年6月4日 下午6:18:11 
26 
27  * 修改人:deng 
28 
29  * 修改时间:2017年6月4日 下午6:18:11 
30 
31  * 修改备注: 
32 
33  * @version  
34 
35  *  
36 
37  */
38 
39 public class FirstTestRunningTask implements JavaDelegate{       
40 
41          //重写委托的提交方法
42 
43          @Override
44 
45          public void execute(DelegateExecution execution) throws Exception {
46 
47                    //receiveTaskprocess
48 
49                    System.out.println("FirstTestRunningTask is running!");
50 
51          }
52 
53 }
 1 /**
 2 
 3  *
 4 
 5  */
 6 
 7 package light.mvc.workflow.serviceTask;
 8 
 9  
10 
11 import org.activiti.engine.delegate.DelegateExecution;
12 
13 import org.activiti.engine.delegate.JavaDelegate;
14 
15 /** 
16 
17  *  
18 
19  * 项目名称:lightmvc 
20 
21  * 类名称:ServiceTask 
22 
23  * 类描述: 
24 
25  * 创建人:邓家海 
26 
27  * 创建时间:2017年6月4日 下午6:18:11 
28 
29  * 修改人:deng 
30 
31  * 修改时间:2017年6月4日 下午6:18:11 
32 
33  * 修改备注: 
34 
35  * @version  
36 
37  *  
38 
39  */
40 
41 public class SecondTestRunningTask implements JavaDelegate{  
42 
43          //重写委托的提交方法
44 
45          @Override
46 
47          public void execute(DelegateExecution execution) throws Exception {
48 
49                    //receiveTaskprocess
50 
51                    System.out.println("SecondTestRunningTask is running!");
52 
53          }
54 
55 }
 1 /**
 2 
 3  *
 4 
 5  */
 6 
 7 package light.mvc.workflow.serviceTask;
 8 
 9 import org.activiti.engine.delegate.DelegateExecution;
10 
11 import org.activiti.engine.delegate.JavaDelegate;
12 
13 /** 
14 
15  *  
16 
17  * 项目名称:lightmvc 
18 
19  * 类名称:ServiceTask 
20 
21  * 类描述: 
22 
23  * 创建人:邓家海 
24 
25  * 创建时间:2017年6月4日 下午6:18:11 
26 
27  * 修改人:deng 
28 
29  * 修改时间:2017年6月4日 下午6:18:11 
30 
31  * 修改备注: 
32 
33  * @version  
34 
35  *  
36 
37  */
38 
39 public class ThreeTestRunningTask implements JavaDelegate{    
40 
41          //重写委托的提交方法
42 
43          @Override
44 
45          public void execute(DelegateExecution execution) throws Exception {
46 
47                    //receiveTaskprocess
48 
49                    System.out.println("ThreeTestRunningTask is running!");
50 
51          }
52 
53 }
 1 /**
 2 
 3  *
 4 
 5  */
 6 
 7 package light.mvc.workflow.serviceTask;
 8 
 9 import org.activiti.engine.delegate.BpmnError;
10 
11 import org.activiti.engine.delegate.DelegateExecution;
12 
13 import org.activiti.engine.delegate.JavaDelegate;
14 
15 /** 
16 
17  *  
18 
19  * 项目名称:lightmvc 
20 
21  * 类名称:ServiceTask 
22 
23  * 类描述: 
24 
25  * 创建人:邓家海 
26 
27  * 创建时间:2017年6月4日 下午6:18:11 
28 
29  * 修改人:deng 
30 
31  * 修改时间:2017年7月16日 下午7:28:11 
32 
33  * 修改备注: 
34 
35  * @version  
36 
37  *  
38 
39  */
40 
41 public class TestRunningTask implements JavaDelegate{
42 
43                   //重写委托的提交方法
44 
45          @Override
46 
47          public void execute(DelegateExecution execution) throws Exception{
48 
49                             System.out.println("TestRunningTask is running!");
50 
51          }
52 
53 }

 

6       终结任务(Cancel end event)

取消结束事件,只能与bpmn事务子流程(bpmn transaction subprocess)一起使用。当到达取消结束事件时,会抛出取消事件,且必须由取消边界事件(cancel boundary event)捕获。之后这个取消边界事件将取消事务,并触发补偿(compensation)。

6.1   流程实例图标:

图6-1 终结事件图标

6.2   流程图设计

注意,子流程必须是事务子流程,否则会抛异常。在这里可以看到,主流程是被终止的

 Activiti结束事件(End Event)_第8张图片

图6-3 终结事件流程设计

6.3   执行结果

Activiti结束事件(End Event)_第9张图片

图6-4 终结事件执行结果

6.4   XML代码:

  1 xml version='1.0' encoding='UTF-8'?>
  2 
  3 <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">
  4 
  5   <process id="process" isExecutable="true">
  6 
  7     <serviceTask id="sid-379EE829-82D3-4FDD-8B7B-BC23EAA22EEA" name="Four" activiti:class="light.mvc.workflow.serviceTask.FourTestRunningTask" />
  8 
  9     <endEvent id="sid-DD868C6E-0BCC-4074-8ECD-EC0FD43EE1D4" name="CacheEnd">
 10 
 11       <extensionElements>
 12 
 13         <activiti:executionListener event="start" class="light.mvc.workflow.serviceTask.CacheEndTestRunningTask" />
 14 
 15       extensionElements>
 16 
 17     endEvent>
 18 
 19     <sequenceFlow id="sid-2D990EC2-4C0D-4802-AD4A-060C3D6C9AD5" sourceRef="sid-379EE829-82D3-4FDD-8B7B-BC23EAA22EEA" targetRef="sid-DD868C6E-0BCC-4074-8ECD-EC0FD43EE1D4" />
 20 
 21     <sequenceFlow id="sid-DF71B4EC-8565-4576-9C4E-08E5B022A1E6" sourceRef="sid-403E776E-E879-46AE-8C38-F95612795F54" targetRef="sid-379EE829-82D3-4FDD-8B7B-BC23EAA22EEA" />
 22 
 23     <endEvent id="sid-6E841FD5-91A5-418B-89FD-7B97B3005A9D" name="NormalEnd">
 24 
 25       <extensionElements>
 26 
 27         <activiti:executionListener event="start" class="light.mvc.workflow.serviceTask.NormalEndTestRunningTask" />
 28 
 29       extensionElements>
 30 
 31     endEvent>
 32 
 33     <sequenceFlow id="sid-FA2AAEE1-C3EB-4291-9333-83CAE7773B0E" sourceRef="sid-ECFBFB19-9774-4B38-BEA2-02B4C02F3C8F" targetRef="sid-6E841FD5-91A5-418B-89FD-7B97B3005A9D" />
 34 
 35     <serviceTask id="sid-ECFBFB19-9774-4B38-BEA2-02B4C02F3C8F" name="Three" activiti:class="light.mvc.workflow.serviceTask.ThreeTestRunningTask" />
 36 
 37     <startEvent id="sid-1F74E6EF-FBDB-426F-8623-B24E2A247F22" />
 38 
 39     <sequenceFlow id="sid-1504E61E-C564-4017-B118-78D3437EC26E" sourceRef="sid-1F74E6EF-FBDB-426F-8623-B24E2A247F22" targetRef="sid-A0E1519E-9B55-4297-9A12-828E0350E8BE" />
 40 
 41     <transaction id="sid-A0E1519E-9B55-4297-9A12-828E0350E8BE" name="subProcess">
 42 
 43       <endEvent id="sid-8F0912E8-6F42-4E21-BBAC-CD5619FBED13" name="CancelEvent">
 44 
 45         <extensionElements>
 46 
 47           <activiti:executionListener event="start" class="light.mvc.workflow.serviceTask.CancelEndEventTestRunningTask" />
 48 
 49         extensionElements>
 50 
 51         <cancelEventDefinition />
 52 
 53       endEvent>
 54 
 55       <endEvent id="sid-75C106FA-BE45-44C7-BA67-7C078737D2FB" name="SubNormalEnd">
 56 
 57         <extensionElements>
 58 
 59           <activiti:executionListener event="start" class="light.mvc.workflow.serviceTask.SubNormalEndTestRunningTask" />
 60 
 61         extensionElements>
 62 
 63       endEvent>
 64 
 65       <serviceTask id="sid-674CCA99-084E-48B8-96EC-F2C46BEF2F39" name="Second" activiti:class="light.mvc.workflow.serviceTask.SecondTestRunningTask" />
 66 
 67       <serviceTask id="sid-18151C51-783E-4050-82E9-D1EDF442F662" name="First
" activiti:class="light.mvc.workflow.serviceTask.FirstTestRunningTask" />
 68 
 69       <startEvent id="sid-0AC715C3-CCD6-4212-B05B-696E50F31D7E" />
 70 
 71       <sequenceFlow id="sid-BF460B0C-C157-49CA-9E69-19075219BB59" sourceRef="sid-0AC715C3-CCD6-4212-B05B-696E50F31D7E" targetRef="sid-18151C51-783E-4050-82E9-D1EDF442F662" />
 72 
 73       <sequenceFlow id="sid-76368B45-07DD-45A5-95B9-600325F34C61" sourceRef="sid-18151C51-783E-4050-82E9-D1EDF442F662" targetRef="sid-674CCA99-084E-48B8-96EC-F2C46BEF2F39" />
 74 
 75       <sequenceFlow id="sid-FE2E4DD7-0358-4EA4-B1CD-FF41923EA1CB" sourceRef="sid-674CCA99-084E-48B8-96EC-F2C46BEF2F39" targetRef="sid-75C106FA-BE45-44C7-BA67-7C078737D2FB" />
 76 
 77       <sequenceFlow id="sid-73E5A61C-2515-4F2D-9A61-91446AAF12FC" sourceRef="sid-18151C51-783E-4050-82E9-D1EDF442F662" targetRef="sid-8F0912E8-6F42-4E21-BBAC-CD5619FBED13" />
 78 
 79     transaction>
 80 
 81     <sequenceFlow id="sid-B2D27F5B-E292-4AE8-96B3-AB5A2872B039" sourceRef="sid-A0E1519E-9B55-4297-9A12-828E0350E8BE" targetRef="sid-ECFBFB19-9774-4B38-BEA2-02B4C02F3C8F" />
 82 
 83     <boundaryEvent id="sid-403E776E-E879-46AE-8C38-F95612795F54" name="CancelEvent" attachedToRef="sid-A0E1519E-9B55-4297-9A12-828E0350E8BE" cancelActivity="false">
 84 
 85       <cancelEventDefinition />
 86 
 87     boundaryEvent>
 88 
 89   process>
 90 
 91   <bpmndi:BPMNDiagram id="BPMNDiagram_process">
 92 
 93     <bpmndi:BPMNPlane bpmnElement="process" id="BPMNPlane_process">
 94 
 95       <bpmndi:BPMNShape bpmnElement="sid-379EE829-82D3-4FDD-8B7B-BC23EAA22EEA" id="BPMNShape_sid-379EE829-82D3-4FDD-8B7B-BC23EAA22EEA">
 96 
 97         <omgdc:Bounds height="80.0" width="100.0" x="617.7854450025696" y="285.0" />
 98 
 99       bpmndi:BPMNShape>
100 
101       <bpmndi:BPMNShape bpmnElement="sid-DD868C6E-0BCC-4074-8ECD-EC0FD43EE1D4" id="BPMNShape_sid-DD868C6E-0BCC-4074-8ECD-EC0FD43EE1D4">
102 
103         <omgdc:Bounds height="28.0" width="28.0" x="840.0" y="311.0" />
104 
105       bpmndi:BPMNShape>
106 
107       <bpmndi:BPMNShape bpmnElement="sid-6E841FD5-91A5-418B-89FD-7B97B3005A9D" id="BPMNShape_sid-6E841FD5-91A5-418B-89FD-7B97B3005A9D">
108 
109         <omgdc:Bounds height="28.0" width="28.0" x="961.75" y="102.0" />
110 
111       bpmndi:BPMNShape>
112 
113       <bpmndi:BPMNShape bpmnElement="sid-ECFBFB19-9774-4B38-BEA2-02B4C02F3C8F" id="BPMNShape_sid-ECFBFB19-9774-4B38-BEA2-02B4C02F3C8F">
114 
115         <omgdc:Bounds height="80.0" width="100.0" x="816.75" y="76.0" />
116 
117       bpmndi:BPMNShape>
118 
119       <bpmndi:BPMNShape bpmnElement="sid-1F74E6EF-FBDB-426F-8623-B24E2A247F22" id="BPMNShape_sid-1F74E6EF-FBDB-426F-8623-B24E2A247F22">
120 
121         <omgdc:Bounds height="30.0" width="30.0" x="161.75" y="101.0" />
122 
123       bpmndi:BPMNShape>
124 
125       <bpmndi:BPMNShape bpmnElement="sid-A0E1519E-9B55-4297-9A12-828E0350E8BE" id="BPMNShape_sid-A0E1519E-9B55-4297-9A12-828E0350E8BE">
126 
127         <omgdc:Bounds height="190.0" width="477.0" x="266.75" y="21.0" />
128 
129       bpmndi:BPMNShape>
130 
131       <bpmndi:BPMNShape bpmnElement="sid-8F0912E8-6F42-4E21-BBAC-CD5619FBED13" id="BPMNShape_sid-8F0912E8-6F42-4E21-BBAC-CD5619FBED13">
132 
133         <omgdc:Bounds height="28.0" width="28.0" x="411.0" y="165.0" />
134 
135       bpmndi:BPMNShape>
136 
137       <bpmndi:BPMNShape bpmnElement="sid-75C106FA-BE45-44C7-BA67-7C078737D2FB" id="BPMNShape_sid-75C106FA-BE45-44C7-BA67-7C078737D2FB">
138 
139         <omgdc:Bounds height="28.0" width="28.0" x="685.0" y="86.0" />
140 
141       bpmndi:BPMNShape>
142 
143       <bpmndi:BPMNShape bpmnElement="sid-674CCA99-084E-48B8-96EC-F2C46BEF2F39" id="BPMNShape_sid-674CCA99-084E-48B8-96EC-F2C46BEF2F39">
144 
145         <omgdc:Bounds height="80.0" width="100.0" x="540.0" y="60.0" />
146 
147       bpmndi:BPMNShape>
148 
149       <bpmndi:BPMNShape bpmnElement="sid-18151C51-783E-4050-82E9-D1EDF442F662" id="BPMNShape_sid-18151C51-783E-4050-82E9-D1EDF442F662">
150 
151         <omgdc:Bounds height="80.0" width="100.0" x="375.0" y="60.0" />
152 
153       bpmndi:BPMNShape>
154 
155       <bpmndi:BPMNShape bpmnElement="sid-0AC715C3-CCD6-4212-B05B-696E50F31D7E" id="BPMNShape_sid-0AC715C3-CCD6-4212-B05B-696E50F31D7E">
156 
157         <omgdc:Bounds height="30.0" width="30.0" x="300.0" y="83.0" />
158 
159       bpmndi:BPMNShape>
160 
161       <bpmndi:BPMNShape bpmnElement="sid-403E776E-E879-46AE-8C38-F95612795F54" id="BPMNShape_sid-403E776E-E879-46AE-8C38-F95612795F54">
162 
163         <omgdc:Bounds height="30.0" width="30.0" x="652.7854450025696" y="196.32788210358325" />
164 
165       bpmndi:BPMNShape>
166 
167       <bpmndi:BPMNEdge bpmnElement="sid-BF460B0C-C157-49CA-9E69-19075219BB59" id="BPMNEdge_sid-BF460B0C-C157-49CA-9E69-19075219BB59">
168 
169         <omgdi:waypoint x="329.99752127569985" y="98.27268220501271" />
170 
171         <omgdi:waypoint x="375.0" y="99.0909090909091" />
172 
173       bpmndi:BPMNEdge>
174 
175       <bpmndi:BPMNEdge bpmnElement="sid-1504E61E-C564-4017-B118-78D3437EC26E" id="BPMNEdge_sid-1504E61E-C564-4017-B118-78D3437EC26E">
176 
177         <omgdi:waypoint x="191.75" y="116.0" />
178 
179         <omgdi:waypoint x="266.75" y="116.0" />
180 
181       bpmndi:BPMNEdge>
182 
183       <bpmndi:BPMNEdge bpmnElement="sid-2D990EC2-4C0D-4802-AD4A-060C3D6C9AD5" id="BPMNEdge_sid-2D990EC2-4C0D-4802-AD4A-060C3D6C9AD5">
184 
185         <omgdi:waypoint x="717.7854450025696" y="325.0" />
186 
187         <omgdi:waypoint x="840.0" y="325.0" />
188 
189       bpmndi:BPMNEdge>
190 
191       <bpmndi:BPMNEdge bpmnElement="sid-B2D27F5B-E292-4AE8-96B3-AB5A2872B039" id="BPMNEdge_sid-B2D27F5B-E292-4AE8-96B3-AB5A2872B039">
192 
193         <omgdi:waypoint x="743.75" y="116.0" />
194 
195         <omgdi:waypoint x="816.75" y="116.0" />
196 
197       bpmndi:BPMNEdge>
198 
199       <bpmndi:BPMNEdge bpmnElement="sid-FE2E4DD7-0358-4EA4-B1CD-FF41923EA1CB" id="BPMNEdge_sid-FE2E4DD7-0358-4EA4-B1CD-FF41923EA1CB">
200 
201         <omgdi:waypoint x="640.0" y="100.0" />
202 
203         <omgdi:waypoint x="685.0" y="100.0" />
204 
205       bpmndi:BPMNEdge>
206 
207       <bpmndi:BPMNEdge bpmnElement="sid-DF71B4EC-8565-4576-9C4E-08E5B022A1E6" id="BPMNEdge_sid-DF71B4EC-8565-4576-9C4E-08E5B022A1E6">
208 
209         <omgdi:waypoint x="667.7854450025696" y="226.32788210358325" />
210 
211         <omgdi:waypoint x="667.7854450025696" y="285.0" />
212 
213       bpmndi:BPMNEdge>
214 
215       <bpmndi:BPMNEdge bpmnElement="sid-FA2AAEE1-C3EB-4291-9333-83CAE7773B0E" id="BPMNEdge_sid-FA2AAEE1-C3EB-4291-9333-83CAE7773B0E">
216 
217         <omgdi:waypoint x="916.75" y="116.0" />
218 
219         <omgdi:waypoint x="961.75" y="116.0" />
220 
221       bpmndi:BPMNEdge>
222 
223       <bpmndi:BPMNEdge bpmnElement="sid-73E5A61C-2515-4F2D-9A61-91446AAF12FC" id="BPMNEdge_sid-73E5A61C-2515-4F2D-9A61-91446AAF12FC">
224 
225         <omgdi:waypoint x="423.8888888888889" y="140.0" />
226 
227         <omgdi:waypoint x="422.81932127326405" y="178.50443416249374" />
228 
229       bpmndi:BPMNEdge>
230 
231       <bpmndi:BPMNEdge bpmnElement="sid-76368B45-07DD-45A5-95B9-600325F34C61" id="BPMNEdge_sid-76368B45-07DD-45A5-95B9-600325F34C61">
232 
233         <omgdi:waypoint x="475.0" y="100.0" />
234 
235         <omgdi:waypoint x="540.0" y="100.0" />
236 
237       bpmndi:BPMNEdge>
238 
239     bpmndi:BPMNPlane>
240 
241   bpmndi:BPMNDiagram>
242 
243 definitions>

6.5   Java监听类代码:

 1 /**
 2 
 3  *
 4 
 5  */
 6 
 7 package light.mvc.workflow.serviceTask;
 8 
 9  
10 
11 import org.activiti.engine.delegate.DelegateExecution;
12 
13 import org.activiti.engine.delegate.JavaDelegate;
14 
15  
16 
17 /** 
18 
19  *  
20 
21  * 项目名称:lightmvc 
22 
23  * 类名称:ServiceTask 
24 
25  * 类描述: 
26 
27  * 创建人:邓家海 
28 
29  * 创建时间:2017年6月4日 下午6:18:11 
30 
31  * 修改人:deng 
32 
33  * 修改时间:2017年6月4日 下午6:18:11 
34 
35  * 修改备注: 
36 
37  * @version  
38 
39  *  
40 
41  */
42 
43 public class FirstTestRunningTask implements JavaDelegate{       
44 
45          //重写委托的提交方法
46 
47          @Override
48 
49          public void execute(DelegateExecution execution) throws Exception {
50 
51                    //receiveTaskprocess
52 
53                    System.out.println("FirstTestRunningTask is running!");
54 
55          }
56 
57 }

 

 1 /**
 2 
 3  *
 4 
 5  */
 6 
 7 package light.mvc.workflow.serviceTask;
 8 
 9  
10 
11 import org.activiti.engine.delegate.DelegateExecution;
12 
13 import org.activiti.engine.delegate.JavaDelegate;
14 
15  
16 
17 /** 
18 
19  *  
20 
21  * 项目名称:lightmvc 
22 
23  * 类名称:ServiceTask 
24 
25  * 类描述: 
26 
27  * 创建人:邓家海 
28 
29  * 创建时间:2017年6月4日 下午6:18:11 
30 
31  * 修改人:deng 
32 
33  * 修改时间:2017年6月4日 下午6:18:11 
34 
35  * 修改备注: 
36 
37  * @version  
38 
39  *  
40 
41  */
42 
43 public class SecondTestRunningTask implements JavaDelegate{  
44 
45          //重写委托的提交方法
46 
47          @Override
48 
49          public void execute(DelegateExecution execution) throws Exception {
50 
51                    //receiveTaskprocess
52 
53                    System.out.println("SecondTestRunningTask is running!");
54 
55          }
56 
57 }
 1 /**
 2 
 3  *
 4 
 5  */
 6 
 7 package light.mvc.workflow.serviceTask;
 8 
 9  
10 
11 import org.activiti.engine.delegate.DelegateExecution;
12 
13 import org.activiti.engine.delegate.JavaDelegate;
14 
15  
16 
17 /** 
18 
19  *  
20 
21  * 项目名称:lightmvc 
22 
23  * 类名称:ServiceTask 
24 
25  * 类描述: 
26 
27  * 创建人:邓家海 
28 
29  * 创建时间:2017年6月4日 下午6:18:11 
30 
31  * 修改人:deng 
32 
33  * 修改时间:2017年6月4日 下午6:18:11 
34 
35  * 修改备注: 
36 
37  * @version  
38 
39  *  
40 
41  */
42 
43 public class ThreeTestRunningTask implements JavaDelegate{    
44 
45          //重写委托的提交方法
46 
47          @Override
48 
49          public void execute(DelegateExecution execution) throws Exception {
50 
51                    //receiveTaskprocess
52 
53                    System.out.println("ThreeTestRunningTask is running!");
54 
55          }
56 
57 }
 1 /**
 2 
 3  *
 4 
 5  */
 6 
 7 package light.mvc.workflow.serviceTask;
 8 
 9  
10 
11 import org.activiti.engine.delegate.DelegateExecution;
12 
13 import org.activiti.engine.delegate.JavaDelegate;
14 
15  
16 
17 /** 
18 
19  *  
20 
21  * 项目名称:lightmvc 
22 
23  * 类名称:ServiceTask 
24 
25  * 类描述: 
26 
27  * 创建人:邓家海 
28 
29  * 创建时间:2017年6月4日 下午6:18:11 
30 
31  * 修改人:deng 
32 
33  * 修改时间:2017年6月4日 下午6:18:11 
34 
35  * 修改备注: 
36 
37  * @version  
38 
39  *  
40 
41  */
42 
43  
44 
45 public class FourTestRunningTask implements JavaDelegate{       
46 
47          //重写委托的提交方法
48 
49          @Override
50 
51          public void execute(DelegateExecution execution) throws Exception {
52 
53                    //receiveTaskprocess
54 
55                    System.out.println("FourTestRunningTask is running!");
56 
57          }
58 
59 }
 1 /**
 2 
 3  *
 4 
 5  */
 6 
 7 package light.mvc.workflow.serviceTask;
 8 
 9  
10 
11 import org.activiti.engine.delegate.DelegateExecution;
12 
13 import org.activiti.engine.delegate.JavaDelegate;
14 
15 /** 
16 
17  *  
18 
19  * 项目名称:lightmvc 
20 
21  * 类名称:ServiceTask 
22 
23  * 类描述: 
24 
25  * 创建人:邓家海 
26 
27  * 创建时间:2017年6月4日 下午6:18:11 
28 
29  * 修改人:deng 
30 
31  * 修改时间:2017年6月4日 下午6:18:11 
32 
33  * 修改备注: 
34 
35  * @version  
36 
37  *  
38 
39  */
40 
41 public class NormalEndTestRunningTask implements JavaDelegate{   
42 
43          //重写委托的提交方法
44 
45          @Override
46 
47          public void execute(DelegateExecution execution) throws Exception {
48 
49                    //receiveTaskprocess
50 
51                    System.out.println("NormalEndTestRunningTask is running!");
52 
53          }
54 
55  
56 
57 }
 1 /**
 2 
 3  *
 4 
 5  */
 6 
 7 package light.mvc.workflow.serviceTask;
 8 
 9  
10 
11 import org.activiti.engine.delegate.DelegateExecution;
12 
13 import org.activiti.engine.delegate.JavaDelegate;
14 
15  
16 
17 /** 
18 
19  *  
20 
21  * 项目名称:lightmvc 
22 
23  * 类名称:ServiceTask 
24 
25  * 类描述: 
26 
27  * 创建人:邓家海 
28 
29  * 创建时间:2017年6月4日 下午6:18:11 
30 
31  * 修改人:deng 
32 
33  * 修改时间:2017年6月4日 下午6:18:11 
34 
35  * 修改备注: 
36 
37  * @version  
38 
39  *  
40 
41  */
42 
43 public class CacheEndTestRunningTask implements JavaDelegate{      
44 
45          //重写委托的提交方法
46 
47          @Override
48 
49          public void execute(DelegateExecution execution) throws Exception {
50 
51                    //receiveTaskprocess
52 
53                    System.out.println("CacheEndTestRunningTask is running!");
54 
55          }
56 
57 }
 1 /**
 2 
 3  *
 4 
 5  */
 6 
 7 package light.mvc.workflow.serviceTask;
 8 
 9  
10 
11 import org.activiti.engine.delegate.DelegateExecution;
12 
13 import org.activiti.engine.delegate.JavaDelegate;
14 
15 /** 
16 
17  *  
18 
19  * 项目名称:lightmvc 
20 
21  * 类名称:ServiceTask 
22 
23  * 类描述: 
24 
25  * 创建人:邓家海 
26 
27  * 创建时间:2017年6月4日 下午6:18:11 
28 
29  * 修改人:deng 
30 
31  * 修改时间:2017年6月4日 下午6:18:11 
32 
33  * 修改备注: 
34 
35  * @version  
36 
37  *  
38 
39  */
40 
41 public class CancelEndEventTestRunningTask implements JavaDelegate{   
42 
43          //重写委托的提交方法
44 
45          @Override
46 
47          public void execute(DelegateExecution execution) throws Exception {
48 
49                    //receiveTaskprocess
50 
51                    System.out.println("CancelEndEventTestRunningTask is running!");
52 
53          }
54 
55  
56 
57 }
 1 /**
 2 
 3  *
 4 
 5  */
 6 
 7 package light.mvc.workflow.serviceTask;
 8 
 9  
10 
11 import org.activiti.engine.delegate.DelegateExecution;
12 
13 import org.activiti.engine.delegate.JavaDelegate;
14 
15  
16 
17 /** 
18 
19  *  
20 
21  * 项目名称:lightmvc 
22 
23  * 类名称:ServiceTask 
24 
25  * 类描述: 
26 
27  * 创建人:邓家海 
28 
29  * 创建时间:2017年6月4日 下午6:18:11 
30 
31  * 修改人:deng 
32 
33  * 修改时间:2017年6月4日 下午6:18:11 
34 
35  * 修改备注: 
36 
37  * @version  
38 
39  *  
40 
41  */
42 
43 public class SubNormalEndTestRunningTask implements JavaDelegate{      
44 
45          //重写委托的提交方法
46 
47          @Override
48 
49          public void execute(DelegateExecution execution) throws Exception {
50 
51                    //receiveTaskprocess
52 
53                    System.out.println("SubNormalEndTestRunningTask is running!");
54 
55          }
56 
57 }

6.6   延伸

下面我们改动一下流程:发现它还是一样的,终止了主流程。Activiti结束事件(End Event)_第10张图片

 

图6-4 终结事件流程图设计

 

 

图6-4 终结事件执行结果

 

 

 

 Activiti交流QQ群:634320089

 

 

 

 

 

你可能感兴趣的:(Activiti结束事件(End Event))