Search in sources :

Example 1 with JobExecutorContext

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();
        }
    }
}
Also used : JobExecutorContext(org.camunda.bpm.engine.impl.jobexecutor.JobExecutorContext) DbEntityCache(org.camunda.bpm.engine.impl.db.entitymanager.cache.DbEntityCache) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)

Example 2 with JobExecutorContext

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;
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) IdentityService(org.camunda.bpm.engine.IdentityService) JobExecutorContext(org.camunda.bpm.engine.impl.jobexecutor.JobExecutorContext) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Aggregations

ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)2 JobExecutorContext (org.camunda.bpm.engine.impl.jobexecutor.JobExecutorContext)2 IdentityService (org.camunda.bpm.engine.IdentityService)1 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)1 DbEntityCache (org.camunda.bpm.engine.impl.db.entitymanager.cache.DbEntityCache)1 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)1