JBPM-其他节点

(一) decision  其实就是判断节点  目的 改善代码结构


<?xml version="1.0" encoding="UTF-8"?>

<process name="decision" xmlns="http://jbpm.org/4.4/jpdl">
   <start g="314,26,48,48" name="start1">
      <transition g="-53,-17" name="to task1" to="task1"/>
   </start>
   <end g="283,386,48,48" name="end1"/>
   <task g="185,107,92,52" name="task1">
      <transition g="26,-23" name="to task2" to="task2"/>
   </task>
   <task g="267,176,104,58" name="task2">
      <transition g="-103,-13" name="to exclusive1" to="exclusive1"/>
   </task>
   <task g="465,261,92,52" name="task3">
      <transition g="29,-9" name="to end1" to="end1"/>
   </task>
   <decision g="350,267,48,48" name="exclusive1">
   	  <handler class="cn.itcast.jbpm0909.decision.MyHandler" />
      <transition g="-9,-40" name="to task3" to="task3"/>
      <transition g="-47,-17" name="to end1" to="end1"/>
   </decision>
</process>

public class MyHandler implements DecisionHandler{

	@Override
	public String decide(OpenExecution execution) {
		// TODO Auto-generated method stub
		int days = (Integer)execution.getVariable("请假天数");
		if(days<=3){
			return "to end1";
		}else{
			return "to task3";
		}
	}
	
}

public class DecisionTest extends BaseJbpm{
	@Test
	public void testDeploy(){
		processEngine.getRepositoryService()
		.createDeployment()
		.addResourceFromClasspath("cn/itcast/jbpm0909/decision/decision.jpdl.xml")
		.deploy();
	}
	
	@Test
	public void testStartPI(){
		processEngine.getExecutionService()
		.startProcessInstanceById("decision-1");
	}
	
	@Test
	public void testFinishTask(){
//		Map<String, Integer> variables = new HashMap<String, Integer>();
//		variables.put("请假天数", 2);
//		processEngine.getTaskService().setVariables("410002", variables);
		processEngine.getTaskService()
		.completeTask("420002");
	}
}

(二) event



<?xml version="1.0" encoding="UTF-8"?>

<process name="event" xmlns="http://jbpm.org/4.4/jpdl">
	<!-- 
		流程级别的开始事件
	 -->
	<on event="start">
		<event-listener class="c.event.ProcessStartEvent"></event-listener>
	</on>
	
	<!-- 
		流程级别的结束事件
	 -->
	<on event="end">
		<event-listener class="c.event.ProcessEndEvent"></event-listener>
	</on>
   <start name="start1" g="257,59,48,48"> <!--   开始节点的结束事件 -->
   	  <on event="end">
   	  	<event-listener class="cStartNodeEndEvent"></event-listener>
   	  </on>
      <transition name="to task1" to="task1" g="-53,-17"/>
   </start>
   <end name="end1" g="276,330,48,48"> <!--   开始节点的结束事件 -->
   	<on event="start">
   		<event-listener class="c.EndNodeStartEvent"></event-listener>
   	</on>
   </end>
   <task name="task1" g="225,177,92,52">
   	  <on event="start">
			<!--  一般节点的开始事件 -->


<event-listener class="c.NodeStartEvent"></event-listener> </on> <on event="end">
			<!--  一般节点的结束事件 -->
<event-listener class="c.NodeEndEvent"></event-listener> </on> <transition name="to end1" to="end1" g="-47,-17"/> </task></process>


public class ProcessStartEvent implements EventListener{

	@Override
	public void notify(EventListenerExecution execution) throws Exception {
		
		System.out.println("process start event");
	}

}

@Override
	public void notify(EventListenerExecution execution) throws Exception {
		
		System.out.println("process end event");
	}
public class StartNodeEndEvent implements EventListener{

	@Override
	public void notify(EventListenerExecution execution) throws Exception {
		System.out.println("start node end event");
	}

}

public class EndNodeStartEvent implements EventListener{

	@Override
	public void notify(EventListenerExecution execution) throws Exception {
		System.out.println("end node start event");
	}

}

public class NodeStartEvent implements EventListener{

	@Override
	public void notify(EventListenerExecution execution) throws Exception {
		System.out.println("node start event");
	}

}

public class NodeEndEvent implements EventListener{

	@Override
	public void notify(EventListenerExecution execution) throws Exception {
		System.out.println("node end event");
	}

}


/**
 * event和decision的发明就是为了达到代码的松耦合
 *   把流程的控制逻辑和流程的业务逻辑分离
 * @author Administrator
 *
 */
public class EventTest extends BaseJbpm{
	@Test
	public void testDeploy(){
		processEngine.getRepositoryService()
		.createDeployment()
		.addResourceFromClasspath("cn/itcast/jbpm0909/event/event.jpdl.xml")
		.deploy();
	}
	
	@Test
	public void testStartPI(){
		processEngine.getExecutionService()
		.startProcessInstanceById("event-1");
	}
	
	@Test
	public void testFinishTask(){
		processEngine.getTaskService()
		.completeTask("450002");
	}
}


(三)fock和join(并发执行的)



<?xml version="1.0" encoding="UTF-8"?>

<process name="forkjoin" xmlns="http://jbpm.org/4.4/jpdl">
   <start name="start1" g="270,8,48,48">
      <transition name="to fork1" to="fork1" g="-53,-17"/>
   </start>
   <end name="end1" g="276,404,48,48"/>
   <task name="task1" g="129,137,92,52" assignee="张三">
      <transition name="to task3" to="task3" g="-53,-17"/>
   </task>
   <task name="task2" g="366,146,92,52" assignee="干露露">
      <transition name="to task4" to="task4" g="-53,-17"/>
   </task>
   <task name="task3" g="106,275,92,52" assignee="干露露">
      <transition name="to join1" to="join1" g="-74,6"/>
   </task>
   <task name="task4" g="391,292,92,52" assignee="张三">
      <transition name="to join1" to="join1" g="3,11"/>
   </task>
   <fork name="fork1" g="273,95,48,48">
      <transition name="to task1" to="task1" g="-53,-17"/>
      <transition name="to task2" to="task2" g="9,-19"/>
   </fork>
   <join name="join1" g="293,326,48,48">
      <transition name="to end1" to="end1" g="-47,-17"/>
   </join>
</process>


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值