当前位置: 首页>>代码示例>>Java>>正文


Java Context.getJobExecutorContext方法代码示例

本文整理汇总了Java中org.activiti.engine.impl.context.Context.getJobExecutorContext方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getJobExecutorContext方法的具体用法?Java Context.getJobExecutorContext怎么用?Java Context.getJobExecutorContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.activiti.engine.impl.context.Context的用法示例。


在下文中一共展示了Context.getJobExecutorContext方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.activiti.engine.impl.context.Context; //导入方法依赖的package包/类
@Override
public Object execute(CommandContext commandContext) {

    if (jobId == null && job == null) {
        throw new ActivitiIllegalArgumentException("jobId and job is null");
    }

    if (job == null) {
        job = commandContext
                .getJobEntityManager()
                .findJobById(jobId);
    }

    if (job == null) {
        throw new JobNotFoundException(jobId);
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Executing job {}", job.getId());
    }

    JobExecutorContext jobExecutorContext = Context.getJobExecutorContext();
    if (jobExecutorContext != null) { // if null, then we are not called by the job executor
        jobExecutorContext.setCurrentJob(job);
    }

    FailedJobListener failedJobListener = null;
    try {
        // When transaction is rolled back, decrement retries
        failedJobListener = new FailedJobListener(commandContext.getProcessEngineConfiguration().getCommandExecutor(), job.getId());
        commandContext.getTransactionContext().addTransactionListener(
                TransactionState.ROLLED_BACK,
                failedJobListener);

        job.execute(commandContext);

        if (commandContext.getEventDispatcher().isEnabled()) {
            commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(
                    FlowableEngineEventType.JOB_EXECUTION_SUCCESS, job));
        }

    } catch (Throwable exception) {
        failedJobListener.setException(exception);

        // Dispatch an event, indicating job execution failed in a try-catch block, to prevent the original
        // exception to be swallowed
        if (commandContext.getEventDispatcher().isEnabled()) {
            try {
                commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityExceptionEvent(
                        FlowableEngineEventType.JOB_EXECUTION_FAILURE, job, exception));
            } catch (Throwable ignore) {
                LOGGER.warn("Exception occurred while dispatching job failure event, ignoring.", ignore);
            }
        }

        // Finally, Throw the exception to indicate the ExecuteJobCmd failed
        if (!(exception instanceof ActivitiException)) {
            throw new ActivitiException("Job " + jobId + " failed", exception);
        } else {
            throw (ActivitiException) exception;
        }
    } finally {
        if (jobExecutorContext != null) {
            jobExecutorContext.setCurrentJob(null);
        }
    }
    return null;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:69,代码来源:ExecuteJobsCmd.java


注:本文中的org.activiti.engine.impl.context.Context.getJobExecutorContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。