Activiti 6.x【9】BoundaryEvent【上】

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

這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章