当前位置:网站首页>Comments on flowable source code (XXXV) timer activation process definition processor, process instance migration job processor
Comments on flowable source code (XXXV) timer activation process definition processor, process instance migration job processor
2022-07-06 01:35: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
TimerActivateProcessDefinitionHandler Timer activation process definition processor
/** * Timer activation process definition processor * * @author Joram Barrez */
public class TimerActivateProcessDefinitionHandler extends TimerChangeProcessDefinitionSuspensionStateJobHandler {
// type : Activate the process definition
public static final String TYPE = "activate-processdefinition";
// Access to type
@Override
public String getType() {
return TYPE;
}
// Perform operation ,job Operation entity ,configuration To configure ,variableScope Variable range ,commandContext Command context
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
boolean activateProcessInstances = false;
try {
JsonNode configNode = processEngineConfiguration.getObjectMapper().readTree(configuration);
activateProcessInstances = getIncludeProcessInstances(configNode);
} catch (Exception e) {
// Read json Error in value
throw new FlowableException("Error reading json value " + configuration, e);
}
String processDefinitionId = job.getProcessDefinitionId();
ActivateProcessDefinitionCmd activateProcessDefinitionCmd = new ActivateProcessDefinitionCmd(processDefinitionId, null, activateProcessInstances, null, job.getTenantId());
activateProcessDefinitionCmd.execute(commandContext);
}
}
AbstractProcessInstanceMigrationJobHandler Abstract process instance migration job processor
/** * Abstract process instance migration job processor */
public abstract class AbstractProcessInstanceMigrationJobHandler implements JobHandler {
// Batch result status label
public static final String BATCH_RESULT_STATUS_LABEL = "resultStatus";
// Batch result information label
public static final String BATCH_RESULT_MESSAGE_LABEL = "resultMessage";
protected static final String CFG_LABEL_BATCH_ID = "batchId";
protected static final String CFG_LABEL_BATCH_PART_ID = "batchPartId";
protected static String getBatchIdFromHandlerCfg(String handlerCfg) {
try {
JsonNode cfgAsJson = getObjectMapper().readTree(handlerCfg);
if (cfgAsJson.has(CFG_LABEL_BATCH_ID)) {
return cfgAsJson.get(CFG_LABEL_BATCH_ID).asText();
}
return null;
} catch (IOException e) {
return null;
}
}
protected static String getBatchPartIdFromHandlerCfg(String handlerCfg) {
try {
JsonNode cfgAsJson = getObjectMapper().readTree(handlerCfg);
if (cfgAsJson.has(CFG_LABEL_BATCH_PART_ID)) {
return cfgAsJson.get(CFG_LABEL_BATCH_PART_ID).asText();
}
return null;
} catch (IOException e) {
return null;
}
}
public static String getHandlerCfgForBatchId(String batchId) {
ObjectNode handlerCfg = getObjectMapper().createObjectNode();
handlerCfg.put(CFG_LABEL_BATCH_ID, batchId);
return handlerCfg.toString();
}
public static String getHandlerCfgForBatchPartId(String batchPartId) {
ObjectNode handlerCfg = getObjectMapper().createObjectNode();
handlerCfg.put(CFG_LABEL_BATCH_PART_ID, batchPartId);
return handlerCfg.toString();
}
protected static ObjectMapper getObjectMapper() {
if (CommandContextUtil.getCommandContext() != null) {
return CommandContextUtil.getProcessEngineConfiguration().getObjectMapper();
} else {
return new ObjectMapper();
}
}
}
ProcessInstanceMigrationJobHandler Process instance migration job processor
/** * Process instance migration job processor */
public class ProcessInstanceMigrationJobHandler extends AbstractProcessInstanceMigrationJobHandler {
// type : Process migration
public static final String TYPE = "process-migration";
@Override
public String getType() {
return TYPE;
}
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
BatchService batchService = processEngineConfiguration.getBatchServiceConfiguration().getBatchService();
ProcessInstanceMigrationManager processInstanceMigrationManager = processEngineConfiguration.getProcessInstanceMigrationManager();
String batchPartId = getBatchPartIdFromHandlerCfg(configuration);
BatchPart batchPart = batchService.getBatchPart(batchPartId);
Batch batch = batchService.getBatch(batchPart.getBatchId());
ProcessInstanceMigrationDocument migrationDocument = ProcessInstanceMigrationDocumentImpl.fromJson(batch.getBatchDocumentJson(processEngineConfiguration.getEngineCfgKey()));
String exceptionMessage = null;
try {
processInstanceMigrationManager.migrateProcessInstance(batchPart.getScopeId(), migrationDocument, commandContext);
} catch (FlowableException e) {
exceptionMessage = e.getMessage();
}
String resultAsJsonString = prepareResultAsJsonString(exceptionMessage);
if (exceptionMessage != null) {
batchService.completeBatchPart(batchPartId, ProcessInstanceBatchMigrationResult.RESULT_FAIL, resultAsJsonString);
} else {
batchService.completeBatchPart(batchPartId, ProcessInstanceBatchMigrationResult.RESULT_SUCCESS, resultAsJsonString);
}
}
protected static String prepareResultAsJsonString(String exceptionMessage) {
ObjectNode objectNode = getObjectMapper().createObjectNode();
if (exceptionMessage == null) {
objectNode.put(BATCH_RESULT_STATUS_LABEL, ProcessInstanceBatchMigrationResult.RESULT_SUCCESS);
} else {
objectNode.put(BATCH_RESULT_STATUS_LABEL, ProcessInstanceBatchMigrationResult.RESULT_FAIL);
objectNode.put(BATCH_RESULT_MESSAGE_LABEL, exceptionMessage);
}
return objectNode.toString();
}
}
边栏推荐
- False breakthroughs in the trend of London Silver
- NLP第四范式:Prompt概述【Pre-train,Prompt(提示),Predict】【刘鹏飞】
- [detailed] several ways to quickly realize object mapping
- TrueType字体文件提取关键信息
- Paging of a scratch (page turning processing)
- [flask] obtain request information, redirect and error handling
- Luo Gu P1170 Bugs Bunny and Hunter
- SPIR-V初窺
- MATLB | real time opportunity constrained decision making and its application in power system
- Redis守护进程无法停止解决方案
猜你喜欢
ThreeDPoseTracker项目解析
XSS learning XSS lab problem solution
How to upgrade kubernetes in place
Basic operations of databases and tables ----- primary key constraints
Docker compose配置MySQL并实现远程连接
Recommended areas - ways to explore users' future interests
C web page open WinForm exe
[Jiudu OJ 09] two points to find student information
Folio.ink 免费、快速、易用的图片分享工具
Leetcode skimming questions_ Verify palindrome string II
随机推荐
Basic process and testing idea of interface automation
竞赛题 2022-6-26
[机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。
Redis-字符串类型
Leetcode 剑指 Offer 59 - II. 队列的最大值
Force buckle 1020 Number of enclaves
[flask] obtain request information, redirect and error handling
ClickOnce does not support request execution level 'requireAdministrator'
黄金价格走势k线图如何看?
记一个 @nestjs/typeorm^8.1.4 版本不能获取.env选项问题
Unity | 实现面部驱动的两种方式
Tcpdump: monitor network traffic
3D model format summary
国家级非遗传承人高清旺《四大美人》皮影数字藏品惊艳亮相!
什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
Basic operations of database and table ----- set the fields of the table to be automatically added
Une image! Pourquoi l'école t'a - t - elle appris à coder, mais pourquoi pas...
Development trend of Ali Taobao fine sorting model
Netease smart enterprises enter the market against the trend, and there is a new possibility for game industrialization
A Cooperative Approach to Particle Swarm Optimization