linux怎么查看本机内存大小
463
2022-09-07
Jbpm4.3 学习笔记一
Jbpm4.3 学习笔记(一)
1. jbpm创建数据库
package com.langsi.jbpm;
import org.jbpm.api.Configuration; import org.jbpm.api.ProcessEngine;
public class Test1 { /** * 创建JBPM数据库表 */ public static void main(String[] args) {
Configuration configuration = new Configuration(); //创建流程引擎 @SuppressWarnings("unused") ProcessEngine processEngine = configuration.buildProcessEngine(); }
} |
2. 流程一first.jpdl.xml
2.1 流程定义文件
<?xml version="1.0" encoding="UTF-8"?> <process name="first" xmlns="data-id="p838747a-7BIER7kw"> <start g="222,38,48,48" name="start1"> <transition g="-59,-17" name="to state1" to="state1"/> </start> <state g="197,174,92,52" name="state1"> <transition name="to end1" to="end1" g="-47,-17"/> </state> <end g="220,350,48,48" name="end1"/> </process> |
2.2 流程图first.png
2.3 部署程序
package com.langsi.jbpm;
import org.jbpm.api.Configuration; import org.jbpm.api.NewDeployment; import org.jbpm.api.ProcessEngine; import org.jbpm.api.RepositoryService;
public class Test2 {
/** * 完成流程的部署功能 */ public static void main(String[] args) { //1、创建JBPM配置对象 Configuration configuration = new Configuration(); //2、创建流程引擎 ProcessEngine processEngine = configuration.buildProcessEngine(); //3、获得数据仓库服务对象 RepositoryService repositoryService = processEngine.getRepositoryService(); //4、创建部署实例对象 NewDeployment newDeployment = repositoryService.createDeployment(); //5、从类路径下面增加流程部署文件到部署实例对象 newDeployment = newDeployment.addResourceFromClasspath("first.jpdl.xml"); //6完成流程的部署 String processNameString = newDeployment.deploy(); System.out.println(processNameString); } } |
2.4 获取流程定义
package com.langsi.jbpm;
import java.util.Iterator; import java.util.List;
import org.jbpm.api.Configuration; import org.jbpm.api.NewDeployment; import org.jbpm.api.ProcessDefinition; import org.jbpm.api.ProcessEngine; import org.jbpm.api.RepositoryService;
public class Test3 { /** * 完成流程的执行 */ public static void main(String[] args) { // 1、创建JBPM配置对象 Configuration configuration = new Configuration(); // 2、创建流程引擎 ProcessEngine processEngine = configuration.buildProcessEngine(); // 3、获得数据仓库服务对象 RepositoryService repositoryService = processEngine .getRepositoryService(); // 4、创建部署实例对象 NewDeployment newDeployment = repositoryService.createDeployment(); // 5、从类路径下面增加流程部署文件到部署实例对象 newDeployment = newDeployment .addResourceFromClasspath("first.jpdl.xml"); // 6完成流程的部署 newDeployment.deploy(); //7由RepositoryService创建流程定义查询接口 List<ProcessDefinition> list = repositoryService .createProcessDefinitionQuery().list(); for (Iterator<ProcessDefinition> iterator = list.iterator(); iterator.hasNext();) { ProcessDefinition processDefinition = (ProcessDefinition) iterator .next(); System.out.println(processDefinition.getDeploymentId()+"---" +processDefinition.getId()+"---"+processDefinition.getName()); } } } |
2.5 流程开始执行
package com.langsi.jbpm;
import org.jbpm.api.Configuration; import org.jbpm.api.ExecutionService; import org.jbpm.api.ProcessEngine; import org.jbpm.api.ProcessInstance;
public class Test4 { public static void main(String[] args) { // 1、创建JBPM配置对象 Configuration configuration = new Configuration(); // 2、创建流程引擎 ProcessEngine processEngine = configuration.buildProcessEngine(); //3、获得流程执行服务对象 ExecutionService executionService = processEngine.getExecutionService(); //4、流程执行服务对象根据流程定义执行,获得流程实例 ProcessInstance processInstance = executionService.startProcessInstanceByKey("first"); System.out.println("processInstance Id " +processInstance.getId()); } } |
2.6 流程执行下一步
package com.langsi.jbpm; import org.jbpm.api.Configuration; import org.jbpm.api.ExecutionService; import org.jbpm.api.NewDeployment; import org.jbpm.api.ProcessEngine; import org.jbpm.api.ProcessInstance; import org.jbpm.api.RepositoryService;
public class Test5 { public static void main(String[] args) { //1、创建JBPM配置对象 Configuration configuration = new Configuration(); //2、创建流程引擎 ProcessEngine processEngine = configuration.buildProcessEngine(); //3、获得数据仓库服务对象 RepositoryService repositoryService = processEngine.getRepositoryService(); //4、创建部署实例对象 NewDeployment newDeployment = repositoryService.createDeployment(); //5、从类路径下面增加流程部署文件到部署实例对象 newDeployment = newDeployment.addResourceFromClasspath("first.jpdl.xml"); //6完成流程的部署 newDeployment.deploy(); //7、获得流程执行服务对象 ExecutionService executionService = processEngine.getExecutionService(); //8、流程执行服务对象根据流程定义执行,得到流程实例 ProcessInstance processInstance = executionService.startProcessInstanceByKey("first"); //9、使用流程执行服务对象触发流程实例往下一节点走,产生一个新的流程实例对象 ProcessInstance processInstance2 = executionService.signalExecutionById(processInstance.getId()); System.out.println(processInstance2.isEnded()); } } |
3.secondprocess.jpdl.xml 第二个流程
3.1 流程定义文件secondprocess.jpdl.xml
<?xml version="1.0" encoding="UTF-8"?> <process name="secondprocess" xmlns="data-id="p838747a-hFiEslPs"> <start name="start1" g="272,38,48,48"> <transition name="to state1" to="state1" g="-59,-17"/> </start> <state name="state1" g="419,90,92,52"> <transition name="to state2" to="state2" g="-59,-17"/> </state> <state name="state2" g="526,202,92,52"> <transition name="to state3" to="state3" g="-59,-17"/> </state> <state name="state3" g="440,355,92,52"> <transition name="to end1" to="end1" g="-47,-17"/> </state> <end name="end1" g="339,428,48,48"/> </process> |
3.2 流程图
3.3 流程测试
package com.langsi.jbpm; import org.jbpm.api.Configuration; import org.jbpm.api.ExecutionService; import org.jbpm.api.NewDeployment; import org.jbpm.api.ProcessEngine; import org.jbpm.api.ProcessInstance; import org.jbpm.api.RepositoryService;
public class Test6 { public static void main(String[] args) { //1、创建JBPM配置对象 Configuration configuration = new Configuration(); //2、创建流程引擎 ProcessEngine processEngine = configuration.buildProcessEngine(); //3、获得数据仓库服务对象 RepositoryService repositoryService = processEngine.getRepositoryService(); //4、创建部署实例对象 NewDeployment newDeployment = repositoryService.createDeployment(); //5、从类路径下面增加流程部署文件到部署实例对象 newDeployment = newDeployment.addResourceFromClasspath("secondprocess.jpdl.xml"); //6完成流程的部署 newDeployment.deploy(); //7、获得流程执行服务对象 ExecutionService executionService = processEngine.getExecutionService(); //8、流程执行服务对象根据流程定义执行,得到流程实例 ProcessInstance processInstance = executionService.startProcessInstanceByKey("secondprocess"); //9、使用流程执行服务对象触发流程实例往下一节点走,产生一个新的流程实例对象 processInstance = executionService.signalExecutionById(processInstance.getId()); processInstance = executionService.signalExecutionById(processInstance.getId()); processInstance = executionService.signalExecutionById(processInstance.getId()); System.out.println(processInstance.isEnded()); } } |
3.4 删除流程
package com.langsi.jbpm;
import org.jbpm.api.Configuration; import org.jbpm.api.ExecutionService; import org.jbpm.api.NewDeployment; import org.jbpm.api.ProcessEngine; import org.jbpm.api.ProcessInstance; import org.jbpm.api.RepositoryService;
public class Test7 { /** * 流程实例的删除 * @param args */ public static void main(String[] args) { //1、创建JBPM配置对象 Configuration configuration = new Configuration(); //2、创建流程引擎 ProcessEngine processEngine = configuration.buildProcessEngine(); //3、获得数据仓库服务对象 RepositoryService repositoryService = processEngine.getRepositoryService(); //4、创建部署实例对象 NewDeployment newDeployment = repositoryService.createDeployment(); //5、从类路径下面增加流程部署文件到部署实例对象 newDeployment = newDeployment.addResourceFromClasspath("secondprocess.jpdl.xml"); //6完成流程的部署 newDeployment.deploy(); //7、获得流程执行服务对象 ExecutionService executionService = processEngine.getExecutionService(); //8、流程执行服务对象根据流程定义执行,得到流程实例 ProcessInstance processInstance = executionService.startProcessInstanceByKey("secondprocess"); //删除流程实例对象 executionService.deleteProcessInstance(processInstance.getId()); } } |
4. 第三个流程thirdprocess.jpdl.xml
4.1 流程定义
<?xml version="1.0" encoding="UTF-8"?> <process name="thirdprocess" xmlns="data-id="p838747a-Kd0660eP"> <start name="start1" g="332,116,48,48"> <transition name="to state1" to="state1" g="-59,-17"/> </start> <end name="end1" g="333,364,48,48"/> <state name="state1" g="456,265,92,52"> <on event="start"> <event-listener class="com.langsi.event.MyEventListener"/> </on> <on event="end"> <event-listener class="com.langsi.event.MyEventListener"/> </on> <transition name="to end1" to="end1" g="-47,-17"/> </state> </process> |
4.2 流程图
4.3 相关事件
package com.langsi.event; import org.jbpm.api.listener.EventListener; import org.jbpm.api.listener.EventListenerExecution;
@SuppressWarnings("serial") public class MyEventListener implements EventListener { @Override public void notify(EventListenerExecution execution) throws Exception { System.out.println("-------------------------------------"+execution.getId()); } } |
4.4 测试流程
package com.langsi.jbpm; import org.jbpm.api.Configuration; import org.jbpm.api.ExecutionService; import org.jbpm.api.NewDeployment; import org.jbpm.api.ProcessEngine; import org.jbpm.api.ProcessInstance; import org.jbpm.api.RepositoryService;
public class Test8 { /** * 增加事件 * @param args */ public static void main(String[] args) { //1、创建JBPM配置对象 Configuration configuration = new Configuration(); //2、创建流程引擎 ProcessEngine processEngine = configuration.buildProcessEngine(); //3、获得数据仓库服务对象 RepositoryService repositoryService = processEngine.getRepositoryService(); //4、创建部署实例对象 NewDeployment newDeployment = repositoryService.createDeployment(); //5、从类路径下面增加流程部署文件到部署实例对象 newDeployment = newDeployment.addResourceFromClasspath("thirdprocess.jpdl.xml"); //6完成流程的部署 newDeployment.deploy(); //7、获得流程执行服务对象 ExecutionService executionService = processEngine.getExecutionService(); //8、流程执行服务对象根据流程定义执行,得到流程实例 ProcessInstance processInstance = executionService.startProcessInstanceByKey("thirdprocess"); executionService.signalExecutionById(processInstance.getId()); } } |
5. 流程四fourthprocess.jpdl.xml
5.1 定义文件
<?xml version="1.0" encoding="UTF-8"?>
<process name="fourthprocess" xmlns="data-id="p838747a-yfHVuDxO"> <start name="start1" g="242,62,48,48"> <transition name="to task1" to="task1" g="-53,-17"/> </start> <end name="end1" g="246,393,48,48"/> <task name="task1" g="237,220,92,52" assignee="zhangsan"> <transition name="to end1" to="end1" g="-47,-17"/> </task>
</process> |
5.2 流程图
5.3 测试流程
package com.langsi.jbpm;
import java.util.List;
import org.jbpm.api.Configuration; import org.jbpm.api.ExecutionService; import org.jbpm.api.NewDeployment; import org.jbpm.api.ProcessEngine; import org.jbpm.api.ProcessInstance; import org.jbpm.api.RepositoryService; import org.jbpm.api.TaskService; import org.jbpm.api.task.Task;
//任务与事件 public class Test9 {
public static void main(String[] args) {
//1、创建JBPM配置对象 Configuration configuration = new Configuration(); //2、创建流程引擎 ProcessEngine processEngine = configuration.buildProcessEngine(); //3、获得数据仓库服务对象 RepositoryService repositoryService = processEngine.getRepositoryService(); //4、创建部署实例对象 NewDeployment newDeployment = repositoryService.createDeployment(); //5、从类路径下面增加流程部署文件到部署实例对象 newDeployment = newDeployment.addResourceFromClasspath("fourthprocess.jpdl.xml"); //6完成流程的部署 newDeployment.deploy(); //7、获得流程执行服务对象 ExecutionService executionService = processEngine.getExecutionService(); //8、流程执行服务对象根据流程定义执行,得到流程实例 ProcessInstance processInstance = executionService.startProcessInstanceByKey("fourthprocess");
System.out.println(processInstance.findActiveActivityNames());
// 得到任务处理服务对象 TaskService taskService = processEngine.getTaskService(); List<Task> tasks = taskService.findPersonalTasks("zhangsan"); System.out.println(tasks.size());
//完成任务实例,taskService.completeTask(taskId) Task task = tasks.iterator().next(); taskService.completeTask(task.getId()); } } |
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~