当前位置:网站首页>Floating source code comment (38) parallel job processor
Floating source code comment (38) parallel job processor
2022-07-03 19:08:00 【jinyangjie0】
Flowable Source code address :https://github.com/flowable/flowable-engine
Flowable-6.7.2 Source code comment address :https://github.com/solojin/flowable-6.7.2-annotated
Package path :org.flowable.engine.impl.jobexecutor
ParallelMultiInstanceWithNoWaitStatesAsyncLeaveJobHandler Parallel multi instance asynchronous leave job processor without waiting state
/** * Parallel multi instance asynchronous leave job processor without waiting state * * @author Joram Barrez */
public class ParallelMultiInstanceWithNoWaitStatesAsyncLeaveJobHandler implements JobHandler {
public static final String TYPE = "parallel-multi-instance-no-waits-async-leave";
@Override
public String getType() {
return TYPE;
}
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
ExecutionEntityManager executionEntityManager = processEngineConfiguration.getExecutionEntityManager();
ExecutionEntity execution = executionEntityManager.findById(job.getExecutionId());
if (execution != null) {
FlowElement currentFlowElement = execution.getCurrentFlowElement();
if (currentFlowElement instanceof Activity) {
Object behavior = ((Activity) currentFlowElement).getBehavior();
if (behavior instanceof ParallelMultiInstanceBehavior) {
ParallelMultiInstanceBehavior parallelMultiInstanceBehavior = (ParallelMultiInstanceBehavior) behavior;
DelegateExecution multiInstanceRootExecution = ExecutionGraphUtil.getMultiInstanceRootExecution(execution);
if (multiInstanceRootExecution != null) {
// Optimize the activity count here : If there is still activity execution in the database , There is no need to do anything :
// No need to get any variables , If completed 、 Activities of the nr etc. .
// This work can be simply rearranged , And when things are not finished , It will try the same logic again .
long activeChildExecutionCount = executionEntityManager.countActiveExecutionsByParentId(multiInstanceRootExecution.getId());
if (activeChildExecutionCount > 0) {
List<String> boundaryEventActivityIds = ExecutionGraphUtil.getBoundaryEventActivityIds(multiInstanceRootExecution);
if (boundaryEventActivityIds.isEmpty()) {
reCreateJob(processEngineConfiguration, execution);
} else {
// If all remaining executions are boundary event executions , You can keep multiple instances .
List<ExecutionEntity> boundaryEventChildExecutions = executionEntityManager
.findExecutionsByParentExecutionAndActivityIds(multiInstanceRootExecution.getId(), boundaryEventActivityIds);
if (activeChildExecutionCount <= boundaryEventChildExecutions.size()) {
leaveMultiInstance(processEngineConfiguration, execution, parallelMultiInstanceBehavior);
} else {
reCreateJob(processEngineConfiguration, execution);
}
}
} else {
leaveMultiInstance(processEngineConfiguration, execution, parallelMultiInstanceBehavior);
}
}
}
}
}
}
protected void reCreateJob(ProcessEngineConfigurationImpl processEngineConfiguration, ExecutionEntity execution) {
// This is not a common way to create jobs , Because we especially don't want asynchronous actuators to trigger .
// This operation should extract , To avoid continuous circulation .
JobService jobService = processEngineConfiguration.getJobServiceConfiguration().getJobService();
JobEntity newJob = JobUtil.createJob(execution, TYPE, processEngineConfiguration);
jobService.createAsyncJobNoTriggerAsyncExecutor(newJob, true);
jobService.insertJob(newJob);
}
protected void leaveMultiInstance(ProcessEngineConfigurationImpl processEngineConfiguration, ExecutionEntity execution,
ParallelMultiInstanceBehavior parallelMultiInstanceBehavior) {
// ParallelMultiInstanceBehavior The implementation of considers sub execution .
// So choose random sub execution instead of passing multiple instance root execution
boolean multiInstanceCompleted = parallelMultiInstanceBehavior.leaveAsync(execution);
if (!multiInstanceCompleted) {
reCreateJob(processEngineConfiguration, execution);
}
}
}
ParallelMultiInstanceActivityCompletionJobHandler Parallel multi instance activity completion job processor
/** * Parallel multi instance activity completion job processor * * @author Filip Hrisafov */
public class ParallelMultiInstanceActivityCompletionJobHandler implements JobHandler {
public static final String TYPE = "parallel-multi-instance-complete";
@Override
public String getType() {
return TYPE;
}
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
ExecutionEntity completingExecution = processEngineConfiguration.getExecutionEntityManager().findById(job.getExecutionId());
if (completingExecution != null) {
// It is possible that the execution completed (through another thread). In that case we ignore it.
FlowElement currentFlowElement = completingExecution.getCurrentFlowElement();
if (currentFlowElement instanceof Activity) {
Object behavior = ((Activity) currentFlowElement).getBehavior();
if (behavior instanceof ParallelMultiInstanceBehavior) {
ParallelMultiInstanceBehavior parallelMultiInstanceBehavior = (ParallelMultiInstanceBehavior) behavior;
parallelMultiInstanceBehavior.leaveAsync(completingExecution);
}
}
}
}
}
边栏推荐
- [water quality prediction] water quality prediction based on MATLAB Fuzzy Neural Network [including Matlab source code 1923]
- Integrated easy to pay secondary domain name distribution system
- Scrapy爬虫框架
- Unity2018 to wechat games without pictures
- Understanding of database architecture
- 235. Ancêtre public le plus proche de l'arbre de recherche binaire [modèle LCA + même chemin de recherche]
- [leetcode weekly race] game 300 - 6110 Number of incremental paths in the grid graph - difficult
- SQL custom collation
- Common PostgreSQL commands
- Free hand account sharing in September - [cream Nebula]
猜你喜欢
[academic related] how to find the innovation of top papers? Chinese universities won the CVPR Best Student Thesis Award for the first time
我們做了一個智能零售結算平臺
Web3 credential network project galaxy is better than nym?
[proteus simulation] a simple encrypted electronic password lock designed with 24C04 and 1602LCD
平淡的生活里除了有扎破皮肤的刺,还有那些原本让你魂牵梦绕的诗与远方
Summary of composition materials for 2020 high-frequency examination center of educational resources
Day18 - basis of interface testing
KINGS
22.2.14 -- station B login with code -for circular list form - 'no attribute' - 'needs to be in path selenium screenshot deviation -crop clipping error -bytesio(), etc
Analysis of dart JSON encoder and decoder
随机推荐
FBI警告:有人利用AI换脸冒充他人身份进行远程面试
Analyse du Code du planificateur ego bspline Section Optimizer (1)
[new year job hopping season] test the technical summary of interviewers' favorite questions (with video tutorials and interview questions)
Latex image rotates with title
记录在模拟器中运行flutter时报的错
Differential constrained SPFA
Su embedded training - Day10
Recommend a simple browser tab
达梦数据库的物理备份和还原简解
组策略中开机脚本与登录脚本所使用的用户身份
Suffix derivation based on query object fields
Unity2018 to wechat games without pictures
Does SQL always report foreign key errors when creating tables?
Dart JSON编码器和解码器剖析
These problems should be paid attention to in the production of enterprise promotional videos
FBI warning: some people use AI to disguise themselves as others for remote interview
The more you talk, the more your stupidity will be exposed.
leetcode:11. 盛最多水的容器【双指针 + 贪心 + 去除最短板】
Change is the eternal theme
Counting from the East and counting from the West will stimulate 100 billion industries. Only storage manufacturers who dare to bite the "hard bone" will have more opportunities