版权声明:转载注明出处就OK的说,有些东西会转载,都会注明的说= =如果有冒犯麻烦见谅 https://blog.csdn.net/Pan1458689676/article/details/82720556
BoundaryEvent组件
BoundaryEvent总述
BoundaryEvent分为六种,第一种为时间Boundary事件,第二种为错误Boundary事件,第三种消息Boundary事件,第四种为取消Boundary事件,第五种为补偿Boundary事件,第六种为信号Boundary事件。边界事件依附于事件存在。
MessageBoundaryEvent
流程图总览
注意部分
ServiceTask
ServiceTask
public class ServiceTask implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) {
System.out.println("ServiceTask");
}
}
@Test
public void MessageBoundary() throws InterruptedException{
Deployment deployment = repositoryService.createDeployment()
.name("MessageBoundary")
.addClasspathResource("bpmn/MessageBoundary.bpmn")
.addClasspathResource("bpmn/MessageBoundary.png")
.deploy();
System.out.println("部署ID:"+deployment.getId());
System.out.println("部署名称:"+deployment.getName());
ProcessInstance pi = runtimeService.startProcessInstanceByKey("MessageBoundary");
Execution ex = runtimeService.createExecutionQuery().processDefinitionId(pi.getProcessDefinitionId()).activityId("boundarymessage1").singleResult();
runtimeService.messageEventReceived("msgName", ex.getId());
Thread.sleep(1000 *10);
}
SignalBoundaryEvent
如果有两个活动信号边界事件捕获相同的信号事件,则两个边界事件都会被触发,即使它们是不同流程实例的一部分。
流程图总览
流程配置
ServiceTask
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">
<signal id="Signal" name="SignalPTM"></signal>
<process id="SignalBoundary" 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="boundarysignal1" name="Signal" attachedToRef="usertask1" cancelActivity="true">
<signalEventDefinition signalRef="Signal"></signalEventDefinition>
</boundaryEvent>
<serviceTask id="servicetask1" name="Service Task" activiti:class="com.ptm.prdemo.servicetask.ServiceTask"></serviceTask>
<sequenceFlow id="flow3" sourceRef="boundarysignal1" targetRef="servicetask1"></sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow4" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_SignalBoundary">
<bpmndi:BPMNPlane bpmnElement="SignalBoundary" id="BPMNPlane_SignalBoundary">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="130.0" y="160.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="240.0" y="150.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="boundarysignal1" id="BPMNShape_boundarysignal1">
<omgdc:Bounds height="30.0" width="30.0" x="280.0" y="190.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
<omgdc:Bounds height="55.0" width="105.0" x="366.0" y="260.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="500.0" y="160.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="165.0" y="177.0"></omgdi:waypoint>
<omgdi:waypoint x="240.0" y="177.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="295.0" y="220.0"></omgdi:waypoint>
<omgdi:waypoint x="418.0" y="260.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="345.0" y="177.0"></omgdi:waypoint>
<omgdi:waypoint x="500.0" y="177.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
测试代码
@Test
public void SignalBoundary() throws InterruptedException{
Deployment deployment = repositoryService.createDeployment()
.name("SignalBoundary")
.addClasspathResource("bpmn/SignalBoundary.bpmn")
.addClasspathResource("bpmn/SignalBoundary.png")
.deploy();
System.out.println("部署ID:"+deployment.getId());
System.out.println("部署名称:"+deployment.getName());
ProcessInstance pi = runtimeService.startProcessInstanceByKey("SignalBoundary");
runtimeService.signalEventReceived("SignalPTM");
Thread.sleep(1000 *10);
}
事先部署三个流程之后执行signalEventReceived【三个流程全部执行了信号边界事件,信号事件是跨流程实例的,而且,与message不同message是一对一的发送要对应指定的ExecutionId对应单实例单执行对象。name不能在单个流程定义中有重复】
关于补偿与取消边界事件在我的这篇帖子里面有相关demo讲解【https://blog.csdn.net/Pan1458689676/article/details/82711607#cancelendevent】
CancelBoundaryEvent
触发取消边界事件时,它首先中断当前作用域中活动的所有执行。接下来,它开始补偿范围内的所有有效补偿边界事件。补偿是同步进行的。
- 注意:事务子流程只允许一个取消边界事件。
- 注意:如果事务子进程承载嵌套子进程,则仅对已成功完成的子进程触发补偿。
- 注意:如果在具有多实例特征的事务子流程上放置取消边界事件,则如果一个实例触发取消,则边界事件将取消所有实例。
CompensationBoundaryEvent
补偿边界事件在附加的活动成功完成时激活。此时,创建对补偿事件的相应订阅。在触发补偿事件或相应的流程实例结束时,将删除订阅。
- 触发补偿时,与补偿边界事件关联的补偿处理程序的调用次数与成功完成的活动的次数相同。
- 如果将补偿边界事件附加到具有多个实例特征的活动,则会为每个实例创建补偿事件订阅。
- 如果补偿边界事件附加到循环内包含的活动,则每次执行活动时都会创建补偿事件订阅。
- 如果流程实例结束,则取消对补偿事件的订阅。
- 嵌入的子进程不支持补偿边界事件。
- 补偿边界事件必须关联一个补偿处理程序。