use of org.activiti.engine.impl.persistence.entity.MessageEntity in project Activiti by Activiti.
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.getCommandExecutor();
deploymentId = repositoryService.createDeployment().addClasspathResource("org/activiti/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();
processEngineConfiguration.getClock().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();
processEngineConfiguration.getClock().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();
processEngineConfiguration.getClock().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.getJobEntityManager().send(message);
return message.getId();
}
});
}
use of org.activiti.engine.impl.persistence.entity.MessageEntity in project Activiti by Activiti.
the class AcquireJobsCmd method execute.
public AcquiredJobs execute(CommandContext commandContext) {
String lockOwner = jobExecutor.getLockOwner();
int lockTimeInMillis = jobExecutor.getLockTimeInMillis();
int maxNonExclusiveJobsPerAcquisition = jobExecutor.getMaxJobsPerAcquisition();
AcquiredJobs acquiredJobs = new AcquiredJobs();
List<JobEntity> jobs = commandContext.getJobEntityManager().findNextJobsToExecute(new Page(0, maxNonExclusiveJobsPerAcquisition));
for (JobEntity job : jobs) {
List<String> jobIds = new ArrayList<String>();
if (job != null && !acquiredJobs.contains(job.getId())) {
if (job instanceof MessageEntity && job.isExclusive() && job.getProcessInstanceId() != null) {
// wait to get exclusive jobs within 100ms
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
// acquire all exclusive jobs in the same process instance
// (includes the current job)
List<JobEntity> exclusiveJobs = commandContext.getJobEntityManager().findExclusiveJobsToExecute(job.getProcessInstanceId());
for (JobEntity exclusiveJob : exclusiveJobs) {
if (exclusiveJob != null) {
lockJob(commandContext, exclusiveJob, lockOwner, lockTimeInMillis);
jobIds.add(exclusiveJob.getId());
}
}
} else {
lockJob(commandContext, job, lockOwner, lockTimeInMillis);
jobIds.add(job.getId());
}
}
acquiredJobs.addJobIdBatch(jobIds);
}
return acquiredJobs;
}
use of org.activiti.engine.impl.persistence.entity.MessageEntity in project Activiti by Activiti.
the class JobExecutorCmdExceptionTest method createTweetExceptionMessage.
protected MessageEntity createTweetExceptionMessage() {
MessageEntity message = new MessageEntity();
message.setJobHandlerType("tweet-exception");
return message;
}
use of org.activiti.engine.impl.persistence.entity.MessageEntity in project Activiti by Activiti.
the class JobExecutorTestCase method createTweetMessage.
protected MessageEntity createTweetMessage(String msg) {
MessageEntity message = new MessageEntity();
message.setJobHandlerType("tweet");
message.setJobHandlerConfiguration(msg);
return message;
}
use of org.activiti.engine.impl.persistence.entity.MessageEntity in project Activiti by Activiti.
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");
}
try {
managementService.executeJob(job.getId());
fail();
} catch (Exception e) {
// exception expected
}
// 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");
}
Aggregations