轻量级前端框架助力开发者提升项目效率与性能
903
2022-10-16
Activiti 流程启动及节点流转源码分析
作者:jiankunking
本文主要是以activiti-study中的xiaomage.xml流程图为例进行跟踪分析
具体的流程图如下:
流程图对应的XML文件如下:
流程启动跟踪分析:
图一:
图二:
图三:
图四:
以上主要是跟踪分析了,三个节点之间的流转情况。
在流转的时候需要注意以下两个接口:
原子操作(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
注意:
void
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
注意:
void
单独摘出来的两个方法是图一中:
上下文、原子操作、执行器实体三者相互调用的关键。
上图的具体调用情况如下:
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
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
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~