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
補償邊界事件在附加的活動成功完成時激活。此時,創建對補償事件的相應訂閱。在觸發補償事件或相應的流程實例結束時,將刪除訂閱。
- 觸發補償時,與補償邊界事件關聯的補償處理程序的調用次數與成功完成的活動的次數相同。
- 如果將補償邊界事件附加到具有多個實例特徵的活動,則會爲每個實例創建補償事件訂閱。
- 如果補償邊界事件附加到循環內包含的活動,則每次執行活動時都會創建補償事件訂閱。
- 如果流程實例結束,則取消對補償事件的訂閱。
- 嵌入的子進程不支持補償邊界事件。
- 補償邊界事件必須關聯一個補償處理程序。