取消结束事件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了取消结束事件相关的知识,希望对你有一定的参考价值。
- 描述
取消结束事件只能与BPMN事务子流程结合使用。 实际应用中,会把取消事件,事务子流程,补偿事件一起用。当到达取消结束事件时,会抛出取消事件,它必须被取消边界事件捕获。 取消边界事件会取消事务,并触发补偿机制
- 图标
-
实例
流程启动会进入流程取消结束事件和sub Task,取消结束事件触发取消边界事件以及结束子流程,最后只能看到cancel Task。 -
注意
1、取消结束事件只能使用在事务子流程中
2、取消结束事件会触发依附在子流程上的取消边界事件(取消结束事件会被抛出,而取消边界事件则会捕获事件)
3、在BPMN2.0中对于已经完成的活动,可以使用补偿机制,而对于一些正在进行的活动,不能使用补偿机制,而使用取消机制 -
XML文件
1 <?xml version="1.0" encoding="UTF-8"?> 2 <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/test"> 3 <process id="myProcess" name="My process" isExecutable="true"> 4 <startEvent id="startevent1" name="Start"></startEvent> 5 <transaction id="transaction1" name="Transaction"> 6 <startEvent id="startevent2" name="Start"></startEvent> 7 8 <userTask id="usertask2" name="sub Task"></userTask> 9 <endEvent id="endevent1" name="End"></endEvent> 10 <sequenceFlow id="flow3" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow> 11 <endEvent id="cancelendevent1" name="CancelEnd"> 12 <cancelEventDefinition></cancelEventDefinition> 13 </endEvent> 14 15 <parallelGateway id="parallelgateway1" name="Parallel Gateway"></parallelGateway> 16 <sequenceFlow id="flow11" sourceRef="startevent2" targetRef="parallelgateway1"></sequenceFlow> 17 <sequenceFlow id="flow12" sourceRef="parallelgateway1" targetRef="cancelendevent1"></sequenceFlow> 18 <sequenceFlow id="flow13" sourceRef="parallelgateway1" targetRef="usertask2"></sequenceFlow> 19 </transaction> 20 <boundaryEvent id="boundarycancel1" name="Cancel" attachedToRef="transaction1" cancelActivity="true"> 21 22 <cancelEventDefinition></cancelEventDefinition> 23 </boundaryEvent> 24 <userTask id="usertask3" name="cancel Task"></userTask> 25 <sequenceFlow id="flow6" sourceRef="boundarycancel1" targetRef="usertask3"></sequenceFlow> 26 <endEvent id="endevent2" name="End"></endEvent> 27 <sequenceFlow id="flow7" sourceRef="usertask3" targetRef="endevent2"></sequenceFlow> 28 29 <sequenceFlow id="flow9" sourceRef="startevent1" targetRef="transaction1"></sequenceFlow> 30 <endEvent id="endevent3" name="End"></endEvent> 31 <sequenceFlow id="flow10" sourceRef="transaction1" targetRef="endevent3"></sequenceFlow> 32 </process> 33 <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess"> 34 <bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess"> 35 36 <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1"> 37 <omgdc:Bounds height="35.0" width="35.0" x="172.0" y="229.0"></omgdc:Bounds> 38 </bpmndi:BPMNShape> 39 <bpmndi:BPMNShape bpmnElement="transaction1" id="BPMNShape_transaction1"> 40 <omgdc:Bounds height="241.0" width="451.0" x="250.0" y="117.0"></omgdc:Bounds> 41 </bpmndi:BPMNShape> 42 43 <bpmndi:BPMNShape bpmnElement="startevent2" id="BPMNShape_startevent2"> 44 <omgdc:Bounds height="35.0" width="35.0" x="300.0" y="227.0"></omgdc:Bounds> 45 </bpmndi:BPMNShape> 46 <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2"> 47 <omgdc:Bounds height="55.0" width="105.0" x="460.0" y="212.0"></omgdc:Bounds> 48 </bpmndi:BPMNShape> 49 50 <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1"> 51 <omgdc:Bounds height="35.0" width="35.0" x="590.0" y="222.0"></omgdc:Bounds> 52 </bpmndi:BPMNShape> 53 <bpmndi:BPMNShape bpmnElement="cancelendevent1" id="BPMNShape_cancelendevent1"> 54 <omgdc:Bounds height="35.0" width="35.0" x="403.0" y="161.0"></omgdc:Bounds> 55 </bpmndi:BPMNShape> 56 57 <bpmndi:BPMNShape bpmnElement="parallelgateway1" id="BPMNShape_parallelgateway1"> 58 <omgdc:Bounds height="40.0" width="40.0" x="400.0" y="224.0"></omgdc:Bounds> 59 </bpmndi:BPMNShape> 60 <bpmndi:BPMNShape bpmnElement="boundarycancel1" id="BPMNShape_boundarycancel1"> 61 <omgdc:Bounds height="30.0" width="30.0" x="406.0" y="340.0"></omgdc:Bounds> 62 </bpmndi:BPMNShape> 63 64 <bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3"> 65 <omgdc:Bounds height="55.0" width="105.0" x="368.0" y="410.0"></omgdc:Bounds> 66 </bpmndi:BPMNShape> 67 <bpmndi:BPMNShape bpmnElement="endevent2" id="BPMNShape_endevent2"> 68 <omgdc:Bounds height="35.0" width="35.0" x="518.0" y="420.0"></omgdc:Bounds> 69 </bpmndi:BPMNShape> 70 71 <bpmndi:BPMNShape bpmnElement="endevent3" id="BPMNShape_endevent3"> 72 <omgdc:Bounds height="35.0" width="35.0" x="746.0" y="220.0"></omgdc:Bounds> 73 </bpmndi:BPMNShape> 74 <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3"> 75 <omgdi:waypoint x="565.0" y="239.0"></omgdi:waypoint> 76 <omgdi:waypoint x="590.0" y="239.0"></omgdi:waypoint> 77 78 </bpmndi:BPMNEdge> 79 <bpmndi:BPMNEdge bpmnElement="flow11" id="BPMNEdge_flow11"> 80 <omgdi:waypoint x="335.0" y="244.0"></omgdi:waypoint> 81 <omgdi:waypoint x="400.0" y="244.0"></omgdi:waypoint> 82 </bpmndi:BPMNEdge> 83 <bpmndi:BPMNEdge bpmnElement="flow12" id="BPMNEdge_flow12"> 84 85 <omgdi:waypoint x="420.0" y="224.0"></omgdi:waypoint> 86 <omgdi:waypoint x="420.0" y="196.0"></omgdi:waypoint> 87 </bpmndi:BPMNEdge> 88 <bpmndi:BPMNEdge bpmnElement="flow13" id="BPMNEdge_flow13"> 89 <omgdi:waypoint x="440.0" y="244.0"></omgdi:waypoint> 90 <omgdi:waypoint x="460.0" y="239.0"></omgdi:waypoint> 91 92 </bpmndi:BPMNEdge> 93 <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6"> 94 <omgdi:waypoint x="421.0" y="370.0"></omgdi:waypoint> 95 <omgdi:waypoint x="420.0" y="410.0"></omgdi:waypoint> 96 </bpmndi:BPMNEdge> 97 <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7"> 98 99 <omgdi:waypoint x="473.0" y="437.0"></omgdi:waypoint> 100 <omgdi:waypoint x="518.0" y="437.0"></omgdi:waypoint> 101 </bpmndi:BPMNEdge> 102 <bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9"> 103 <omgdi:waypoint x="207.0" y="246.0"></omgdi:waypoint> 104 <omgdi:waypoint x="250.0" y="237.0"></omgdi:waypoint> 105 106 </bpmndi:BPMNEdge> 107 <bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10"> 108 <omgdi:waypoint x="701.0" y="237.0"></omgdi:waypoint> 109 <omgdi:waypoint x="746.0" y="237.0"></omgdi:waypoint> 110 </bpmndi:BPMNEdge> 111 </bpmndi:BPMNPlane> 112 113 </bpmndi:BPMNDiagram> 114 </definitions>
-
java代码
1 package com.alfrescoblog.MyTest; 2 3 import org.activiti.engine.ProcessEngine; 4 import org.activiti.engine.ProcessEngines; 5 import org.activiti.engine.RepositoryService; 6 import org.activiti.engine.RuntimeService; 7 8 import org.activiti.engine.TaskService; 9 import org.activiti.engine.runtime.ProcessInstance; 10 11 public class CancelEndEventTest { 12 13 public static void main(String[] args) { 14 15 try { 16 ProcessEngine processEngine = ProcessEngines 17 .getDefaultProcessEngine(); 18 RepositoryService repositoryService = processEngine 19 .getRepositoryService(); 20 21 22 // 各种服务 23 RuntimeService runtimeService = processEngine.getRuntimeService(); 24 TaskService taskService = processEngine.getTaskService(); 25 26 // 部署流程文件 27 repositoryService.createDeployment() 28 29 .addClasspathResource("CancelEndEventTest.bpmn").deploy(); 30 // 启动流程 31 ProcessInstance pi = runtimeService 32 .startProcessInstanceByKey("myProcess"); 33 34 System.out.println(taskService.createTaskQuery().singleResult().getName()); 35 36 } catch (Exception e) { 37 e.printStackTrace(); 38 } 39 40 System.exit(0); 41 } 42 43 }
以上是关于取消结束事件的主要内容,如果未能解决你的问题,请参考以下文章