一。开始事件(Start Events) 开始事件用来指明流程从哪里开始。开始事件启动一个流程的新实例,它只有一个唯一的无条件输出顺序流,没有输入连线。 开始事件类型包含: 普通开始事件 定时开始事件 信号开始事件 消息开始事件 [图片] 开始事件被触发后,流程引擎产生流程实例,顺着开始事件沿线继续下一步。 1. 普通 ..

Activiti 6.x 开始事件

本贴最后更新于 199 天前,其中的信息可能已经东海扬尘

一。开始事件(Start Events)

开始事件用来指明流程从哪里开始。开始事件启动一个流程的新实例,它只有一个唯一的无条件输出顺序流,没有输入连线。
开始事件类型包含:

  1. 普通开始事件
  2. 定时开始事件
  3. 信号开始事件
  4. 消息开始事件
    开始事件图
    开始事件被触发后,流程引擎产生流程实例,顺着开始事件沿线继续下一步。

1. 普通开始事件

常规的开始事件,不指定事件的起因,由 API 触发。
流程图
image.png
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/processdef">
  <process id="normal_3432443" name="正常开始事件" isExecutable="true">
    <startEvent id="startEvent1"></startEvent>
    <userTask id="sid-E0E01A2B-A9C6-4475-9ADD-494514DC29F8" name="普通开始事件">
      <extensionElements>
        <activiti:taskListener event="create" class="com.lei2j.activiti.taskListener.UserTaskCreateListener"></activiti:taskListener>
      </extensionElements>
    </userTask>
    <sequenceFlow id="sid-5B4E73E4-6EFB-455B-A4E2-8DC93E28A761" sourceRef="startEvent1" targetRef="sid-E0E01A2B-A9C6-4475-9ADD-494514DC29F8"></sequenceFlow>
    <endEvent id="sid-7411852C-7759-4023-A280-892D8022B9BA"></endEvent>
    <sequenceFlow id="sid-256588F2-C41F-402E-BEEF-E120B3BE704D" sourceRef="sid-E0E01A2B-A9C6-4475-9ADD-494514DC29F8" targetRef="sid-7411852C-7759-4023-A280-892D8022B9BA"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_timer-process">
    <bpmndi:BPMNPlane bpmnElement="timer_3432443" id="BPMNPlane_timer-process">
      <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
        <omgdc:Bounds height="30.0" width="30.0" x="100.0" y="163.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-E0E01A2B-A9C6-4475-9ADD-494514DC29F8" id="BPMNShape_sid-E0E01A2B-A9C6-4475-9ADD-494514DC29F8">
        <omgdc:Bounds height="80.0" width="100.0" x="175.0" y="138.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-7411852C-7759-4023-A280-892D8022B9BA" id="BPMNShape_sid-7411852C-7759-4023-A280-892D8022B9BA">
        <omgdc:Bounds height="28.0" width="28.0" x="320.0" y="164.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-256588F2-C41F-402E-BEEF-E120B3BE704D" id="BPMNEdge_sid-256588F2-C41F-402E-BEEF-E120B3BE704D">
        <omgdi:waypoint x="275.0" y="178.0"></omgdi:waypoint>
        <omgdi:waypoint x="320.0" y="178.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-5B4E73E4-6EFB-455B-A4E2-8DC93E28A761" id="BPMNEdge_sid-5B4E73E4-6EFB-455B-A4E2-8DC93E28A761">
        <omgdi:waypoint x="130.0" y="178.0"></omgdi:waypoint>
        <omgdi:waypoint x="175.0" y="178.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

2. 定时开始事件

时间定时事件可以在指定时间启动一个流程实例,也可以周期内多次启动。当流程被定义后,程序会在由定时开始事件中定义的定时器自动启动一个新的流程实例。
流程图
image.png
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/processdef">
  <process id="timer_process_2" name="定时器开始事件" isExecutable="true">
    <userTask id="sid-2E1A5FB2-FC78-4DC4-ABC6-069A749C2769" name="定时器任务">
      <extensionElements>
        <activiti:taskListener event="create" expression="${resumeService.exp(task,task.eventName)}"></activiti:taskListener>
      </extensionElements>
    </userTask>
    <endEvent id="sid-EA785049-B058-421E-853F-4E4A0112278E"></endEvent>
    <startEvent id="sid-A209E4B6-396B-48E8-B672-685AF46794F4" activiti:isInterrupting="false">
      <timerEventDefinition>
        <timeCycle>0/30 * * * * ?</timeCycle>
      </timerEventDefinition>
    </startEvent>
    <sequenceFlow id="sid-69DEA51D-1551-4D0E-B0FE-90A047C7A0E9" sourceRef="sid-A209E4B6-396B-48E8-B672-685AF46794F4" targetRef="sid-2E1A5FB2-FC78-4DC4-ABC6-069A749C2769"></sequenceFlow>
    <sequenceFlow id="sid-17AA4E3D-7F43-48A4-B5DE-0A2A20A3BC27" sourceRef="sid-2E1A5FB2-FC78-4DC4-ABC6-069A749C2769" targetRef="sid-EA785049-B058-421E-853F-4E4A0112278E"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_timer_process_2">
    <bpmndi:BPMNPlane bpmnElement="timer_process_2" id="BPMNPlane_timer_process_2">
      <bpmndi:BPMNShape bpmnElement="sid-2E1A5FB2-FC78-4DC4-ABC6-069A749C2769" id="BPMNShape_sid-2E1A5FB2-FC78-4DC4-ABC6-069A749C2769">
        <omgdc:Bounds height="80.0" width="100.0" x="165.0" y="135.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-EA785049-B058-421E-853F-4E4A0112278E" id="BPMNShape_sid-EA785049-B058-421E-853F-4E4A0112278E">
        <omgdc:Bounds height="28.0" width="28.0" x="320.0" y="161.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-A209E4B6-396B-48E8-B672-685AF46794F4" id="BPMNShape_sid-A209E4B6-396B-48E8-B672-685AF46794F4">
        <omgdc:Bounds height="31.0" width="31.0" x="45.0" y="159.5"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-17AA4E3D-7F43-48A4-B5DE-0A2A20A3BC27" id="BPMNEdge_sid-17AA4E3D-7F43-48A4-B5DE-0A2A20A3BC27">
        <omgdi:waypoint x="265.0" y="175.0"></omgdi:waypoint>
        <omgdi:waypoint x="320.0" y="175.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-69DEA51D-1551-4D0E-B0FE-90A047C7A0E9" id="BPMNEdge_sid-69DEA51D-1551-4D0E-B0FE-90A047C7A0E9">
        <omgdi:waypoint x="76.99991566941355" y="175.44805222185255"></omgdi:waypoint>
        <omgdi:waypoint x="165.0" y="175.16233766233768"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

3. 信号开始事件

流程被定义后,当接收到特定一个信号后触发,启动一个流程实例。
image.png
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/processdef">
  <signal id="signal_test_1" name="signal_1" activiti:scope="processInstance"></signal>
  <process id="signal_process_2" name="信号开始事件" isExecutable="true">
    <userTask id="sid-74252F8E-E71A-4EC7-8F56-431D0008260C" name="信号开始事件Test">
      <extensionElements>
        <activiti:taskListener event="create" delegateExpression="${signalTaskCreateListener}"/>
      </extensionElements>
    </userTask>
    <endEvent id="sid-F867A804-CBEF-4ED6-8809-63ADB7BB464B"></endEvent>
    <startEvent id="sid-1F00BBE7-27C2-4178-A5B3-92ECC69B7027" activiti:isInterrupting="false">
      <signalEventDefinition signalRef="signal_test_1"></signalEventDefinition>
    </startEvent>
    <sequenceFlow id="sid-B7C679D3-261D-43C0-B13E-854BD38F00D0" sourceRef="sid-1F00BBE7-27C2-4178-A5B3-92ECC69B7027" targetRef="sid-74252F8E-E71A-4EC7-8F56-431D0008260C"></sequenceFlow>
    <sequenceFlow id="sid-8A5C3A03-A9F6-4396-9221-46F4D5EDCCBB" sourceRef="sid-74252F8E-E71A-4EC7-8F56-431D0008260C" targetRef="sid-F867A804-CBEF-4ED6-8809-63ADB7BB464B"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_signal_process_2">
    <bpmndi:BPMNPlane bpmnElement="signal_process_2" id="BPMNPlane_signal_process_2">
      <bpmndi:BPMNShape bpmnElement="sid-74252F8E-E71A-4EC7-8F56-431D0008260C" id="BPMNShape_sid-74252F8E-E71A-4EC7-8F56-431D0008260C">
        <omgdc:Bounds height="80.0" width="100.0" x="165.0" y="138.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-F867A804-CBEF-4ED6-8809-63ADB7BB464B" id="BPMNShape_sid-F867A804-CBEF-4ED6-8809-63ADB7BB464B">
        <omgdc:Bounds height="28.0" width="28.0" x="320.0" y="164.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-1F00BBE7-27C2-4178-A5B3-92ECC69B7027" id="BPMNShape_sid-1F00BBE7-27C2-4178-A5B3-92ECC69B7027">
        <omgdc:Bounds height="30.0" width="30.0" x="45.0" y="163.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-B7C679D3-261D-43C0-B13E-854BD38F00D0" id="BPMNEdge_sid-B7C679D3-261D-43C0-B13E-854BD38F00D0">
        <omgdi:waypoint x="102.0" y="178.0"></omgdi:waypoint>
        <omgdi:waypoint x="165.0" y="178.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-8A5C3A03-A9F6-4396-9221-46F4D5EDCCBB" id="BPMNEdge_sid-8A5C3A03-A9F6-4396-9221-46F4D5EDCCBB">
        <omgdi:waypoint x="265.0" y="178.0"></omgdi:waypoint>
        <omgdi:waypoint x="320.0" y="178.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

Note:该信号定义不能在单个元素中定义,只能在这个整个流程的属性中添加一个 Signal definitions,并设置属性 Id、Name,选择范围,包含:全局、流程实例。通过 API(runtimeService.signalEventReceivedXXX)触发信号开始事件时,参数必须传递 Signal 中 Name 属性。

4. 消息开始事件

当接受特定消息后触发一个新的流程实例。
流程图:
image.png
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/processdef">
  <message id="message_1" name="message_test"></message>
  <process id="message_process_1" name="消息开始事件Test" isExecutable="true">
    <userTask id="sid-1855D812-F7E8-4765-920E-F051F893881A">
      <extensionElements>
        <activiti:taskListener event="create" expression="${resumeService.messageStartEventsTest(task,task.eventName)}"></activiti:taskListener>
      </extensionElements>
    </userTask>
    <endEvent id="sid-EBB5FBB7-9F7D-4CAA-B531-85A1086275A9"></endEvent>
    <startEvent id="sid-BDC1CC0F-C821-47CA-89CA-54CE0583DC88" activiti:isInterrupting="false">
      <messageEventDefinition messageRef="message_1"></messageEventDefinition>
    </startEvent>
    <sequenceFlow id="sid-1028F72E-DDA6-48A3-9626-F8764CF0822B" sourceRef="sid-1855D812-F7E8-4765-920E-F051F893881A" targetRef="sid-EBB5FBB7-9F7D-4CAA-B531-85A1086275A9"></sequenceFlow>
    <sequenceFlow id="sid-D30AF882-BFDD-46D4-B4BF-F4AF96D0AE7E" sourceRef="sid-BDC1CC0F-C821-47CA-89CA-54CE0583DC88" targetRef="sid-1855D812-F7E8-4765-920E-F051F893881A"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_message_process_1">
    <bpmndi:BPMNPlane bpmnElement="message_process_1" id="BPMNPlane_message_process_1">
      <bpmndi:BPMNShape bpmnElement="sid-1855D812-F7E8-4765-920E-F051F893881A" id="BPMNShape_sid-1855D812-F7E8-4765-920E-F051F893881A">
        <omgdc:Bounds height="80.0" width="100.0" x="165.0" y="140.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-EBB5FBB7-9F7D-4CAA-B531-85A1086275A9" id="BPMNShape_sid-EBB5FBB7-9F7D-4CAA-B531-85A1086275A9">
        <omgdc:Bounds height="28.0" width="28.0" x="310.0" y="166.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-BDC1CC0F-C821-47CA-89CA-54CE0583DC88" id="BPMNShape_sid-BDC1CC0F-C821-47CA-89CA-54CE0583DC88">
        <omgdc:Bounds height="30.0" width="30.5" x="75.0" y="165.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-D30AF882-BFDD-46D4-B4BF-F4AF96D0AE7E" id="BPMNEdge_sid-D30AF882-BFDD-46D4-B4BF-F4AF96D0AE7E">
        <omgdi:waypoint x="106.0" y="180.0"></omgdi:waypoint>
        <omgdi:waypoint x="165.0" y="180.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-1028F72E-DDA6-48A3-9626-F8764CF0822B" id="BPMNEdge_sid-1028F72E-DDA6-48A3-9626-F8764CF0822B">
        <omgdi:waypoint x="265.0" y="180.0"></omgdi:waypoint>
        <omgdi:waypoint x="310.0" y="180.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

Note:一个流程定义中,如有多个消息开始事件则不能有相同的消息名称。可以通过 API(runtimeService.startProcessInstanceByMessage)来触发消息开始事件,参数传递必须是 message 元素 name 属性。子流程不支持消息启动事件。

回帖
请输入回帖内容...