BoundaryEvent组件
BoundaryEvent总述
BoundaryEvent分为六种,第一种为时间Boundary事件,第二种为错误Boundary事件,第三种消息Boundary事件,第四种为取消Boundary事件,第五种为补偿Boundary事件,第六种为信号Boundary事件。边界事件依附于事件存在。
TimerBoundaryEvent
流程图总览
【设置参数与时间开始组件的三个设置相同】
Cancel activity 代表是否取消当前流程转向边界事件
并行问题,只能采用网关形式,如下图图示
【官网典型应用】
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/test">
<process id="TimerBoundary" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="User Task"></userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<boundaryEvent id="boundarytimer1" name="Timer" attachedToRef="usertask1" cancelActivity="true">
<timerEventDefinition>
<timeDuration>R1/PT5S</timeDuration>
</timerEventDefinition>
</boundaryEvent>
<serviceTask id="servicetask1" name="Service Task" activiti:class="com.ptm.prdemo.servicetask.TimerBoundary"></serviceTask>
<sequenceFlow id="flow2" sourceRef="boundarytimer1" targetRef="servicetask1"></sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow3" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_TimerBoundary">
<bpmndi:BPMNPlane bpmnElement="TimerBoundary" id="BPMNPlane_TimerBoundary">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="211.0" y="190.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="290.0" y="180.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="boundarytimer1" id="BPMNShape_boundarytimer1">
<omgdc:Bounds height="30.0" width="30.0" x="328.0" y="224.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
<omgdc:Bounds height="55.0" width="105.0" x="420.0" y="270.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="510.0" y="190.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="246.0" y="207.0"></omgdi:waypoint>
<omgdi:waypoint x="290.0" y="207.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="343.0" y="254.0"></omgdi:waypoint>
<omgdi:waypoint x="472.0" y="270.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="395.0" y="207.0"></omgdi:waypoint>
<omgdi:waypoint x="510.0" y="207.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
ServiceTask
TimerBoundary
public class TimerBoundary implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) {
System.out.println("TimerBoundary");
}
}
测试代码
@Test
public void TimerBoundary() throws InterruptedException{
Deployment deployment = repositoryService.createDeployment()
.name("TimerBoundary")
.addClasspathResource("bpmn/TimerBoundary.bpmn")
.addClasspathResource("bpmn/TimerBoundary.png")
.deploy();
System.out.println("部署ID:"+deployment.getId());
System.out.println("部署名称:"+deployment.getName());
runtimeService.startProcessInstanceByKey("TimerBoundary");
Thread.sleep(1000 * 15);
}
ErrorBoundaryEvent【大多用于子流程】
- 如果errorRef被省略,边界错误事件将捕获任何错误事件,而不管的的errorCode的错误。
- 如果提供了errorRef并且它引用了现有错误,则边界事件将仅捕获具有相同错误代码的错误。
- 如果提供了errorRef,但BPMN 2.0文件中没有定义错误,则errorRef用作errorCode(类似于错误结束事件)。
流程图总览
usertask绑定
ErrorBoundary
public class ErrorBoundary implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) {
System.out.println("ErrorBoundary");
}
}
测试代码
@Test
public void ErrorBoundary() throws InterruptedException{
Deployment deployment = repositoryService.createDeployment()
.name("ErrorBoundary")
.addClasspathResource("bpmn/ErrorBoundary.bpmn")
.addClasspathResource("bpmn/ErrorBoundary.png")
.deploy();
System.out.println("部署ID:"+deployment.getId());
System.out.println("部署名称:"+deployment.getName());
runtimeService.startProcessInstanceByKey("ErrorBoundary");
}