Search in sources :

Example 1 with Page

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;
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) AcquiredJobs(org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs) Page(org.camunda.bpm.engine.impl.Page)

Aggregations

Page (org.camunda.bpm.engine.impl.Page)1 AcquiredJobs (org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs)1 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)1