版權聲明:轉載注明出處就OK的說,有些東西會轉載,都會注明的說= =如果有冒犯麻煩見諒 https://blog.csdn.net/Pan1458689676/article/details/82720556
BoundaryEvent元件
BoundaryEvent分為六種,第一種為時間Boundary事件,第二種為錯誤Boundary事件,第三種消息Boundary事件,第四種為取消Boundary事件,第五種為補償Boundary事件,第六種為信号Boundary事件。邊界事件依附于事件存在。
流程圖總覽
注意部分
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);
}
如果有兩個活動信号邊界事件捕獲相同的信号事件,則兩個邊界事件都會被觸發,即使它們是不同流程執行個體的一部分。
流程圖總覽
流程配置
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 】
觸發取消邊界事件時,它首先中斷目前作用域中活動的所有執行。接下來,它開始補償範圍内的所有有效補償邊界事件。補償是同步進行的。
- 注意:事務子流程隻允許一個取消邊界事件。
- 注意:如果事務子程序承載嵌套子程序,則僅對已成功完成的子程序觸發補償。
- 注意:如果在具有多執行個體特征的事務子流程上放置取消邊界事件,則如果一個執行個體觸發取消,則邊界事件将取消所有執行個體。
補償邊界事件在附加的活動成功完成時激活。此時,建立對補償事件的相應訂閱。在觸發補償事件或相應的流程執行個體結束時,将删除訂閱。
- 觸發補償時,與補償邊界事件關聯的補償處理程式的調用次數與成功完成的活動的次數相同。
- 如果将補償邊界事件附加到具有多個執行個體特征的活動,則會為每個執行個體建立補償事件訂閱。
- 如果補償邊界事件附加到循環内包含的活動,則每次執行活動時都會建立補償事件訂閱。
- 如果流程執行個體結束,則取消對補償事件的訂閱。
- 嵌入的子程序不支援補償邊界事件。
- 補償邊界事件必須關聯一個補償處理程式。