Search in sources :

Example 46 with CommandContext

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

the class DeploymentAwareJobExecutorTest method testJobsWithoutDeploymentIdAreAlwaysProcessed.

public void testJobsWithoutDeploymentIdAreAlwaysProcessed() {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    String messageId = commandExecutor.execute(new Command<String>() {

        public String execute(CommandContext commandContext) {
            MessageEntity message = new MessageEntity();
            commandContext.getJobManager().send(message);
            return message.getId();
        }
    });
    AcquiredJobs acquiredJobs = getExecutableJobs(processEngineConfiguration.getJobExecutor());
    Assert.assertEquals(1, acquiredJobs.size());
    Assert.assertTrue(acquiredJobs.contains(messageId));
    commandExecutor.execute(new DeleteJobsCmd(messageId, true));
}
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) AcquiredJobs(org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs) DeleteJobsCmd(org.camunda.bpm.engine.impl.cmd.DeleteJobsCmd)

Example 47 with CommandContext

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

the class AbstractPaLocalScriptEngineTest method getProcessApplication.

protected ProcessApplicationInterface getProcessApplication() {
    ProcessApplicationReference reference = processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<ProcessApplicationReference>() {

        public ProcessApplicationReference execute(CommandContext commandContext) {
            ProcessDefinitionEntity definition = commandContext.getProcessDefinitionManager().findLatestProcessDefinitionByKey(PROCESS_ID);
            String deploymentId = definition.getDeploymentId();
            ProcessApplicationManager processApplicationManager = processEngineConfiguration.getProcessApplicationManager();
            return processApplicationManager.getProcessApplicationForDeployment(deploymentId);
        }
    });
    assertNotNull(reference);
    ProcessApplicationInterface processApplication = null;
    try {
        processApplication = reference.getProcessApplication();
    } catch (ProcessApplicationUnavailableException e) {
        fail("Could not retrieve process application");
    }
    return processApplication.getRawObject();
}
Also used : ProcessApplicationReference(org.camunda.bpm.application.ProcessApplicationReference) ProcessApplicationUnavailableException(org.camunda.bpm.application.ProcessApplicationUnavailableException) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ProcessApplicationManager(org.camunda.bpm.engine.impl.application.ProcessApplicationManager) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) ProcessApplicationInterface(org.camunda.bpm.application.ProcessApplicationInterface)

Example 48 with CommandContext

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

the class SendSignalDelegate method execute.

public void execute(DelegateExecution execution) throws Exception {
    businessProcess.setVariable("processName", "throwSignal-visited (was " + businessProcess.getVariable("processName") + ")");
    String signalProcessInstanceId = (String) execution.getVariable("signalProcessInstanceId");
    String executionId = runtimeService.createExecutionQuery().processInstanceId(signalProcessInstanceId).signalEventSubscriptionName("alert").singleResult().getId();
    CommandContext commandContext = Context.getCommandContext();
    List<EventSubscriptionEntity> findSignalEventSubscriptionsByEventName = commandContext.getEventSubscriptionManager().findSignalEventSubscriptionsByNameAndExecution("alert", executionId);
    for (EventSubscriptionEntity signalEventSubscriptionEntity : findSignalEventSubscriptionsByEventName) {
        signalEventSubscriptionEntity.eventReceived(null, true);
    }
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 49 with CommandContext

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

the class SignalTestRunListener method notify.

public void notify(final DelegateExecution execution) throws Exception {
    final String runId = (String) execution.getVariable(PerfTestConstants.RUN_ID);
    CommandContext commandContext = Context.getCommandContext();
    if (runId != null && commandContext != null) {
        commandContext.getTransactionContext().addTransactionListener(TransactionState.COMMITTED, new TransactionListener() {

            public void execute(CommandContext commandContext) {
                // signal run after the transaction was committed
                PerfTestRunner.signalRun(runId);
            }
        });
    }
}
Also used : TransactionListener(org.camunda.bpm.engine.impl.cfg.TransactionListener) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext)

Example 50 with CommandContext

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

the class HistoricJobLogTest method testDeleteByteArray.

public void testDeleteByteArray() {
    final String processDefinitionId = "myProcessDefition";
    processEngineConfiguration.getCommandExecutorTxRequiresNew().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            for (int i = 0; i < 1234; i++) {
                HistoricJobLogEventEntity log = new HistoricJobLogEventEntity();
                log.setJobId(String.valueOf(i));
                log.setTimestamp(new Date());
                log.setJobDefinitionType(MessageEntity.TYPE);
                log.setProcessDefinitionId(processDefinitionId);
                byte[] aByteValue = StringUtil.toByteArray("abc");
                ByteArrayEntity byteArray = ExceptionUtil.createJobExceptionByteArray(aByteValue);
                log.setExceptionByteArrayId(byteArray.getId());
                commandContext.getHistoricJobLogManager().insert(log);
            }
            return null;
        }
    });
    assertEquals(1234, historyService.createHistoricJobLogQuery().count());
    processEngineConfiguration.getCommandExecutorTxRequiresNew().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByProcessDefinitionId(processDefinitionId);
            return null;
        }
    });
    assertEquals(0, historyService.createHistoricJobLogQuery().count());
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) Date(java.util.Date) HistoricJobLogEventEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricJobLogEventEntity)

Aggregations

CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)120 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)31 List (java.util.List)17 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)17 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)11 Deployment (org.camunda.bpm.engine.test.Deployment)11 ArrayList (java.util.ArrayList)10 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)10 Date (java.util.Date)9 HistoricIncident (org.camunda.bpm.engine.history.HistoricIncident)8 DeploymentCache (org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache)8 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)8 Command (org.camunda.bpm.engine.impl.interceptor.Command)6 HistoricIncidentEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity)6 After (org.junit.After)6 ProcessApplicationReference (org.camunda.bpm.application.ProcessApplicationReference)5 RepositoryService (org.camunda.bpm.engine.RepositoryService)5 ProcessEngineImpl (org.camunda.bpm.engine.impl.ProcessEngineImpl)5 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)5 HistoricDecisionInstance (org.camunda.bpm.engine.history.HistoricDecisionInstance)4