天天看點

Activiti 6.x【9】BoundaryEvent【上】BoundaryEvent元件

版權聲明:轉載注明出處就OK的說,有些東西會轉載,都會注明的說= =如果有冒犯麻煩見諒 https://blog.csdn.net/Pan1458689676/article/details/82717765

BoundaryEvent元件

BoundaryEvent分為六種,第一種為時間Boundary事件,第二種為錯誤Boundary事件,第三種消息Boundary事件,第四種為取消Boundary事件,第五種為補償Boundary事件,第六種為信号Boundary事件。邊界事件依附于事件存在。

流程圖總覽

【設定參數與時間開始元件的三個設定相同】

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);
}           

  • 如果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");
}