public synchronized void run() {
// if (log.isLoggable(Level.INFO)) {
// log.info(jobExecutor.getName() + " starting to acquire jobs");
// }
final CommandExecutor commandExecutor = jobExecutor.getCommandExecutor();
// while is not needed - repetition is done by event scheduling
// while (!isInterrupted) {
isWaiting.set(false);
int maxJobsPerAcquisition = jobExecutor.getMaxJobsPerAcquisition();
try {
AcquiredJobs acquiredJobs = commandExecutor.execute(jobExecutor.getAcquireJobsCmd());
for (List<String> jobIds : acquiredJobs.getJobIdBatches()) {
jobExecutor.executeJobs(jobIds);
}
// if all jobs were executed
millisToWait = jobExecutor.getWaitTimeInMillis();
int jobsAcquired = acquiredJobs.getJobIdBatches().size();
if (jobsAcquired < maxJobsPerAcquisition) {
isJobAdded = false;
// check if the next timer should fire before the normal sleep time is over
Date duedate = new Date(SimulationRunContext.getClock().getCurrentTime().getTime() + millisToWait);
List<TimerEntity> nextTimers = commandExecutor.execute(new GetUnlockedTimersByDuedateCmd(duedate, new Page(0, 1)));
if (!nextTimers.isEmpty()) {
long millisTillNextTimer = nextTimers.get(0).getDuedate().getTime() - SimulationRunContext.getClock().getCurrentTime().getTime();
if (millisTillNextTimer < millisToWait && millisTillNextTimer != 0) {
millisToWait = millisTillNextTimer;