Search in sources :

Example 6 with CommandExecutor

use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.

the class SequentialJobAcquisitionRunnable method acquireJobs.

protected AcquiredJobs acquireJobs(JobAcquisitionContext context, JobAcquisitionStrategy acquisitionStrategy, ProcessEngineImpl currentProcessEngine) {
    CommandExecutor commandExecutor = currentProcessEngine.getProcessEngineConfiguration().getCommandExecutorTxRequired();
    int numJobsToAcquire = acquisitionStrategy.getNumJobsToAcquire(currentProcessEngine.getName());
    AcquiredJobs acquiredJobs = null;
    if (numJobsToAcquire > 0) {
        jobExecutor.logAcquisitionAttempt(currentProcessEngine);
        acquiredJobs = commandExecutor.execute(jobExecutor.getAcquireJobsCmd(numJobsToAcquire));
    } else {
        acquiredJobs = new AcquiredJobs(numJobsToAcquire);
    }
    context.submitAcquiredJobs(currentProcessEngine.getName(), acquiredJobs);
    jobExecutor.logAcquiredJobs(currentProcessEngine, acquiredJobs.size());
    jobExecutor.logAcquisitionFailureJobs(currentProcessEngine, acquiredJobs.getNumberOfJobsFailedToLock());
    LOG.acquiredJobs(currentProcessEngine.getName(), acquiredJobs);
    return acquiredJobs;
}
Also used : CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor)

Example 7 with CommandExecutor

use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.

the class TimerEntity method preExecute.

@Override
protected void preExecute(CommandContext commandContext) {
    if (getJobHandler() instanceof TimerEventJobHandler) {
        TimerJobConfiguration configuration = (TimerJobConfiguration) getJobHandlerConfiguration();
        if (repeat != null && !configuration.isFollowUpJobCreated()) {
            // this timer is a repeating timer and
            // a follow up timer job has not been scheduled yet
            Date newDueDate = calculateRepeat();
            if (newDueDate != null) {
                // the listener is added to the transaction as SYNC on ROLLABCK,
                // when it is necessary to schedule a new timer job invocation.
                // If the transaction does not rollback, it is ignored.
                ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
                CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequiresNew();
                RepeatingFailedJobListener listener = createRepeatingFailedJobListener(commandExecutor);
                commandContext.getTransactionContext().addTransactionListener(TransactionState.ROLLED_BACK, listener);
                // create a new timer job
                createNewTimerJob(newDueDate);
            }
        }
    }
}
Also used : RepeatingFailedJobListener(org.camunda.bpm.engine.impl.jobexecutor.RepeatingFailedJobListener) TimerEventJobHandler(org.camunda.bpm.engine.impl.jobexecutor.TimerEventJobHandler) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) TimerJobConfiguration(org.camunda.bpm.engine.impl.jobexecutor.TimerEventJobHandler.TimerJobConfiguration) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) Date(java.util.Date)

Example 8 with CommandExecutor

use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.

the class HistoricIncidentAuthorizationTest method clearDatabase.

protected void clearDatabase() {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Object>() {

        public Object execute(CommandContext commandContext) {
            commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByHandlerType(TimerSuspendProcessDefinitionHandler.TYPE);
            List<HistoricIncident> incidents = Context.getProcessEngineConfiguration().getHistoryService().createHistoricIncidentQuery().list();
            for (HistoricIncident incident : incidents) {
                commandContext.getHistoricIncidentManager().delete((HistoricIncidentEntity) incident);
            }
            return null;
        }
    });
}
Also used : HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) HistoricIncidentEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) List(java.util.List)

Example 9 with CommandExecutor

use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.

the class ManagementServiceTest method deleteJobAndIncidents.

protected void deleteJobAndIncidents(final Job job) {
    final List<HistoricIncident> incidents = historyService.createHistoricIncidentQuery().incidentType(Incident.FAILED_JOB_HANDLER_TYPE).list();
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {

        @Override
        public Void execute(CommandContext commandContext) {
            ((JobEntity) job).delete();
            HistoricIncidentManager historicIncidentManager = commandContext.getHistoricIncidentManager();
            for (HistoricIncident incident : incidents) {
                HistoricIncidentEntity incidentEntity = (HistoricIncidentEntity) incident;
                historicIncidentManager.delete(incidentEntity);
            }
            commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(job.getId());
            return null;
        }
    });
}
Also used : HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) HistoricIncidentEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) HistoricIncidentManager(org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentManager) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor)

Example 10 with CommandExecutor

use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.

the class ManagementServiceTest method createJob.

protected void createJob(final int retries, final String owner, final Date lockExpirationTime) {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {

        @Override
        public Void execute(CommandContext commandContext) {
            JobManager jobManager = commandContext.getJobManager();
            MessageEntity job = new MessageEntity();
            job.setJobHandlerType("any");
            job.setLockOwner(owner);
            job.setLockExpirationTime(lockExpirationTime);
            job.setRetries(retries);
            jobManager.send(job);
            return null;
        }
    });
}
Also used : MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager)

Aggregations

CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)53 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)31 Deployment (org.camunda.bpm.engine.test.Deployment)17 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)15 SetProcessDefinitionVersionCmd (org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd)13 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)11 Job (org.camunda.bpm.engine.runtime.Job)9 Date (java.util.Date)8 List (java.util.List)7 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)7 Execution (org.camunda.bpm.engine.runtime.Execution)6 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)5 HistoricIncident (org.camunda.bpm.engine.history.HistoricIncident)5 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)5 AcquireJobsCmd (org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd)5 AcquiredJobs (org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs)5 JobExecutor (org.camunda.bpm.engine.impl.jobexecutor.JobExecutor)5 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)5 HistoricIncidentEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity)4 MessageEntity (org.camunda.bpm.engine.impl.persistence.entity.MessageEntity)4