Flowable源码地址:https://github.com/flowable/flowable-engine
Flowable-6.7.2 源码注释地址:https://github.com/solojin/flowable-6.7.2-annotated
包路径:org.activiti.engine.impl.jobexecutor
TriggerTimerEventJobHandler 触发器定时事件作业处理器
继承 JobHandler 作业处理器接口类
package org.flowable.engine.impl.jobexecutor;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.delegate.event.impl.FlowableEventBuilder;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.job.service.JobHandler;
import org.flowable.job.service.impl.persistence.entity.JobEntity;
import org.flowable.variable.api.delegate.VariableScope;
/**
* 触发器定时事件作业处理器
*
* @author Joram Barrez
*/
public class TriggerTimerEventJobHandler implements JobHandler {
// 类型:触发器定时
public static final String TYPE = "trigger-timer";
// 获取作业处理器类型
@Override
public String getType() {
return TYPE;
}
// 执行作业,job工作实体,configuration配置,variableScope变量范围,commandContext命令上下文
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
// 变量范围强制转换执行器实体类
ExecutionEntity executionEntity = (ExecutionEntity) variableScope;
// 通过命令上下文工具类获取议程,设置计划触发执行操作
CommandContextUtil.getAgenda(commandContext).planTriggerExecutionOperation(executionEntity);
// 根据命令上下文获取流程引擎配置
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
// 根据流程引擎配置获取Flowable事件调度器
FlowableEventDispatcher eventDispatcher = processEngineConfiguration.getEventDispatcher();
// 如果Flowable事件调度器存在且已开启
if (eventDispatcher != null && eventDispatcher.isEnabled()) {
// 调度执行事件
eventDispatcher.dispatchEvent(FlowableEventBuilder.createEntityEvent(FlowableEngineEventType.TIMER_FIRED, job),
processEngineConfiguration.getEngineCfgKey());
}
}
}
ProcessEventJobHandler 流程事件作业处理器
同样继承 JobHandler 作业处理器接口类
package org.flowable.engine.impl.jobexecutor;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.EventSubscriptionUtil;
import org.flowable.eventsubscription.service.EventSubscriptionService;
import org.flowable.eventsubscription.service.impl.persistence.entity.EventSubscriptionEntity;
import org.flowable.job.service.JobHandler;
import org.flowable.job.service.impl.persistence.entity.JobEntity;
import org.flowable.variable.api.delegate.VariableScope;
/**
* 流程事件作业处理器
*
* @author Daniel Meyer
* @author Joram Barrez
*/
public class ProcessEventJobHandler implements JobHandler {
// 类型:事件
public static final String TYPE = "event";
// 获取作业处理器类型
@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);
// 根据流程引擎配置获取事件订阅配置以及事件订阅服务类
EventSubscriptionService eventSubscriptionService = processEngineConfiguration.getEventSubscriptionServiceConfiguration().getEventSubscriptionService();
// 查找订阅:
EventSubscriptionEntity eventSubscriptionEntity = eventSubscriptionService.findById(configuration);
// 如果事件订阅为null,则忽略
if (eventSubscriptionEntity != null) {
// 事件订阅工具类,接收事件方法
EventSubscriptionUtil.eventReceived(eventSubscriptionEntity, null, false);
}
}
}