工作流系列–agenda引擎计划分析
先看下源码注释
可以理解成agenda是一个线程池,命令执行前会赛一系列的任务Operation进去,然后执行. 当池中任务没有了则结束.
每个Operation任务都是一个 Runnable 类型的对象,值得深究为什么不是其他的类型, 可能为了后续线程做并发处理设计的
上一篇章讲了命令执行类CommandInvoker主要做了3件事情
1、要执行的命令加入命令链表;
2、循环弹出并且启动执行链表里的所有待执行的线程操作;
3、若当前命令或者流转操作上下文有参与执行的执行对象,则进行执行
4、返回命令执行结果
详细可查看: [后续补充链接]
agenda做为引擎流转的核心类,驱动任务流转,提供了很多接口
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 @Internal public interface ActivitiEngineAgenda extends Agenda { void planContinueProcessOperation (ExecutionEntity execution ) ; void planContinueProcessSynchronousOperation (ExecutionEntity execution ) ; void planContinueProcessInCompensation (ExecutionEntity execution ) ; void planContinueMultiInstanceOperation (ExecutionEntity execution ) ; void planTakeOutgoingSequenceFlowsOperation (ExecutionEntity execution , boolean evaluateConditions) ; void planEndExecutionOperation (ExecutionEntity execution ) ; void planTriggerExecutionOperation (ExecutionEntity execution ) ; void planDestroyScopeOperation (ExecutionEntity execution ) ; void planExecuteInactiveBehaviorsOperation () ; } ActivitiEngineAgenda的默认实现类类设计到以下相关的流转类 ContinueProcessOperation ContinueMultiInstanceOperation TakeOutgoingSequenceFlowsOperation EndExecutionOperation TriggerExecutionOperation DestroyScopeOperation ExecuteInactiveBehaviorsOperation (以上类都继承类AbstractOperation并且实现了runnable接口)
ActivitiEngineAgenda 默认实现类,源码如下, 关键部分, 其余部分都是讲操作命令加入执行链遍, 该类主要负责维护命令实际的线程任务集合和将命令上下文执行实例加入集合。
agenda控制做什么流转,上面说的流转类做具体的流转事项, 就好比如完成任务的命令操作最后, 细心的小伙伴可能关注到,完成任务源码里面最后一步就是通过agenda触发planTriggerExecutionOperation行为, planTriggerExecutionOperation具体请看下集分析
1 2 3 4 5 if (taskEntity.getExecutionId() != null ) { ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findById(taskEntity.getExecutionId()); Context.getAgenda().planTriggerExecutionOperation(executionEntity); }
如果您喜欢此博客或发现它对您有用,则欢迎对此发表评论。 也欢迎您共享此博客,以便更多人可以参与。 如果博客中使用的图像侵犯了您的版权,请与作者联系以将其删除。 谢谢 !