use of org.camunda.bpm.engine.impl.Page in project camunda-bpm-platform by camunda.
the class AcquireJobsCmd method execute.
public AcquiredJobs execute(CommandContext commandContext) {
acquiredJobs = new AcquiredJobs(numJobsToAcquire);
List<JobEntity> jobs = commandContext.getJobManager().findNextJobsToExecute(new Page(0, numJobsToAcquire));
Map<String, List<String>> exclusiveJobsByProcessInstance = new HashMap<String, List<String>>();
for (JobEntity job : jobs) {
lockJob(job);
if (job.isExclusive()) {
List<String> list = exclusiveJobsByProcessInstance.get(job.getProcessInstanceId());
if (list == null) {
list = new ArrayList<String>();
exclusiveJobsByProcessInstance.put(job.getProcessInstanceId(), list);
}
list.add(job.getId());
} else {
acquiredJobs.addJobIdBatch(job.getId());
}
}
for (List<String> jobIds : exclusiveJobsByProcessInstance.values()) {
acquiredJobs.addJobIdBatch(jobIds);
}
// register an OptimisticLockingListener which is notified about jobs which cannot be acquired.
// the listener removes them from the list of acquired jobs.
commandContext.getDbEntityManager().registerOptimisticLockingListener(this);
return acquiredJobs;
}
Aggregations