int processEngineLoopCounter = 0;
List<String> idleEngines = new ArrayList<String>();
boolean jobExecutionFailed = false;
while (!isInterrupted) {
ProcessEngineImpl currentProcessEngine = null;
int maxJobsPerAcquisition = jobExecutor.getMaxJobsPerAcquisition();
try {
List<ProcessEngineImpl> registeredProcessEngines = jobExecutor.getProcessEngines();
synchronized (registeredProcessEngines) {
if (registeredProcessEngines.size() > 0) {
if (registeredProcessEngines.size() <= processEngineLoopCounter) {
processEngineLoopCounter = 0;
isJobAdded = false;
idleEngines.clear();
}
currentProcessEngine = registeredProcessEngines.get(processEngineLoopCounter);
processEngineLoopCounter++;
}
}
} catch (Exception e) {
log.log(Level.SEVERE, "exception while determining next process engine: " + e.getMessage(), e);
}
jobExecutionFailed = false;
if (currentProcessEngine != null) {
try {
final CommandExecutor commandExecutor = currentProcessEngine.getProcessEngineConfiguration()
.getCommandExecutorTxRequired();
AcquiredJobs acquiredJobs = commandExecutor.execute(jobExecutor.getAcquireJobsCmd());
for (List<String> jobIds : acquiredJobs.getJobIdBatches()) {
jobExecutor.executeJobs(jobIds, currentProcessEngine);
}
// add number of jobs which we attempted to acquire but could not obtain a lock for -> do not wait if we could not acquire jobs.
int jobsAcquired = acquiredJobs.getJobIdBatches().size() + acquiredJobs.getNumberOfJobsFailedToLock();
if (jobsAcquired < maxJobsPerAcquisition) {
idleEngines.add(currentProcessEngine.getName());
}
} catch (Exception e) {
log.log(Level.SEVERE, "exception during job acquisition: " + e.getMessage(), e);