Exemplo n.º 1
0
        protected internal virtual void initializeEntityCache()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.camunda.bpm.engine.impl.jobexecutor.JobExecutorContext jobExecutorContext = org.camunda.bpm.engine.impl.context.Context.getJobExecutorContext();
            JobExecutorContext jobExecutorContext = Context.JobExecutorContext;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl processEngineConfiguration = org.camunda.bpm.engine.impl.context.Context.getProcessEngineConfiguration();
            ProcessEngineConfigurationImpl processEngineConfiguration = Context.ProcessEngineConfiguration;

            if (processEngineConfiguration != null && processEngineConfiguration.DbEntityCacheReuseEnabled && jobExecutorContext != null)
            {
                dbEntityCache = jobExecutorContext.EntityCache;
                if (dbEntityCache == null)
                {
                    dbEntityCache = new DbEntityCache(processEngineConfiguration.DbEntityCacheKeyMapping);
                    jobExecutorContext.EntityCache = dbEntityCache;
                }
            }
            else
            {
                if (processEngineConfiguration != null)
                {
                    dbEntityCache = new DbEntityCache(processEngineConfiguration.DbEntityCacheKeyMapping);
                }
                else
                {
                    dbEntityCache = new DbEntityCache();
                }
            }
        }
Exemplo n.º 2
0
        protected internal virtual void HintJobExecutor(JobEntity job)
        {
            JobExecutor jobExecutor = context.Impl.Context.ProcessEngineConfiguration.JobExecutor;

            if (!jobExecutor.IsActive)
            {
                return;
            }

            JobExecutorContext   jobExecutorContext  = context.Impl.Context.JobExecutorContext;
            ITransactionListener transactionListener = null;

            if (!job.Suspended && job.Exclusive && jobExecutorContext != null && jobExecutorContext.ExecutingExclusiveJob && AreInSameProcessInstance(job, jobExecutorContext.CurrentJob))
            {
                // lock job & add to the queue of the current processor
                DateTime currentTime = ClockUtil.CurrentTime;
                job.LockExpirationTime = new DateTime(currentTime.Ticks + jobExecutor.LockTimeInMillis);
                job.LockOwner          = jobExecutor.LockOwner;
                transactionListener    = new ExclusiveJobAddedNotification(job.Id, jobExecutorContext);
            }
            else
            {
                // notify job executor:
                transactionListener = new MessageAddedNotification(jobExecutor);
            }
            context.Impl.Context.CommandContext.TransactionContext.AddTransactionListener(TransactionJavaStatus.Committed, transactionListener);
        }
Exemplo n.º 3
0
        public virtual Void execute(CommandContext commandContext)
        {
            ensureNotNull("jobId", jobId);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.camunda.bpm.engine.impl.persistence.entity.JobEntity job = commandContext.getDbEntityManager().selectById(org.camunda.bpm.engine.impl.persistence.entity.JobEntity.class, jobId);
            JobEntity job = commandContext.DbEntityManager.selectById(typeof(JobEntity), jobId);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl processEngineConfiguration = org.camunda.bpm.engine.impl.context.Context.getProcessEngineConfiguration();
            ProcessEngineConfigurationImpl processEngineConfiguration = Context.ProcessEngineConfiguration;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.camunda.bpm.engine.IdentityService identityService = processEngineConfiguration.getIdentityService();
            IdentityService identityService = processEngineConfiguration.IdentityService;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.camunda.bpm.engine.impl.jobexecutor.JobExecutorContext jobExecutorContext = org.camunda.bpm.engine.impl.context.Context.getJobExecutorContext();
            JobExecutorContext jobExecutorContext = Context.JobExecutorContext;

            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.Job = job;

            if (jobExecutorContext == null)
            {     // if null, then we are not called by the job executor
                foreach (CommandChecker checker in commandContext.ProcessEngineConfiguration.CommandCheckers)
                {
                    checker.checkUpdateJob(job);
                }
                // write a user operation log since we're not called by the job executor
                commandContext.OperationLogManager.logJobOperation(org.camunda.bpm.engine.history.UserOperationLogEntry_Fields.OPERATION_TYPE_EXECUTE, jobId, job.JobDefinitionId, job.ProcessInstanceId, job.ProcessDefinitionId, job.ProcessDefinitionKey, PropertyChange.EMPTY_CHANGE);
            }
            else
            {
                jobExecutorContext.CurrentJob = 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.TenantId;
                if (!string.ReferenceEquals(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.CurrentJob = job;

                job.execute(commandContext);
            }
            finally
            {
                if (jobExecutorContext != null)
                {
                    jobExecutorContext.CurrentJob = null;
                    identityService.clearAuthentication();
                }
            }

            return(null);
        }