@Override public void waitForJobs(UUID id) { JobMetadata job = this.findJob(id); if (job == null) return; while (job.getStatus().isActive()) { Thread.yield(); } }
@Override public synchronized JobMetadata findJob(UUID jobId) { if (jobId == null) throw new IllegalArgumentException( "Unable to find background operations with a specific id without the id specified."); for (JobMetadata job : jobs) { if (jobId.equals(job.getId())) return job; } return null; }
@Override public synchronized List<JobMetadata> findJobsByStatus(JobStatus... statusList) { List<JobMetadata> found = new ArrayList<JobMetadata>(); for (JobMetadata job : jobs) { for (JobStatus status : statusList) { if (job.getStatus() == status) { found.add(job); } } } Collections.reverse(found); return found; }
@Override public void waitForJobs(Class type) { int active; do { active = 0; List<JobMetadata> jobs = this.findJobsByType(type); for (JobMetadata job : jobs) { if (job.getStatus().isActive()) { active++; } } if (active > 0) Thread.yield(); } while (active > 0); }
@Override public synchronized List<JobMetadata> findJobsByOwner(Person owner) { if (owner == null || owner.getId() == null) throw new IllegalArgumentException( "Unable to find background operations from a specific owner without the owner specified."); List<JobMetadata> found = new ArrayList<JobMetadata>(); Long personId = owner.getId(); for (JobMetadata job : jobs) { if (personId.equals(job.getOwnerId())) { found.add(job); } } Collections.reverse(found); return found; }
/** Helpfull method to display the state of the job queue */ public synchronized String toString() { StringBuilder string = new StringBuilder(); for (JobMetadata job : jobs) { string.append(job.getId()); string.append(": "); string.append(job.getStatus().name()); string.append(", "); string.append(job.getProgress().toString()); if (job.getOwnerId() != null) { string.append(" ("); string.append(job.getOwnerId()); string.append(")"); } string.append("\n"); } return string.toString(); }