Mercurial > repos > timpalpant > java_genomics_toolkit
comparison gui/edu/unc/genomics/SubmittedJob.java @ 2:e16016635b2a
Uploaded
| author | timpalpant |
|---|---|
| date | Mon, 13 Feb 2012 22:12:06 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:a54db233ee3d | 2:e16016635b2a |
|---|---|
| 1 package edu.unc.genomics; | |
| 2 | |
| 3 import java.util.concurrent.ExecutionException; | |
| 4 import java.util.concurrent.Future; | |
| 5 | |
| 6 /** | |
| 7 * Represents a job that was submitted for processing | |
| 8 * | |
| 9 * @author timpalpant | |
| 10 * | |
| 11 */ | |
| 12 public class SubmittedJob { | |
| 13 private static int numJobs = 0; | |
| 14 | |
| 15 private final Future<?> future; | |
| 16 private final int id; | |
| 17 private final Job job; | |
| 18 | |
| 19 public SubmittedJob(Job job, Future<?> future) { | |
| 20 this.id = ++numJobs; | |
| 21 this.job = job; | |
| 22 this.future = future; | |
| 23 } | |
| 24 | |
| 25 /** | |
| 26 * @return the id | |
| 27 */ | |
| 28 public int getId() { | |
| 29 return id; | |
| 30 } | |
| 31 | |
| 32 /** | |
| 33 * @return the job | |
| 34 */ | |
| 35 public Job getJob() { | |
| 36 return job; | |
| 37 } | |
| 38 | |
| 39 /** | |
| 40 * If the job is currently running | |
| 41 * @return | |
| 42 */ | |
| 43 public boolean isRunning() { | |
| 44 return job.isRunning() && !isDone(); | |
| 45 } | |
| 46 | |
| 47 /** | |
| 48 * If the job is done running | |
| 49 * (it may have failed or succeeded) | |
| 50 * @return | |
| 51 */ | |
| 52 public boolean isDone() { | |
| 53 return future.isDone(); | |
| 54 } | |
| 55 | |
| 56 /** | |
| 57 * If this job completed without any Exceptions | |
| 58 * @return | |
| 59 */ | |
| 60 public boolean succeeded() { | |
| 61 return (future.isDone() && !failed()); | |
| 62 } | |
| 63 | |
| 64 /** | |
| 65 * If this job completed with Exceptions | |
| 66 * @return | |
| 67 */ | |
| 68 public boolean failed() { | |
| 69 if (future.isDone()) { | |
| 70 try { | |
| 71 future.get(); | |
| 72 return false; | |
| 73 } catch (InterruptedException | ExecutionException e) { | |
| 74 return true; | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 return false; | |
| 79 } | |
| 80 | |
| 81 /** | |
| 82 * Return an Exception that occured, or null if there were none | |
| 83 * or the job is not yet done | |
| 84 * @return | |
| 85 */ | |
| 86 public Exception getException() { | |
| 87 if (future.isDone()) { | |
| 88 try { | |
| 89 future.get(); | |
| 90 return null; | |
| 91 } catch (InterruptedException | ExecutionException e) { | |
| 92 return e; | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 return null; | |
| 97 } | |
| 98 | |
| 99 @Override | |
| 100 public String toString() { | |
| 101 return "Job "+id+": "+job.getName(); | |
| 102 } | |
| 103 } |
