activiti之信号触发事件

 信号----广播----对应所有定义信号事件的 执行流

 

消息---打电话--对应当前用户的执行流

 

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>

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值