Activiti5 定時任務 定時邊界事件

activiti定時邊界事件

Java代碼  收藏代碼
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <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">  
  3.   <process id="myProcess" name="My process" isExecutable="true">  
  4.     <startEvent id="startevent1" name="Start"></startEvent>  
  5.     <userTask id="usertask1" name="1" activiti:assignee="lingling"></userTask>  
  6.     <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>  
  7.     <boundaryEvent id="boundarytimer1" name="Timer" attachedToRef="usertask1" cancelActivity="false">  
  8.       <timerEventDefinition>  
  9.         <timeDuration>${timeDuration}</timeDuration>  
  10.       </timerEventDefinition>  
  11.     </boundaryEvent>  
  12.     <userTask id="usertask2" name="2" activiti:assignee="dongxh"></userTask>  
  13.     <sequenceFlow id="flow4" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>  
  14.     <endEvent id="endevent1" name="End"></endEvent>  
  15.     <sequenceFlow id="flow5" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>  
  16.     <boundaryEvent id="boundarytimer2" name="Timer" attachedToRef="usertask2" cancelActivity="false">  
  17.       <timerEventDefinition>  
  18.         <timeDuration>${timeDuration}</timeDuration>  
  19.       </timerEventDefinition>  
  20.     </boundaryEvent>  
  21.     <serviceTask id="servicetask1" name="Service Task" activiti:delegateExpression="${swTimeOutProcessorListener}"></serviceTask>  
  22.     <sequenceFlow id="flow6" sourceRef="boundarytimer1" targetRef="servicetask1"></sequenceFlow>  
  23.     <sequenceFlow id="flow7" sourceRef="boundarytimer2" targetRef="servicetask1"></sequenceFlow>  
  24.   </process>  
  25.   <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">  
  26.     <bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">  
  27.       <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">  
  28.         <omgdc:Bounds height="35.0" width="35.0" x="60.0" y="80.0"></omgdc:Bounds>  
  29.       </bpmndi:BPMNShape>  
  30.       <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">  
  31.         <omgdc:Bounds height="35.0" width="35.0" x="660.0" y="80.0"></omgdc:Bounds>  
  32.       </bpmndi:BPMNShape>  
  33.       <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">  
  34.         <omgdc:Bounds height="78.0" width="105.0" x="202.0" y="59.0"></omgdc:Bounds>  
  35.       </bpmndi:BPMNShape>  
  36.       <bpmndi:BPMNShape bpmnElement="boundarytimer1" id="BPMNShape_boundarytimer1">  
  37.         <omgdc:Bounds height="30.0" width="30.0" x="230.0" y="130.0"></omgdc:Bounds>  
  38.       </bpmndi:BPMNShape>  
  39.       <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">  
  40.         <omgdc:Bounds height="55.0" width="105.0" x="411.0" y="70.0"></omgdc:Bounds>  
  41.       </bpmndi:BPMNShape>  
  42.       <bpmndi:BPMNShape bpmnElement="boundarytimer2" id="BPMNShape_boundarytimer2">  
  43.         <omgdc:Bounds height="30.0" width="30.0" x="449.0" y="114.0"></omgdc:Bounds>  
  44.       </bpmndi:BPMNShape>  
  45.       <bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">  
  46.         <omgdc:Bounds height="55.0" width="105.0" x="317.0" y="240.0"></omgdc:Bounds>  
  47.       </bpmndi:BPMNShape>  
  48.       <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">  
  49.         <omgdi:waypoint x="95.0" y="97.0"></omgdi:waypoint>  
  50.         <omgdi:waypoint x="202.0" y="98.0"></omgdi:waypoint>  
  51.       </bpmndi:BPMNEdge>  
  52.       <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">  
  53.         <omgdi:waypoint x="307.0" y="98.0"></omgdi:waypoint>  
  54.         <omgdi:waypoint x="411.0" y="97.0"></omgdi:waypoint>  
  55.       </bpmndi:BPMNEdge>  
  56.       <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">  
  57.         <omgdi:waypoint x="516.0" y="97.0"></omgdi:waypoint>  
  58.         <omgdi:waypoint x="660.0" y="97.0"></omgdi:waypoint>  
  59.       </bpmndi:BPMNEdge>  
  60.       <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">  
  61.         <omgdi:waypoint x="245.0" y="160.0"></omgdi:waypoint>  
  62.         <omgdi:waypoint x="369.0" y="240.0"></omgdi:waypoint>  
  63.       </bpmndi:BPMNEdge>  
  64.       <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">  
  65.         <omgdi:waypoint x="464.0" y="144.0"></omgdi:waypoint>  
  66.         <omgdi:waypoint x="369.0" y="240.0"></omgdi:waypoint>  
  67.       </bpmndi:BPMNEdge>  
  68.     </bpmndi:BPMNPlane>  
  69.   </bpmndi:BPMNDiagram>  
  70. </definitions>  

 流程圖:

 

 

 

 

serviceTask處理:

 

Java代碼  收藏代碼
  1. @Component  
  2. public class SwTimeOutProcessorListener implements JavaDelegate {  
  3.   
  4.     @Autowired  
  5.     private TimeOutManagerService timeOutManagerService;  
  6.     @Autowired  
  7.     private TaskService taskService;  
  8.       
  9.     @Override  
  10.     public void execute(DelegateExecution execution) throws Exception {  
  11.         //獲得事務id  
  12.         String businessKey = execution.getProcessBusinessKey();  
  13.         Task task = taskService.createTaskQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();  
  14.         String assignee =task.getAssignee();  
  15.           
  16.         System.out.println(assignee);  
  17.           
  18.         //插入超時記錄  
  19.         //timeOutManagerService.addTimeOut(Integer.valueOf(assignee), Integer.valueOf(businessKey));  
  20.           
  21.           
  22.     }  
  23.   
  24. }  

 

 

定時邊間事件:cancelActivity 說明:

cancelActivity屬性:true時,當timer觸發時,當前的activity被中斷(流程結束);

                                false時,當timer觸發時,不會被中斷(流程原點,流程不會結束),

 

當執行循環定時器時,雖然cancelActivity=true,但是該acitivity還是會持續生成

 

cancelActivity默認爲true中斷事件(結束流程)

cancelActivity爲false非中斷事件(還停留在原地,流程不結束)

中斷和非中斷的事件還是有區別的。默認是中斷事件。

非中斷事件的情況,不會中斷原始環節,那個環節還停留在原地。 對應的,會創建一個新分支,並沿着事件的流向繼續執行。 

 

例子:



 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章