信号----广播----对应所有定义信号事件的 执行流
消息---打电话--对应当前用户的执行流
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.Execution;
import org.activiti.engine.runtime.ProcessInstance;
public class SingleEventTest {
public static void main(String[] args) {
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
// 存储服务
RepositoryService rs = engine.getRepositoryService();
// 运行时服务
RuntimeService runService = engine.getRuntimeService();
// 任务服务
TaskService taskService = engine.getTaskService();
// 部署
Deployment dep = rs.createDeployment()
.addClasspathResource("SingleEvent.bpmn").deploy();
ProcessDefinition pd = rs.createProcessDefinitionQuery()
.deploymentId(dep.getId()).singleResult();
// 启动流程
ProcessInstance pi = runService.startProcessInstanceById(pd.getId());
// 查当前的子执行流(只有一个)
Execution exe = runService.createExecutionQuery()
.processInstanceId(pi.getId()).onlyChildExecutions()
.singleResult();
System.out.println(pi.getId() + ", 当前节点:" + exe.getActivityId());
runService.signalEventReceived("testSignal");
exe = runService.createExecutionQuery()
.processInstanceId(pi.getId()).onlyChildExecutions()
.singleResult();
System.out.println(pi.getId() + ", 当前节点:" + exe.getActivityId());
}
}
<?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="testSignal" name="testSignal"></signal>
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<intermediateCatchEvent id="signalintermediatecatchevent1"
name="SignalCatchEvent">
<signalEventDefinition signalRef="testSignal"></signalEventDefinition>
</intermediateCatchEvent>
<userTask id="usertask1" name="User Task"></userTask>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow1" sourceRef="startevent1"
targetRef="signalintermediatecatchevent1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="signalintermediatecatchevent1"
targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow3" sourceRef="usertask1"
targetRef="endevent1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
<bpmndi:BPMNPlane bpmnElement="myProcess"
id="BPMNPlane_myProcess">
<bpmndi:BPMNShape bpmnElement="startevent1"
id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="150.0"
y="140.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="signalintermediatecatchevent1"
id="BPMNShape_signalintermediatecatchevent1">
<omgdc:Bounds height="35.0" width="35.0" x="260.0"
y="140.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1"
id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0"
x="370.0" y="130.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1"
id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="560.0"
y="140.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1"
id="BPMNEdge_flow1">
<omgdi:waypoint x="185.0" y="157.0"></omgdi:waypoint>
<omgdi:waypoint x="260.0" y="157.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2"
id="BPMNEdge_flow2">
<omgdi:waypoint x="295.0" y="157.0"></omgdi:waypoint>
<omgdi:waypoint x="370.0" y="157.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3"
id="BPMNEdge_flow3">
<omgdi:waypoint x="475.0" y="157.0"></omgdi:waypoint>
<omgdi:waypoint x="560.0" y="157.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>