Search in sources :

Example 1 with MessageEntity

use of org.camunda.bpm.engine.impl.persistence.entity.MessageEntity in project camunda-bpm-platform by camunda.

the class EventSubscriptionJobDeclaration method newJobInstance.

protected MessageEntity newJobInstance(EventSubscriptionEntity eventSubscription) {
    MessageEntity message = new MessageEntity();
    // initialize job
    message.setActivityId(eventSubscription.getActivityId());
    message.setExecutionId(eventSubscription.getExecutionId());
    message.setProcessInstanceId(eventSubscription.getProcessInstanceId());
    ProcessDefinitionEntity processDefinition = eventSubscription.getProcessDefinition();
    if (processDefinition != null) {
        message.setProcessDefinitionId(processDefinition.getId());
        message.setProcessDefinitionKey(processDefinition.getKey());
    }
    return message;
}
Also used : MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 2 with MessageEntity

use of org.camunda.bpm.engine.impl.persistence.entity.MessageEntity in project camunda-bpm-platform by camunda.

the class AsyncTaskTest method testFailingAsyncServiceTimer.

@Deployment
public void testFailingAsyncServiceTimer() {
    // start process
    runtimeService.startProcessInstanceByKey("asyncService");
    // now there should be one job in the database, and it is a message
    assertEquals(1, managementService.createJobQuery().count());
    Job job = managementService.createJobQuery().singleResult();
    if (!(job instanceof MessageEntity)) {
        fail("the job must be a message");
    }
    executeAvailableJobs();
    // the service failed: the execution is still sitting in the service task:
    Execution execution = runtimeService.createExecutionQuery().singleResult();
    assertNotNull(execution);
    assertEquals("service", runtimeService.getActiveActivityIds(execution.getId()).get(0));
    // there is still a single job because the timer was created in the same transaction as the
    // service was executed (which rolled back)
    assertEquals(1, managementService.createJobQuery().count());
    runtimeService.deleteProcessInstance(execution.getId(), "dead");
}
Also used : MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity) Execution(org.camunda.bpm.engine.runtime.Execution) Job(org.camunda.bpm.engine.runtime.Job) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 3 with MessageEntity

use of org.camunda.bpm.engine.impl.persistence.entity.MessageEntity in project camunda-bpm-platform by camunda.

the class MessageJobDeclaration method newJobInstance.

@Override
protected MessageEntity newJobInstance(AtomicOperationInvocation context) {
    MessageEntity message = new MessageEntity();
    message.setExecution(context.getExecution());
    return message;
}
Also used : MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity)

Example 4 with MessageEntity

use of org.camunda.bpm.engine.impl.persistence.entity.MessageEntity 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)

Example 5 with MessageEntity

use of org.camunda.bpm.engine.impl.persistence.entity.MessageEntity in project camunda-bpm-platform by camunda.

the class JobQueryTest method setUp.

/**
 * Setup will create
 *   - 3 process instances, each with one timer, each firing at t1/t2/t3 + 1 hour (see process)
 *   - 1 message
 */
protected void setUp() throws Exception {
    super.setUp();
    this.commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    deploymentId = repositoryService.createDeployment().addClasspathResource("org/camunda/bpm/engine/test/api/mgmt/timerOnTask.bpmn20.xml").deploy().getId();
    // Create proc inst that has timer that will fire on t1 + 1 hour
    Calendar startTime = Calendar.getInstance();
    startTime.set(Calendar.MILLISECOND, 0);
    Date t1 = startTime.getTime();
    ClockUtil.setCurrentTime(t1);
    processInstanceIdOne = runtimeService.startProcessInstanceByKey("timerOnTask").getId();
    testStartTime = t1;
    timerOneFireTime = new Date(t1.getTime() + ONE_HOUR);
    // Create proc inst that has timer that will fire on t2 + 1 hour
    startTime.add(Calendar.HOUR_OF_DAY, 1);
    // t2 = t1 + 1 hour
    Date t2 = startTime.getTime();
    ClockUtil.setCurrentTime(t2);
    processInstanceIdTwo = runtimeService.startProcessInstanceByKey("timerOnTask").getId();
    timerTwoFireTime = new Date(t2.getTime() + ONE_HOUR);
    // Create proc inst that has timer that will fire on t3 + 1 hour
    startTime.add(Calendar.HOUR_OF_DAY, 1);
    // t3 = t2 + 1 hour
    Date t3 = startTime.getTime();
    ClockUtil.setCurrentTime(t3);
    processInstanceIdThree = runtimeService.startProcessInstanceByKey("timerOnTask").getId();
    timerThreeFireTime = new Date(t3.getTime() + ONE_HOUR);
    // Create one message
    messageId = commandExecutor.execute(new Command<String>() {

        public String execute(CommandContext commandContext) {
            MessageEntity message = new MessageEntity();
            commandContext.getJobManager().send(message);
            return message.getId();
        }
    });
}
Also used : MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) Command(org.camunda.bpm.engine.impl.interceptor.Command) Calendar(java.util.Calendar) Date(java.util.Date)

Aggregations

MessageEntity (org.camunda.bpm.engine.impl.persistence.entity.MessageEntity)12 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)5 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)4 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)3 AcquiredJobs (org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs)2 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)2 Deployment (org.camunda.bpm.engine.test.Deployment)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 List (java.util.List)1 AcquireJobsCmd (org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd)1 DeleteJobsCmd (org.camunda.bpm.engine.impl.cmd.DeleteJobsCmd)1 Command (org.camunda.bpm.engine.impl.interceptor.Command)1 JobExecutor (org.camunda.bpm.engine.impl.jobexecutor.JobExecutor)1 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)1 JobDefinition (org.camunda.bpm.engine.management.JobDefinition)1 Execution (org.camunda.bpm.engine.runtime.Execution)1 Job (org.camunda.bpm.engine.runtime.Job)1