工作流activiti 6 学习笔记六 边界事件
【摘要】 边界事件分以下六类。第一类:TimerBoundaryEvent 边界事件,<process id="myProcess" name="My process" isExecutable="true"> <userTask id="usertask1" name="task1"></userTask> <boundaryEvent id="boundarytimer1" name=...
边界事件分以下六类。
第一类:TimerBoundaryEvent 边界事件,
<process id="myProcess" name="My process" isExecutable="true">
<userTask id="usertask1" name="task1"></userTask>
<boundaryEvent id="boundarytimer1" name="Timer" attachedToRef="usertask1" cancelActivity="true">
<timerEventDefinition><timeDuration>PT1M</timeDuration></timerEventDefinition>
</boundaryEvent>
<userTask id="usertask2" name="task3"></userTask>
<endEvent id="endevent1" name="End"></endEvent>
<userTask id="usertask3" name="task2"></userTask>
<startEvent id="startevent1" name="Start"></startEvent>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
<sequenceFlow id="flow3" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>
<sequenceFlow id="flow4" sourceRef="boundarytimer1" targetRef="usertask3"></sequenceFlow>
<sequenceFlow id="flow5" sourceRef="usertask3" targetRef="endevent1"></sequenceFlow>
</process>
activiti.cfg.xml 配置文件修改,开启异步执行,如果不开启,则无法正常运行
<property name="asyncExecutorActivate" value="true" />
java代码
// 部署流程
Deployment deploye = rs.createDeployment().addClasspathResource("timerBoundary.bpmn").deploy();
ProcessDefinition pdf = rs.createProcessDefinitionQuery().deploymentId(deploye.getId()).singleResult();
ProcessInstance pi = runS.startProcessInstanceById(pdf.getId());
System.out.println(pi.getId());
Task task = ts.createTaskQuery().processInstanceId(pi.getId()).singleResult();
System.out.println("当前任务节点"+task.getName());
Thread.sleep(70*1000);
task = ts.createTaskQuery().processInstanceId(pi.getId()).singleResult();
System.out.println("当前任务节点"+task.getName());
运行结果
170005
当前任务节点task1
当前任务节点task2
代码解释:
如果在每执行定时任务前,就审批结束task1,节点会流向task3,代码验证:
// 部署流程
Deployment deploye = rs.createDeployment().addClasspathResource("timerBoundary.bpmn").deploy();
ProcessDefinition pdf = rs.createProcessDefinitionQuery().deploymentId(deploye.getId()).singleResult();
ProcessInstance pi = runS.startProcessInstanceById(pdf.getId());
System.out.println(pi.getId());
Task task = ts.createTaskQuery().processInstanceId(pi.getId()).singleResult();
System.out.println("当前任务节点"+task.getName());
ts.complete(task.getId());// 定时任务触发前,审批结束
Thread.sleep(70*1000);
task = ts.createTaskQuery().processInstanceId(pi.getId()).singleResult();
System.out.println("当前任务节点"+task.getName());
运行结果
172505
当前任务节点task1
当前任务节点task3
bpmn文件中定时规则有三种:分别是:<timeDuration>PT1M</timeDuration>,<timeCycle></timeCycle>,<timeDate></timeDate>, 可根据业务场景进行选择使用。
第二种:错误边界事件,前面文章有提到
第三种:信号边界事件,这个是全局事件,所有流程都能收到。
bpmn文件
<signal id="signalId" name="signalName"></signal>
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="task1"></userTask>
<userTask id="usertask2" name="task2"></userTask>
<userTask id="usertask3" name="task3"></userTask>
<endEvent id="endevent1" name="End"></endEvent>
<userTask id="usertask4" name="task4"></userTask>
<boundaryEvent id="boundarysignal1" name="Signal" attachedToRef="usertask2" cancelActivity="true">
<signalEventDefinition signalRef="signalId"></signalEventDefinition>
</boundaryEvent>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
<sequenceFlow id="flow3" sourceRef="usertask2" targetRef="usertask3"></sequenceFlow>
<sequenceFlow id="flow4" sourceRef="usertask3" targetRef="endevent1"></sequenceFlow>
<sequenceFlow id="flow5" sourceRef="boundarysignal1" targetRef="usertask4"></sequenceFlow>
<sequenceFlow id="flow6" sourceRef="usertask4" targetRef="usertask1"></sequenceFlow>
</process>
java代码
// 部署流程
Deployment deploye = rs.createDeployment().addClasspathResource("signalBoundary.bpmn").deploy();
ProcessDefinition pdf = rs.createProcessDefinitionQuery().deploymentId(deploye.getId()).singleResult();
ProcessInstance pi = runS.startProcessInstanceById(pdf.getId());
System.out.println(pi.getId());
Task task = ts.createTaskQuery().processInstanceId(pi.getId()).singleResult();
System.out.println("当前任务节点"+task.getName());
ts.complete(task.getId());
runS.signalEventReceived("signalName");// 发现消息,始节点跳转到task4
task = ts.createTaskQuery().processInstanceId(pi.getId()).singleResult();
System.out.println("当前任务节点"+task.getName());
运行结果:
175005
当前任务节点task1
当前任务节点task4
代码解释;
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)