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
AsyncCompleteCallActivityJobHandler 异步完成调用活动作业处理器
/**
* 异步完成调用活动作业处理器
* 异步结束执行的作业处理器{@link JobHandler}实现。
* 主要用例是处理并行多实例调用活动,其中子进程在到达结束事件之前有一个异步步骤。
* 异步锁定发生在子进程实例的级别上,但结束事件将执行在范围内完成父进程实例
* 调用活动的完成回调方法,并可能导致乐观锁定异常。
* 通过在父进程实例的上下文中调度作业,将使用正确的锁。
*
* @author Joram Barrez
*/
public class AsyncCompleteCallActivityJobHandler implements JobHandler {
// 类型:异步完成调用活动
public static final String TYPE = "async-complete-call-actiivty";
@Override
public String getType() {
return TYPE;
}
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) { // the executionId of the job = the parent execution, which will be used for locking
ExecutionEntity childProcessInstanceExecutionEntity = CommandContextUtil.getExecutionEntityManager(commandContext).findById(configuration); // the child process instance execution
CommandContextUtil.getAgenda(commandContext).planEndExecutionOperationSynchronous(childProcessInstanceExecutionEntity);
}
}
AsyncSendEventJobHandler 异步发送事件作业处理器
/**
* 异步发送事件作业处理器
*
* @author Tijs Rademakers
*/
public class AsyncSendEventJobHandler implements JobHandler {
// 类型:异步发送事件
public static final String TYPE = "async-send-event";
@Override
public String getType() {
return TYPE;
}
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
ExecutionEntity executionEntity = (ExecutionEntity) variableScope;
FlowElement flowElement = executionEntity.getCurrentFlowElement();
if (!(flowElement instanceof SendEventServiceTask)) {
throw new FlowableException(String.format("Unexpected activity type found for job %s, at activity %s", job.getId(), flowElement.getId()));
}
Object behavior = ((SendEventServiceTask) flowElement).getBehavior();
if (!(behavior instanceof ActivityBehavior)) {
throw new FlowableException(String.format("Unexpected activity behavior found for job %s, at activity %s: %s",
job.getId(), flowElement.getId(), behavior.getClass()));
}
try {
ActivityBehavior activityBehavior = (ActivityBehavior) behavior;
commandContext.addAttribute(TYPE, true); // Will be read in the SendEventTaskActivityBehavior
activityBehavior.execute(executionEntity);
} finally {
commandContext.removeAttribute(TYPE);
}
}
}
AsyncContinuationJobHandler 异步延续作业处理程序
/**
* 异步延续作业处理程序
*
* @author Tijs Rademakers
*/
public class AsyncContinuationJobHandler implements JobHandler {
// 类型:异步延续
public static final String TYPE = "async-continuation";
@Override
public String getType() {
return TYPE;
}
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
ExecutionEntity executionEntity = (ExecutionEntity) variableScope;
if (CommandContextUtil.getProcessEngineConfiguration(commandContext).isLoggingSessionEnabled()) {
FlowElement flowElement = executionEntity.getCurrentFlowElement();
BpmnLoggingSessionUtil.addAsyncActivityLoggingData("Executing async job for " + flowElement.getId() + ", with job id " + job.getId(),
LoggingSessionConstants.TYPE_SERVICE_TASK_EXECUTE_ASYNC_JOB, job, flowElement, executionEntity);
}
CommandContextUtil.getAgenda(commandContext).planContinueProcessSynchronousOperation(executionEntity);
}
}
AsyncTriggerJobHandler 异步触发作业处理器
/**
* 异步触发作业处理器
*
* @author Tijs Rademakers
*/
public class AsyncTriggerJobHandler implements JobHandler {
// 类型:异步触发
public static final String TYPE = "async-trigger";
@Override
public String getType() {
return TYPE;
}
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
ExecutionEntity executionEntity = (ExecutionEntity) variableScope;
CommandContextUtil.getAgenda(commandContext).planTriggerExecutionOperation(executionEntity);
}
}