synchronized (jobs) {
List<String> jobQueueChildren = null;
try {
jobQueueChildren = zk.getChildren(jobQueuePath, jobsInQueueWatcher);
} catch (KeeperException e) {
fireEvent(new OrbExceptionEvent(e));
} catch (InterruptedException e) {
fireEvent(new OrbExceptionEvent(e));
}
List<String> jobsToRemove = new ArrayList<String>();
for (String jobPath : jobs.keySet()) {
if (!jobQueueChildren.contains(jobPath)) {
jobsToRemove.add(jobPath);
// Either a job has completed or been removed by someone else this should fire an event.
// This should really not occur since it should only be removed by the JobManager itself.
// In reality does an event really even need to be thrown?
}
}
for (String job : jobsToRemove) {
logger.debug("Removing job: " + job);
jobs.remove(job);
activeJobs.remove(job);
}
for (String jobPath : jobQueueChildren) {
OrbConfiguration jobConf;
try {
jobConf = (OrbConfiguration) ZookeeperUtils.getNodeWritable(zk, jobQueuePath + "/" + jobPath,
OrbConfiguration.class, orbConf);
if (jobConf != null) {
if (!jobs.containsKey(jobPath)) {
logger.debug("Adding job: " + jobPath);
jobs.put(jobPath, new OrbJob(jobPath, jobConf));
// Here we have a new job--once again an event should be fired.
// Although I am not sure that an event really needs to be fired at this point. We will see.
}
} else {
logger.debug("Job is not a valid job.");
}
} catch (OrbZKFailure e) {
fireEvent(new OrbExceptionEvent(e));
}
}
}
tryToLaunchJob();
}