一、流程图
二、代码实现
1>
- package com.njupt.custom;
- import java.util.Map;
- import org.jbpm.api.activity.ActivityExecution;
- import org.jbpm.api.activity.ExternalActivityBehaviour;
- public class ExternalActivityBehaviourImpl implements ExternalActivityBehaviour {
- // 到达活动后要执行的代码,这就是本活动的行为。
- // 默认是执行完后就使用默认的Transition离开本活动。
- @Override
- public void execute(ActivityExecution execution) throws Exception {
- System.out.println("---> ExternalActivityBehaviourImpl.execute()");
- System.out.println("已经发短信通知所有员工.");
- // // 使用默认的Transition离开本活动(这也是默认行为)
- // execution.takeDefaultTransition();
- // 使用指定的Transition离开本活动
- // execution.take(transitionName);
- // 在本活动等待,直到外部调用signalExecution()时才离开本活动
- execution.waitForSignal();
- }
- // 在离开活动前会被调用的代码,本方法名如果叫做beforeSignal()就好理解了。
- // 在外部调用signalExecution()时,本方法才会执行。
- @Override
- public void signal(ActivityExecution execution, String signalName, Map<String, ?> parameters) throws Exception {
- System.out.println("---> ExternalActivityBehaviourImpl.signal()");
- }
- }
2>编写测试类
- package com.njupt.custom;
- import java.io.InputStream;
- import org.jbpm.api.Configuration;
- import org.jbpm.api.ProcessEngine;
- import org.jbpm.api.ProcessInstance;
- import org.junit.Test;
- public class ProcessTest {
- private ProcessEngine processEngine = Configuration.getProcessEngine();
- @Test
- public void test() throws Exception {
- // 1,部署流程定义
- InputStream in = getClass().getResourceAsStream("test.jpdl.xml");
- processEngine.getRepositoryService()//
- .createDeployment()//
- .addResourceFromInputStream("test.jpdl.xml", in)//
- .deploy();
- // 2,启动流程实例
- ProcessInstance pi = processEngine.getExecutionService().startProcessInstanceByKey("test");
- }
- @Test
- public void testSingal() throws Exception {
- String executionId = "test.340007";
- processEngine.getExecutionService().signalExecutionById(executionId);
- }
- }