use of org.camunda.bpm.engine.impl.jobexecutor.JobExecutorContext in project camunda-bpm-platform by camunda.
the class DbEntityManager method initializeEntityCache.
protected void initializeEntityCache() {
final JobExecutorContext jobExecutorContext = Context.getJobExecutorContext();
final ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
if (processEngineConfiguration != null && processEngineConfiguration.isDbEntityCacheReuseEnabled() && jobExecutorContext != null) {
dbEntityCache = jobExecutorContext.getEntityCache();
if (dbEntityCache == null) {
dbEntityCache = new DbEntityCache(processEngineConfiguration.getDbEntityCacheKeyMapping());
jobExecutorContext.setEntityCache(dbEntityCache);
}
} else {
if (processEngineConfiguration != null) {
dbEntityCache = new DbEntityCache(processEngineConfiguration.getDbEntityCacheKeyMapping());
} else {
dbEntityCache = new DbEntityCache();
}
}
}
use of org.camunda.bpm.engine.impl.jobexecutor.JobExecutorContext in project camunda-bpm-platform by camunda.
the class ExecuteJobsCmd method execute.
public Void execute(CommandContext commandContext) {
ensureNotNull("jobId", jobId);
final JobEntity job = commandContext.getDbEntityManager().selectById(JobEntity.class, jobId);
final ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
final IdentityService identityService = processEngineConfiguration.getIdentityService();
final JobExecutorContext jobExecutorContext = Context.getJobExecutorContext();
if (job == null) {
if (jobExecutorContext != null) {
// CAM-1842
// Job was acquired but does not exist anymore. This is not a problem.
// It usually means that the job has been deleted after it was acquired which can happen if the
// the activity instance corresponding to the job is cancelled.
LOG.debugAcquiredJobNotFound(jobId);
return null;
} else {
throw LOG.jobNotFoundException(jobId);
}
}
jobFailureCollector.setJob(job);
if (jobExecutorContext == null) {
// if null, then we are not called by the job executor
for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
checker.checkUpdateJob(job);
}
} else {
jobExecutorContext.setCurrentJob(job);
// if the job is called by the job executor then set the tenant id of the job
// as authenticated tenant to enable tenant checks
String tenantId = job.getTenantId();
if (tenantId != null) {
identityService.setAuthentication(null, null, Collections.singletonList(tenantId));
}
}
try {
// register as command context close lister to intercept exceptions on flush
commandContext.registerCommandContextListener(jobFailureCollector);
commandContext.setCurrentJob(job);
job.execute(commandContext);
} finally {
if (jobExecutorContext != null) {
jobExecutorContext.setCurrentJob(null);
identityService.clearAuthentication();
}
}
return null;
}
Aggregations