本文整理汇总了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;
}