Flowable源码注释(三十七)异步作业处理器

本文深入探讨Flowable引擎的异步作业处理器,包括AsyncCompleteCallActivityJobHandler、AsyncSendEventJobHandler、AsyncContinuationJobHandler和AsyncTriggerJobHandler,详细解析这些处理器在流程执行中的作用和实现。
摘要由CSDN通过智能技术生成

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);
    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值