- 浏览: 772799 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (208)
- Java (77)
- JavaScript (16)
- UML (1)
- Spring (24)
- Hibernate (11)
- J2EE部署 (18)
- 操作系统 (13)
- struts (11)
- jsp (3)
- J2EE (34)
- 数据库 (22)
- tomcat (4)
- apache (2)
- MyEclipse (13)
- Linux (14)
- Ext (6)
- Weblogic (2)
- 数据库 Oracle 空表导出 (1)
- Oracle (3)
- 编码 乱码 (1)
- 多线程 (5)
- jQuery (2)
- Apache Mina (1)
- ibatis (6)
- abator (1)
- svn (1)
- jvm (1)
- ERwin (2)
- mysql (2)
- ant (1)
- memcache (1)
- dubbo (1)
- PowerDesigner (1)
最新评论
-
di1984HIT:
Shallow heap & Retained heap -
tinguo002:
非常感谢 , 太棒了。
Spring注解方式,异常 'sessionFactory' or 'hibernateTemplate' is required的解决方法 -
白天看黑夜:
Apache Mina Server 2.0 中文参考手册(带 ...
Apache Mina – 简单的客户端/服务端应用示例 -
wumingxingzhe:
好文
Shallow heap & Retained heap -
di1984HIT:
学习了!!
工作流(Workflow)和BPM的不同
Activiti 5.6支持流程活动自动执行与手工触发执行。其中,自动执行是指,在启动流程之前,准备流程所需要的控制流程进度的变量数据,启动流程之后,无需外部干预,就能够按照预定义的流程执行;手工触发执行是指,执行到流程中某个个结点后流程暂时停止运行,直到收到外部发送的信号以后,才会继续向前推进,这样情况可以更加精细地控制流程。
下面主要通过基于Activiti 5.6的<parallelGateway>、<serviceTask>、<receiveTask>、<userTask>元素来看一下。首先,我们在测试的过程中,用到JUnit 3.x,为了方便,这里给了一层封装,代码如下所示:
这里面,主要是在测试之前做一些初始化工作,主要包括流程引擎实例的构建,及其流程提供的基本服务。下面测试会用到该抽象类。
自动执行
<serviceTask>元素,可以实现自动活动,语法如下所示:
<serviceTask id="serviceTaskId" name="serviceTaskName"
activiti:class="org.shirdrn.workflow.activiti.gateway.ServiceTaskClass"/>
其中,activiti:class属性为该结点对应的处理类,该类要求实现org.activiti.engine.delegate.JavaDelegate接口,该接口定义如下所示:
execute方法的参数DelegateExecution execution可以在流程中各个结点之间传递流程变量。
下面给出一个具体的例子:
自动执行的流程,如图所示:
对应的流程定义文件为GatewayTest.testAutomaticForkJoin.bpmn20.xml,如下所示:
上述流程定义中,一共定义了4个ServiceTask,模拟实现代码如下所示
Task1:
Task2:
Task3:
Task4:
测试代码,如下所示:
只需要启动一个流程实例,它会自动执行到结束。这种情况下,你不需要关注流程的执行进度,而只需要把精力集中在每个结点的处理逻辑(通常是简单或者复杂的商业逻辑)上,运行结果如下所示:
===================================
手工触发执行
通过<receiveTask>和<userTask>元素都可以实现流程的手工触发执行。
基于<receiveTask>
实现的流程,如图所示:
对应的流程定义文件Task.ReceiveTask.bpmn20.xml,如下所示:
上述流程定义中,对应的两个处理类,代码分别如下所示:
上面还用到一个org.shirdrn.workflow.activiti.subprocess.Merchant类,该类必须支持序列化,如下所示:
测试用例,代码如下所示:
运行结果如下所示:
基于<userTask>
实现的流程,如图所示:
对应的流程定义文件,如下所示:
我们看一下上述定义中,如下配置片段:
<activiti:taskListener>元素的event属性,它一共包含三种事件:"create"、"assignment"、"complete",分别表示结点执行处理逻辑的时机为:在处理类实例化时、在结点处理逻辑被指派时、在结点处理逻辑执行完成时,可以根据自己的需要进行指定。
上述流程定义中,4个任务结点对应的处理类,代码分别如下所示:
测试用例,代码如下所示:
运行结果如下所示:
下面主要通过基于Activiti 5.6的<parallelGateway>、<serviceTask>、<receiveTask>、<userTask>元素来看一下。首先,我们在测试的过程中,用到JUnit 3.x,为了方便,这里给了一层封装,代码如下所示:
package org.shirdrn.workflow.activiti; import junit.framework.TestCase; import org.activiti.engine.FormService; import org.activiti.engine.HistoryService; import org.activiti.engine.IdentityService; import org.activiti.engine.ManagementService; 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; public abstract class AbstractTest extends TestCase { private ProcessEngine processEngine; protected String deploymentId; protected RepositoryService repositoryService; protected RuntimeService runtimeService; protected TaskService taskService; protected FormService formService; protected HistoryService historyService; protected IdentityService identityService; protected ManagementService managementService; @Override protected void setUp() throws Exception { super.setUp(); if(processEngine==null) { processEngine = ProcessEngines.getDefaultProcessEngine(); } repositoryService = processEngine.getRepositoryService(); runtimeService = processEngine.getRuntimeService(); taskService = processEngine.getTaskService(); formService = processEngine.getFormService(); historyService = processEngine.getHistoryService(); identityService = processEngine.getIdentityService(); managementService = processEngine.getManagementService(); initialize(); } @Override protected void tearDown() throws Exception { super.tearDown(); destroy(); } protected abstract void initialize() throws Exception; protected abstract void destroy() throws Exception; }
这里面,主要是在测试之前做一些初始化工作,主要包括流程引擎实例的构建,及其流程提供的基本服务。下面测试会用到该抽象类。
自动执行
<serviceTask>元素,可以实现自动活动,语法如下所示:
<serviceTask id="serviceTaskId" name="serviceTaskName"
activiti:class="org.shirdrn.workflow.activiti.gateway.ServiceTaskClass"/>
其中,activiti:class属性为该结点对应的处理类,该类要求实现org.activiti.engine.delegate.JavaDelegate接口,该接口定义如下所示:
package org.activiti.engine.delegate; public interface JavaDelegate { void execute(DelegateExecution execution) throws Exception; }
execute方法的参数DelegateExecution execution可以在流程中各个结点之间传递流程变量。
下面给出一个具体的例子:
自动执行的流程,如图所示:
对应的流程定义文件为GatewayTest.testAutomaticForkJoin.bpmn20.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: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"> <process id="AutomaticParalellBasedForkJoin" name="AutomaticParalellBasedForkJoin"> <startEvent id="startevent7" name="Start"></startEvent> <parallelGateway id="parallelgateway12" name="Fork"></parallelGateway> <serviceTask id="servicetask3" name="Task 1" activiti:class="org.shirdrn.workflow.activiti.gateway.ServiceTask1"></serviceTask> <serviceTask id="servicetask4" name="Task 2" activiti:class="org.shirdrn.workflow.activiti.gateway.ServiceTask2"></serviceTask> <serviceTask id="servicetask5" name="Task 3" activiti:class="org.shirdrn.workflow.activiti.gateway.ServiceTask3"></serviceTask> <parallelGateway id="parallelgateway13" name="First Join"></parallelGateway> <serviceTask id="servicetask6" name="Task 4" activiti:class="org.shirdrn.workflow.activiti.gateway.ServiceTask4"></serviceTask> <parallelGateway id="parallelgateway14"></parallelGateway> <endEvent id="endevent7" name="End"></endEvent> <sequenceFlow id="flow45" name="" sourceRef="startevent7" targetRef="parallelgateway12"></sequenceFlow> <sequenceFlow id="flow46" name="" sourceRef="parallelgateway12" targetRef="servicetask3"></sequenceFlow> <sequenceFlow id="flow47" name="" sourceRef="parallelgateway12" targetRef="servicetask4"></sequenceFlow> <sequenceFlow id="flow48" name="" sourceRef="parallelgateway12" targetRef="servicetask5"></sequenceFlow> <sequenceFlow id="flow49" name="" sourceRef="servicetask3" targetRef="parallelgateway13"></sequenceFlow> <sequenceFlow id="flow50" name="" sourceRef="servicetask4" targetRef="parallelgateway13"></sequenceFlow> <sequenceFlow id="flow51" name="" sourceRef="servicetask5" targetRef="parallelgateway14"></sequenceFlow> <sequenceFlow id="flow52" name="" sourceRef="parallelgateway13" targetRef="servicetask6"></sequenceFlow> <sequenceFlow id="flow53" name="" sourceRef="servicetask6" targetRef="parallelgateway14"></sequenceFlow> <sequenceFlow id="flow54" name="" sourceRef="parallelgateway14" targetRef="endevent7"></sequenceFlow> </process> </definitions>
上述流程定义中,一共定义了4个ServiceTask,模拟实现代码如下所示
Task1:
package org.shirdrn.workflow.activiti.gateway; import java.util.logging.Logger; import org.activiti.engine.delegate.DelegateExecution; import org.activiti.engine.delegate.JavaDelegate; public class ServiceTask1 implements JavaDelegate { private final Logger log = Logger.getLogger(ServiceTask1.class.getName()); @Override public void execute(DelegateExecution execution) throws Exception { Thread.sleep(10000); log.info("variavles=" + execution.getVariables()); execution.setVariable("task1", "I am task 1"); log.info("I am task 1."); } }
Task2:
package org.shirdrn.workflow.activiti.gateway; import java.util.logging.Logger; public class ServiceTask2 implements JavaDelegate { private final Logger log = Logger.getLogger(ServiceTask2.class.getName()); @Override public void execute(DelegateExecution execution) throws Exception { Thread.sleep(10000); log.info("variavles=" + execution.getVariables()); execution.setVariable("task2", "I am task 2"); log.info("I am task 2."); } }
Task3:
package org.shirdrn.workflow.activiti.gateway; import java.util.logging.Logger; public class ServiceTask3 implements JavaDelegate { private final Logger log = Logger.getLogger(ServiceTask3.class.getName()); @Override public void execute(DelegateExecution execution) throws Exception { Thread.sleep(10000); log.info("variavles=" + execution.getVariables()); execution.setVariable("task3", "I am task 3"); log.info("I am task 3."); } }
Task4:
package org.shirdrn.workflow.activiti.gateway; import java.util.logging.Logger; public class ServiceTask4 implements JavaDelegate { private final Logger log = Logger.getLogger(ServiceTask4.class.getName()); @Override public void execute(DelegateExecution execution) throws Exception { Thread.sleep(10000); log.info("variavles=" + execution.getVariables()); execution.setVariable("task4", "I am task 4"); log.info("I am task 4."); } }
测试代码,如下所示:
package org.shirdrn.workflow.activiti.gateway; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.test.Deployment; import org.shirdrn.workflow.activiti.AbstractTest; public class AutomaticParallelGatewayTest extends AbstractTest { private String deploymentId; @Override protected void initialize() throws Exception { deploymentId = repositoryService.createDeployment() .addClasspathResource("diagrams/GatewayTest.testAutomaticForkJoin.bpmn20.xml") .deploy().getId(); } @Override protected void destroy() throws Exception { repositoryService.deleteDeployment(deploymentId, true); } @Deployment public void testForkJoin() { ProcessInstance pi = runtimeService.startProcessInstanceByKey("AutomaticParalellBasedForkJoin"); assertEquals(true, pi.isEnded()); } }
只需要启动一个流程实例,它会自动执行到结束。这种情况下,你不需要关注流程的执行进度,而只需要把精力集中在每个结点的处理逻辑(通常是简单或者复杂的商业逻辑)上,运行结果如下所示:
Sep 21, 2011 10:41:04 AM com.workflow.activiti.gateway.ServiceTask1 execute INFO: variavles={} Sep 21, 2011 10:41:04 AM com.workflow.activiti.gateway.ServiceTask1 execute INFO: I am task 1. Sep 21, 2011 10:41:14 AM com.workflow.activiti.gateway.ServiceTask2 execute INFO: variavles={task1=I am task 1} Sep 21, 2011 10:41:14 AM com.workflow.activiti.gateway.ServiceTask2 execute INFO: I am task 2. Sep 21, 2011 10:41:24 AM com.workflow.activiti.gateway.ServiceTask4 execute INFO: variavles={task1=I am task 1, task2=I am task 2} Sep 21, 2011 10:41:24 AM com.workflow.activiti.gateway.ServiceTask4 execute INFO: I am task 4. Sep 21, 2011 10:41:34 AM com.workflow.activiti.gateway.ServiceTask3 execute INFO: variavles={task1=I am task 1, task2=I am task 2, task4=I am task 4} Sep 21, 2011 10:41:34 AM com.workflow.activiti.gateway.ServiceTask3 execute INFO: I am task 3.
===================================
手工触发执行
通过<receiveTask>和<userTask>元素都可以实现流程的手工触发执行。
基于<receiveTask>
实现的流程,如图所示:
对应的流程定义文件Task.ReceiveTask.bpmn20.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: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"> <process id="MyReceiveTask" name="MyReceiveTask"> <startEvent id="startevent4" name="Start"></startEvent> <receiveTask id="receivetask1" name="Check bank"> <extensionElements> <activiti:executionListener event="start" class="org.shirdrn.workflow.activiti.task.CheckBankReceiveTask"></activiti:executionListener> </extensionElements> </receiveTask> <receiveTask id="receivetask2" name="Check merchant"> <extensionElements> <activiti:executionListener event="start" class="org.shirdrn.workflow.activiti.task.CheckMerchantReceiveTask"></activiti:executionListener> </extensionElements> </receiveTask> <endEvent id="endevent5" name="End"></endEvent> <sequenceFlow id="flow16" name="" sourceRef="startevent4" targetRef="receivetask1"></sequenceFlow> <sequenceFlow id="flow17" name="" sourceRef="receivetask1" targetRef="receivetask2"></sequenceFlow> <sequenceFlow id="flow18" name="" sourceRef="receivetask2" targetRef="endevent5"></sequenceFlow> </process> </definitions>
上述流程定义中,对应的两个处理类,代码分别如下所示:
package org.shirdrn.workflow.activiti.task; import java.util.HashMap; import java.util.logging.Logger; import org.activiti.engine.delegate.DelegateExecution; import org.activiti.engine.delegate.JavaDelegate; public class CheckBankReceiveTask implements JavaDelegate { private final Logger log = Logger.getLogger(CheckBankReceiveTask.class.getName()); @SuppressWarnings("unchecked") @Override public void execute(DelegateExecution execution) throws Exception { log.info("i am CheckBankReceiveTask."); System.out.println("in : " + execution.getVariables()); ((HashMap<String, Object>)execution.getVariables().get("in")).put("next", "CheckBankTask"); ((HashMap<String, Object>)execution.getVariables().get("out")).put("reponse", "subprocess:CheckBankReceiveTask->CheckMerchantReceiveTask"); } }
package org.shirdrn.workflow.activiti.task; import java.util.HashMap; import java.util.logging.Logger; import org.activiti.engine.delegate.DelegateExecution; import org.activiti.engine.delegate.JavaDelegate; public class CheckMerchantReceiveTask implements JavaDelegate { private final Logger log = Logger.getLogger(CheckMerchantReceiveTask.class.getName()); @SuppressWarnings("unchecked") @Override public void execute(DelegateExecution execution) throws Exception { log.info("i am CheckMerchantReceiveTask."); System.out.println("in : " + execution.getVariables()); ((HashMap<String, Object>)execution.getVariables().get("in")).put("previous", "CheckMerchantReceiveTask"); } }
上面还用到一个org.shirdrn.workflow.activiti.subprocess.Merchant类,该类必须支持序列化,如下所示:
package org.shirdrn.workflow.activiti.subprocess; import java.io.Serializable; public class Merchant implements Serializable { private static final long serialVersionUID = 1L; public Merchant(String merchantId, int priority, short serviceType, short status) { super(); this.merchantId = merchantId; this.priority = priority; this.serviceType = serviceType; this.status = status; } public Merchant(String merchantId) { this(merchantId, -1, (short)0, (short)0); } private String merchantId; private int priority = -1; private short serviceType = 0; private short status = 0; public String getMerchantId() { return merchantId; } public void setMerchantId(String merchantId) { this.merchantId = merchantId; } public int getPriority() { return priority; } public void setPriority(int priority) { this.priority = priority; } public short getServiceType() { return serviceType; } public void setServiceType(short serviceType) { this.serviceType = serviceType; } public short getStatus() { return status; } public void setStatus(short status) { this.status = status; } @Override public String toString() { return "Merchant[" + merchantId + "]"; } }
测试用例,代码如下所示:
package org.shirdrn.workflow.activiti.task; import java.util.HashMap; import java.util.List; import java.util.Map; import org.activiti.engine.repository.Deployment; import org.activiti.engine.runtime.Execution; import org.activiti.engine.runtime.ProcessInstance; import org.shirdrn.workflow.activiti.AbstractTest; import org.shirdrn.workflow.activiti.subprocess.Merchant; public class MyReceiveTaskTest extends AbstractTest { @Override protected void initialize() throws Exception { Deployment deployment = repositoryService .createDeployment() .addClasspathResource( "diagrams/Task.ReceiveTask.bpmn20.xml") .deploy(); deploymentId = deployment.getId(); } @Override protected void destroy() throws Exception { repositoryService.deleteDeployment(deploymentId, true); } public void testSubProcess() { // prepare data packet Map<String, Object> variables = new HashMap<String, Object>(); Map<String, Object> subVariables = new HashMap<String, Object>(); variables.put("maxTransCount", 1000000); variables.put("merchant", new Merchant("ICBC")); variables.put("protocol", "UM32"); variables.put("repository", "10.10.38.99:/home/shirdrn/repository"); variables.put("in", subVariables); variables.put("out", new HashMap<String, Object>()); // start process instance ProcessInstance pi = runtimeService.startProcessInstanceByKey("MyReceiveTask", variables); List<Execution> executions = runtimeService.createExecutionQuery().list(); assertEquals(1, executions.size()); Execution execution = runtimeService.createExecutionQuery().singleResult(); runtimeService.setVariable(execution.getId(), "type", "receiveTask"); runtimeService.signal(execution.getId()); assertEquals(1, executions.size()); execution = runtimeService.createExecutionQuery().list().get(0); assertNotNull(execution); runtimeService.setVariable(execution.getId(), "oper", "shirdrn"); runtimeService.signal(execution.getId()); } }
运行结果如下所示:
2011-3-23 12:51:35 org.shirdrn.workflow.activiti.task.CheckBankReceiveTask execute 信息: i am CheckBankReceiveTask. in : {protocol=UM32, repository=10.10.38.99:/home/shirdrn/repository, merchant=Merchant[ICBC], maxTransCount=1000000, in={}, out={}} 2011-3-23 12:51:35 org.shirdrn.workflow.activiti.task.CheckMerchantReceiveTask execute 信息: i am CheckMerchantReceiveTask. in : {protocol=UM32, repository=10.10.38.99:/home/shirdrn/repository, merchant=Merchant[ICBC], maxTransCount=1000000, type=receiveTask, in={}, out={}}
基于<userTask>
实现的流程,如图所示:
对应的流程定义文件,如下所示:
<?xml version="1.0" encoding="UTF-8"?> <definitions id="definitions" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" targetNamespace="Umpay"> <process id="ParalellBasedForkJoin"> <startEvent id="theStart" /> <sequenceFlow id="flow1" sourceRef="theStart" targetRef="fork" /> <parallelGateway id="fork" name="Fork" /> <sequenceFlow sourceRef="fork" targetRef="task1" /> <sequenceFlow sourceRef="fork" targetRef="task2" /> <sequenceFlow sourceRef="fork" targetRef="task3" /> <userTask id="task1" name="Task 1"> <extensionElements> <activiti:taskListener event="complete" class="org.shirdrn.workflow.activiti.gateway.Task1Listener" /> </extensionElements> </userTask> <sequenceFlow sourceRef="task1" targetRef="firstJoin" /> <userTask id="task2" name="Task 2"> <extensionElements> <activiti:taskListener event="complete" class="org.shirdrn.workflow.activiti.gateway.Task2Listener" /> </extensionElements> </userTask> <sequenceFlow sourceRef="task2" targetRef="firstJoin" /> <userTask id="task3" name="Task 3"> <extensionElements> <activiti:taskListener event="complete" class="org.shirdrn.workflow.activiti.gateway.Task3Listener" /> </extensionElements> </userTask> <sequenceFlow sourceRef="task3" targetRef="secondJoin" /> <parallelGateway id="firstJoin" name="First Join" /> <sequenceFlow sourceRef="firstJoin" targetRef="task4" /> <userTask id="task4" name="Task 4"> <extensionElements> <activiti:taskListener event="complete" class="org.shirdrn.workflow.activiti.gateway.Task4Listener" /> </extensionElements> </userTask> <sequenceFlow sourceRef="task4" targetRef="secondJoin" /> <parallelGateway id="secondJoin" /> <sequenceFlow sourceRef="secondJoin" targetRef="theEnd" /> <endEvent id="theEnd" /> </process> </definitions>
我们看一下上述定义中,如下配置片段:
<userTask id="task1" name="Task 1"> <extensionElements> <activiti:taskListener event="complete" class="org.shirdrn.workflow.activiti.gateway.Task1Listener" /> </extensionElements> </userTask>
<activiti:taskListener>元素的event属性,它一共包含三种事件:"create"、"assignment"、"complete",分别表示结点执行处理逻辑的时机为:在处理类实例化时、在结点处理逻辑被指派时、在结点处理逻辑执行完成时,可以根据自己的需要进行指定。
上述流程定义中,4个任务结点对应的处理类,代码分别如下所示:
package org.shirdrn.workflow.activiti.gateway; import java.util.logging.Logger; import org.activiti.engine.delegate.DelegateTask; import org.activiti.engine.impl.pvm.delegate.TaskListener; public class Task1Listener implements TaskListener { private final Logger log = Logger.getLogger(Task1Listener.class.getName()); @Override public void notify(DelegateTask delegateTask) { try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } log.info("I am task 1."); } }
package org.shirdrn.workflow.activiti.gateway; import java.util.logging.Logger; public class Task2Listener implements TaskListener { private final Logger log = Logger.getLogger(Task2Listener.class.getName()); @Override public void notify(DelegateTask delegateTask) { try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } log.info("I am task 2."); } }
package org.shirdrn.workflow.activiti.gateway; import java.util.logging.Logger; public class Task3Listener implements TaskListener { private final Logger log = Logger.getLogger(Task3Listener.class.getName()); @Override public void notify(DelegateTask delegateTask) { try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } log.info("I am task 3."); } }
引用
package org.shirdrn.workflow.activiti.gateway;
import java.util.logging.Logger;
public class Task4Listener implements TaskListener {
private final Logger log = Logger.getLogger(Task4Listener.class.getName());
@Override
public void notify(DelegateTask delegateTask) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
log.info("I am task 4.");
}
}
import java.util.logging.Logger;
public class Task4Listener implements TaskListener {
private final Logger log = Logger.getLogger(Task4Listener.class.getName());
@Override
public void notify(DelegateTask delegateTask) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
log.info("I am task 4.");
}
}
测试用例,代码如下所示:
引用
package org.shirdrn.workflow.activiti.gateway;
import java.util.Date;
import java.util.List;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
import org.activiti.engine.test.Deployment;
import org.shirdrn.workflow.activiti.AbstractTest;
public class ParallelGatewayTest extends AbstractTest {
private String deploymentId;
private Date start = null;
private Date end = null;
@Override
protected void initialize() throws Exception {
deploymentId = repositoryService.createDeployment()
.addClasspathResource("diagrams/GatewayTest.testForkJoin.bpmn20.xml")
.deploy().getId();
}
@Override
protected void destroy() throws Exception {
repositoryService.deleteDeployment(deploymentId, true);
}
@Deployment
public void testUnbalancedForkJoin() {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("ParalellBasedForkJoin");
TaskQuery query = taskService.createTaskQuery().processInstanceId(pi.getId()).orderByTaskName().asc();
List<Task> tasks = query.list();
assertEquals(3, tasks.size());
start = new Date();
for(Task task : tasks) {
taskService.complete(task.getId());
end = new Date();
System.out.println("" + (end.getTime()-start.getTime()) + "ms.");
}
tasks = query.list();
assertEquals(1, tasks.size());
for(Task task : tasks) {
taskService.complete(task.getId());
end = new Date();
System.out.println("" + (end.getTime()-start.getTime()) + "ms.");
}
end = new Date();
System.out.println("" + (end.getTime()-start.getTime()) + "ms.");
}
}
import java.util.Date;
import java.util.List;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
import org.activiti.engine.test.Deployment;
import org.shirdrn.workflow.activiti.AbstractTest;
public class ParallelGatewayTest extends AbstractTest {
private String deploymentId;
private Date start = null;
private Date end = null;
@Override
protected void initialize() throws Exception {
deploymentId = repositoryService.createDeployment()
.addClasspathResource("diagrams/GatewayTest.testForkJoin.bpmn20.xml")
.deploy().getId();
}
@Override
protected void destroy() throws Exception {
repositoryService.deleteDeployment(deploymentId, true);
}
@Deployment
public void testUnbalancedForkJoin() {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("ParalellBasedForkJoin");
TaskQuery query = taskService.createTaskQuery().processInstanceId(pi.getId()).orderByTaskName().asc();
List<Task> tasks = query.list();
assertEquals(3, tasks.size());
start = new Date();
for(Task task : tasks) {
taskService.complete(task.getId());
end = new Date();
System.out.println("" + (end.getTime()-start.getTime()) + "ms.");
}
tasks = query.list();
assertEquals(1, tasks.size());
for(Task task : tasks) {
taskService.complete(task.getId());
end = new Date();
System.out.println("" + (end.getTime()-start.getTime()) + "ms.");
}
end = new Date();
System.out.println("" + (end.getTime()-start.getTime()) + "ms.");
}
}
运行结果如下所示:
2011-3-23 12:50:09 org.shirdrn.workflow.activiti.gateway.Task1Listener notify 信息: I am task 1. 10031ms. 2011-3-23 12:50:19 org.shirdrn.workflow.activiti.gateway.Task2Listener notify 信息: I am task 2. 20078ms. 2011-3-23 12:50:24 org.shirdrn.workflow.activiti.gateway.Task3Listener notify 信息: I am task 3. 25093ms. 2011-3-23 12:50:29 org.shirdrn.workflow.activiti.gateway.Task4Listener notify 信息: I am task 4. 30172ms. 30172ms.
发表评论
-
Eclipse,javaw 通过Proxifile代理ipv6协议问题解决
2015-03-17 18:06 2797myeclipse2010升级到myeclipse2014之后 ... -
初始化EHcache CacheManager时报java.net.UnknownHostException
2014-11-13 11:45 12510工程启动时,报一下异常: [wdfportal] [201 ... -
tomcat7可能带来的问题
2013-06-27 00:31 9841、struts标签校验更加严格,如果struts标签中存在嵌 ... -
iBatis执行insert后返回主键
2013-01-18 23:55 1652iBatis插入数据后,返回主键。级联操作很有用。省去了一次的 ... -
Shallow heap & Retained heap
2012-05-16 17:09 49325所有包含Heap Profling功能的工具(MAT, You ... -
什么是两阶段提交协议
2012-05-08 16:58 1067两阶段提交协议 实现分布式事务的关键就是两阶段提交协议。在此 ... -
Abator —— IBatis 代码生成工具
2012-04-03 18:31 19351、在eclipse安装abator插件http://ibat ... -
使用Eclipse远程调试Tomcat
2012-03-23 22:56 1512有些时候,调试不得不用外网,比如说做支付宝的支付接口,服务器后 ... -
Java compiler level does not match the version of the installed Java project fac
2012-03-02 11:32 1321问题现象:项目图标报错“Java compiler level ... -
WebService的事务处理
2012-03-01 15:03 1562如果你只是要解决两个系统之间的事务同步问题,可以采用判断服务是 ... -
线程池(java.util.concurrent.ThreadPoolExecutor)的使用
2012-02-29 15:50 2509一、简介 线程池类为 j ... -
myeclipse 颜色设置(保护视力)
2012-02-28 09:29 20911.window -> Preferences -> ... -
Quartz表达式解析
2012-02-08 14:40 809字段 允许值 允许的特 ... -
使用iBatis中报 java.sql.SQLException: 无效的列类型异常
2011-12-15 14:46 2244<!--Content表 插入应的 ... -
非常有用的proxool属性详细解说
2011-12-13 16:19 1612Proxool连接池是sourceforge下的一个开源项目, ... -
在工程中查找自己修改的所有代码
2011-12-09 17:41 1049在工程中查找自己修改的所有代码的方法: 1.工程右键 -&g ... -
如何在Eclipse中安装和使用ibatis插件Abator
2011-12-01 21:26 49761、获得abator: http://ibatis. ... -
newCachedThreadPool线程池
2011-11-20 11:35 43036public static ExecutorService n ... -
Apache Mina – 简单的客户端/服务端应用示例
2011-11-19 23:49 5530转自http://javasight.net/2011/05/ ... -
Class.forName()、Class.forName().newInstance() 、New 三者区别!
2011-11-15 09:18 1263终于明白为什么加载数据库驱动只用Class.forName() ...
相关推荐
Activiti5.6 用户手册
5. 表单(Form):与任务相关的用户界面,用于输入或展示数据。 三、实例解析 在"myactiviti"目录下,我们通常会看到以下关键文件: - myprocess.bpmn20.xml:流程定义文件,包含了流程图的所有信息。 - ...
Activiti 是一个开源的工作流和业务流程管理(BPM)引擎,它被广泛用于企业级应用中,以实现流程自动化和提升工作效率。标题提到的是 Activiti 的两个版本,5.6 和 5.8,这表明我们将探讨这两个版本的源代码。 在 ...
activiti5.6,想对activiti有所提高,进一步了解的朋友必备,对初学者也是必备文档
总结起来,Activiti 5.6与Spring 3.03的整合提供了一种高效的方式来建模和执行业务流程,如模拟程序员的面试过程。通过XML配置,我们可以定义复杂的流程逻辑,并结合Spring的特性进行灵活的控制和管理。这种整合使得...
Activiti 是一个开源的工作流和业务自动化引擎,广泛应用于企业级应用中,提供流程定义、执行、监控等全面的功能。本学习笔记将聚焦于流程执行的历史记录,这是理解流程运行情况、追踪问题以及优化流程的关键。 一...
Alfresco软件在2010年5月17日宣布Activiti业务流程管理(BPM)开源项目的正式启动,其首席架构师由业务流程管理BPM的专家 Tom Baeyens担任。 Activiti项目是一项新的基于Apache许可的开源BPM平台,从基础开始构建,...
这是一本深入讲解Activiti的书,这是一本干货书,不仅有源码的讲解,还有基于源码讲解基础之上的实战讲解,这是一本诚意十足的书,这是一本深入讲解Activiti内核的书,这是一本真正企业级实战的书。 Activiti权威...
activiti in action meap版 全本
Activiti 是一个开源的工作流和业务自动化引擎,它支持企业级的业务流程管理(BPM)系统和模型驱动的应用程序。这个"activiti流程图查看demo"是一个示例项目,旨在帮助用户理解如何在Activiti中查看和操作流程图。在...
总结,Activiti 的开始活动节点是流程的起点,而流程是否结束则需要通过查询流程实例和历史流程实例的状态来判断。理解并熟练掌握这些概念和操作,将有助于我们在实际项目中更有效地管理和优化业务流程。通过 ...
1. **Activiti Engine**: Activiti Engine 是 Activiti 的核心组件,负责执行流程定义,管理流程实例,以及处理与流程相关的各种任务。它提供了一个API,开发者可以通过这个API来启动流程实例,查询任务,完成任务等...
Activiti 是一个开源的工作流引擎,它用于自动化业务流程。在 Activiti 中,流程变量是流程实例中的数据载体,它们可以被流程中的不同任务、事件或服务调用所使用。理解并熟练操作流程变量是深入学习 Activiti 的...
Activiti 是一个开源的工作流和业务自动化引擎,它被广泛应用于企业级应用中,用于处理业务流程和工作流。这个“简单的activiti请假流程”项目是针对初学者或希望了解Activiti基本操作的一个实例,旨在展示如何在...
5.6:ProcessDefinition 14 5.7:ProcessInstance 14 5.8:Execution 14 6:HelloWorld程序(模拟流程的执行) 16 6.1:流程图: 16 6.2:部署流程定义 16 6.3:启动流程实例 17 6.4:查看我的个人任务 17 6.5:完成...
在企业级应用中,工作流管理系统(Workflow Management System, WMS)是不可或缺的一部分,它能够自动化业务流程,提高效率。Activiti 是一个流行的开源工作流引擎,它基于模型驱动的架构,提供了一套完整的工具来...
Activiti7是一款强大的开源工作流引擎,用于在Java应用程序中实现业务流程自动化。它基于模型驱动的架构,允许开发者通过BPMN 2.0标准来设计、部署和执行流程。这个“Activiti7(流程引擎)简单笔记”很可能是作者在...
Activiti 是一个开源的工作流和业务自动化引擎,广泛应用于企业级应用中,提供流程定义、流程实例管理、任务处理等功能。本学习笔记将深入探讨流程实例和任务执行这两个关键概念。 流程实例是 Activiti 中的一个...
工作流Activiti是一种开源的工作流引擎,用于在企业应用程序中实现业务流程自动化。它由Alfresco Software开发,旨在提供灵活、可扩展且易于使用的流程管理解决方案。在本"工作流Activiti学习代码"资源中,我们将...
理解并熟练掌握流程图的部署和查询是使用Activiti进行业务流程自动化开发的基础。 总之,Activiti流程图的部署和操作涉及到流程定义的生命周期管理,包括创建、部署、查询和更新等步骤。正确地部署和操作流程图能够...