DateTime then = new DateTime().minusMinutes(RESULTS_PERIOD_MINUTES);
Collection<JobExecutionLog> logs = jobExecutionLogDAO.findAllSince(then);
Map<String, AtomicInteger> record = new HashMap<String, AtomicInteger>();
for (JobExecutionLog log : logs) {
JobDescriptor job = log.getJob();
if (record.containsKey(job.getKey())) {
record.get(job.getKey()).getAndIncrement();
} else {
record.put(job.getKey(), new AtomicInteger(1));
}
}
MuninResults results = new MuninResults();
for (JobDescriptor job : jobDescriptorDAO.findAll()) {
MuninResult result = new MuninResult();
result.setKey(job.getKey());
if (record.containsKey(job.getKey())) {
AtomicInteger count = record.get(job.getKey());
result.setValue(String.valueOf(count.get()));
} else {
result.setValue("0");
}
results.add(result);