Activiti 流程啟動及節點流轉原始碼分析
作者:jiankunking 出處:http://blog.csdn.net/jiankunking
本文主要是以activiti-study中的xiaomage.xml流程圖為例進行跟蹤分析
具體的流程圖如下:
流程圖對應的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="MyProcess" name="MyProcess">
<documentation>Place documentation for the 'MyProcess' process here.</documentation>
<startEvent id="startevent1" name="Start"/>
<userTask id="sss" name="ddd" activiti:assignee="fq"/>
<sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="sss"/>
<endEvent id="endevent1" name="End"/>
<sequenceFlow id="flow2" name="" sourceRef="sss" targetRef="endevent1"/>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_MyProcess">
<bpmndi:BPMNPlane bpmnElement="MyProcess" id="BPMNPlane_MyProcess">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35" width="35" x="340" y="150"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sss" id="BPMNShape_sss">
<omgdc:Bounds height="55" width="105" x="305" y="250"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35" width="35" x="340" y="370"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="357" y="185"/>
<omgdi:waypoint x="357" y="250"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="357" y="305"/>
<omgdi:waypoint x="357" y="370"/>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
流程例項建立過程如下(下圖轉載自:activiti 原始碼筆記之startProcess):
流程啟動跟蹤分析:
圖一:
圖二:
圖三:
圖四:
以上主要是跟蹤分析了,三個節點之間的流轉情況。
在流轉的時候需要注意以下兩個介面:
原子操作(AtomicOperation)介面:
public interface AtomicOperation {
AtomicOperation PROCESS_START = new AtomicOperationProcessStart();
AtomicOperation PROCESS_START_INITIAL = new AtomicOperationProcessStartInitial();
AtomicOperation PROCESS_END = new AtomicOperationProcessEnd();
AtomicOperation ACTIVITY_START = new AtomicOperationActivityStart();
AtomicOperation ACTIVITY_EXECUTE = new AtomicOperationActivityExecute();
AtomicOperation ACTIVITY_END = new AtomicOperationActivityEnd();
AtomicOperation TRANSITION_NOTIFY_LISTENER_END = new AtomicOperationTransitionNotifyListenerEnd();
AtomicOperation TRANSITION_DESTROY_SCOPE = new AtomicOperationTransitionDestroyScope();
AtomicOperation TRANSITION_NOTIFY_LISTENER_TAKE = new AtomicOperationTransitionNotifyListenerTake();
AtomicOperation TRANSITION_CREATE_SCOPE = new AtomicOperationTransitionCreateScope();
AtomicOperation TRANSITION_NOTIFY_LISTENER_START = new AtomicOperationTransitionNotifyListenerStart();
AtomicOperation DELETE_CASCADE = new AtomicOperationDeleteCascade();
AtomicOperation DELETE_CASCADE_FIRE_ACTIVITY_END = new AtomicOperationDeleteCascadeFireActivityEnd();
void execute(InterpretableExecution execution);
boolean isAsync(InterpretableExecution execution);
}
注意:
void execute(InterpretableExecution execution);
InterpretableExecution介面:
public interface InterpretableExecution extends ActivityExecution, ExecutionListenerExecution, PvmProcessInstance {
void take(PvmTransition transition);
void take(PvmTransition transition, boolean fireActivityCompletedEvent);
void setEventName(String eventName);
void setEventSource(PvmProcessElement element);
Integer getExecutionListenerIndex();
void setExecutionListenerIndex(Integer executionListenerIndex);
ProcessDefinitionImpl getProcessDefinition();
void setActivity(ActivityImpl activity);
void performOperation(AtomicOperation etomicOperation);
boolean isScope();
void destroy();
void remove();
InterpretableExecution getReplacedBy();
void setReplacedBy(InterpretableExecution replacedBy);
InterpretableExecution getSubProcessInstance();
void setSubProcessInstance(InterpretableExecution subProcessInstance);
InterpretableExecution getSuperExecution();
void deleteCascade(String deleteReason);
boolean isDeleteRoot();
TransitionImpl getTransition();
void setTransition(TransitionImpl object);
void initialize();
void setParent(InterpretableExecution parent);
void setProcessDefinition(ProcessDefinitionImpl processDefinitionImpl);
void setProcessInstance(InterpretableExecution processInstance);
boolean isEventScope();
void setEventScope(boolean isEventScope);
StartingExecution getStartingExecution();
void disposeStartingExecution();
}
注意:
void performOperation(AtomicOperation etomicOperation);
單獨摘出來的兩個方法是圖一中:
上下文、原子操作、執行器實體三者相互呼叫的關鍵。
上圖的具體呼叫情況如下:
ExecutionEntity類中的:
public void performOperation(AtomicOperation executionOperation) {
if (executionOperation.isAsync(this)) {
scheduleAtomicOperationAsync(executionOperation);
} else {
performOperationSync(executionOperation);
}
}
protected void performOperationSync(AtomicOperation executionOperation) {
Context
.getCommandContext()
.performOperation(executionOperation, this);
}
performOperation函式中呼叫上下文CommandContext類中的:
public void performOperation(AtomicOperation executionOperation, InterpretableExecution execution) {
nextOperations.add(executionOperation);
if (nextOperations.size()==1) {
try {
Context.setExecutionContext(execution);
while (!nextOperations.isEmpty()) {
AtomicOperation currentOperation = nextOperations.removeFirst();
if (log.isTraceEnabled()) {
log.trace("AtomicOperation: {} on {}", currentOperation, this);
}
if (execution.getReplacedBy() == null) {
currentOperation.execute(execution);
} else {
currentOperation.execute(execution.getReplacedBy());
}
}
} finally {
Context.removeExecutionContext();
}
}
}
performOperation函式呼叫原子操作(AtomicOperation)介面中的void execute(InterpretableExecution execution)來處理。
該處的處理分為兩種情況:
1、根據AtomicOperation介面標識來繼續進行流轉
(再次呼叫ExecutionEntity類中的performOperation(AtomicOperation executionOperation)方法)
比如:
PROCESS_START=》PROCESS_START_INITIAL=》ACTIVITY_EXECUTE。。。。。。
具體可以參考本文圖一到圖四的程式碼跟蹤中的標識。
2、根據節點上的ActivityBehavior類進行不同的處理
Activiti節點(開始、結束、任務、閘道器等等)都是Activity型別的,只是其掛的ActivityBehavior不同,通過不同的ActivityBehavior來實現相應的操作。
作者:jiankunking 出處:http://blog.csdn.net/jiankunking
相關文章
- Netty啟動流程及原始碼分析Netty原始碼
- Tomcat原始碼分析--啟動流程Tomcat原始碼
- Flutter啟動流程原始碼分析Flutter原始碼
- Activity啟動流程原始碼分析原始碼
- apiserver原始碼分析——啟動流程APIServer原始碼
- Activiti5.2 自動完成第一節點流程
- Android Activity啟動流程原始碼分析Android原始碼
- Android原始碼分析:Activity啟動流程Android原始碼
- containerd 原始碼分析:啟動註冊流程AI原始碼
- Apache Flink原始碼分析---JobManager啟動流程Apache原始碼
- Activiti 學習(三)—— Activiti 流程啟動並完成
- 以太坊原始碼分析(39)geth啟動流程分析原始碼
- Android系統原始碼分析--Service啟動流程Android原始碼
- Android系統原始碼分析–Service啟動流程Android原始碼
- Sharding-JDBC 原始碼之啟動流程分析JDBC原始碼
- SpringBoot2 | SpringBoot啟動流程原始碼分析(一)Spring Boot原始碼
- Scrapy原始碼閱讀分析_2_啟動流程原始碼
- Android 系統原始碼-1:Android 系統啟動流程原始碼分析Android原始碼
- [原始碼解析] PyTorch 分散式之彈性訓練(2)---啟動&單節點流程原始碼PyTorch分散式
- Java Activiti 工作流引擎 springmvc SSM 流程審批 後臺框架原始碼JavaSpringMVCSSM框架原始碼
- 玩轉Elasticsearch原始碼-一圖看懂ES啟動流程Elasticsearch原始碼
- SpringBoot一站式啟動流程原始碼分析Spring Boot原始碼
- SpringMVC執行流程及原始碼分析SpringMVC原始碼
- SpringBoot原始碼學習4——SpringBoot內嵌Tomcat啟動流程原始碼分析Spring Boot原始碼Tomcat
- NioEventLoop啟動流程原始碼解析OOP原始碼
- 【zookeeper原始碼】啟動流程詳解原始碼
- SpringBoot原始碼解析-啟動流程(二)Spring Boot原始碼
- SpringBoot原始碼解析-啟動流程(一)Spring Boot原始碼
- Spring原始碼解析02:Spring IOC容器之XmlBeanFactory啟動流程分析和原始碼解析Spring原始碼XMLBean
- SpringBoot配置外部Tomcat專案啟動流程原始碼分析(長文)Spring BootTomcat原始碼
- DRF檢視的使用及原始碼流程分析原始碼
- nodejs啟動流程分析NodeJS
- FlutterApp啟動流程分析FlutterAPP
- Activity啟動流程分析
- Unbound啟動流程分析
- Spring IOC 容器預啟動流程原始碼探析Spring原始碼
- hadoop原始碼_hdfs啟動流程_2_DataNodeHadoop原始碼
- SpringBoot原始碼學習3——SpringBoot啟動流程Spring Boot原始碼
- Activity 啟動流程學習總結(附原始碼流程圖)原始碼流程圖