Flowable源码地址:https://github.com/flowable/flowable-engine
Flowable-6.7.2 源码注释地址:https://github.com/solojin/flowable-6.7.2-annotated
包路径:org.flowable.engine.impl.jobexecutor
TimerChangeProcessDefinitionSuspensionStateJobHandler 定时器修改流程定义挂起状态作业处理器
package org.flowable.engine.impl.jobexecutor;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.job.service.JobHandler;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* 定时器修改流程定义挂起状态作业处理器
*
* @author Joram Barrez
*/
public abstract class TimerChangeProcessDefinitionSuspensionStateJobHandler implements JobHandler {
// 作业处理器包含的流程实例
private static final String JOB_HANDLER_CFG_INCLUDE_PROCESS_INSTANCES = "includeProcessInstances";
// 创建作业处理器配置
public static String createJobHandlerConfiguration(boolean includeProcessInstances) {
// 通过命令上下文工具类获取流程引擎配置器
ObjectNode jsonNode = CommandContextUtil.getProcessEngineConfiguration().getObjectMapper().createObjectNode();
jsonNode.put(JOB_HANDLER_CFG_INCLUDE_PROCESS_INSTANCES, includeProcessInstances);
return jsonNode.toString();
}
// 获取标志位,是否包含流程实例
public static boolean getIncludeProcessInstances(JsonNode configNode) {
// 从配置节点中获取属性:JOB_HANDLER_CFG_INCLUDE_PROCESS_INSTANCES 作业处理器包含的流程实例
if (configNode.has(JOB_HANDLER_CFG_INCLUDE_PROCESS_INSTANCES)) {
return configNode.get(JOB_HANDLER_CFG_INCLUDE_PROCESS_INSTANCES).asBoolean();
}
// 默认返回false
return false;
}
}
TimerSuspendProcessDefinitionHandler 定时器挂起流程定义处理器
package org.flowable.engine.impl.jobexecutor;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.cmd.SuspendProcessDefinitionCmd;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.job.service.impl.persistence.entity.JobEntity;
import org.flowable.variable.api.delegate.VariableScope;
import com.fasterxml.jackson.databind.JsonNode;
/**
* 定时器挂起流程定义处理器
* 继承定时器修改流程定义挂起状态作业处理器
*
* @author Joram Barrez
*/
public class TimerSuspendProcessDefinitionHandler extends TimerChangeProcessDefinitionSuspensionStateJobHandler {
// 类型:挂起流程定义
public static final String TYPE = "suspend-processdefinition";
@Override
public String getType() {
return TYPE;
}
// 执行作业,job作业实体,configuration配置,variableScope变量范围,commandContext命令上下文
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
// 根据命令上下文,通过命令上下文工具类获取流程引擎配置
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
// 挂起流程实例标志位,默认false
boolean suspendProcessInstances = false;
try {
// 从流程引擎配置器获取配置节点
JsonNode configNode = processEngineConfiguration.getObjectMapper().readTree(configuration);
// 获取标志位,是否包含流程实例
suspendProcessInstances = getIncludeProcessInstances(configNode);
} catch (Exception e) {
// 读取json值时出错
throw new FlowableException("Error reading json value " + configuration, e);
}
// 从作业实体获取流程定义ID
String processDefinitionId = job.getProcessDefinitionId();
// 新建挂起流程定义命令
SuspendProcessDefinitionCmd suspendProcessDefinitionCmd = new SuspendProcessDefinitionCmd(processDefinitionId, null, suspendProcessInstances, null, job.getTenantId());
// 执行挂起流程定义命令
suspendProcessDefinitionCmd.execute(commandContext);
}
}