+package jalview.ws2.api;
+
+public enum JobStatus
+{
+ /** Job has invalid inputs and cannot be started. */
+ INVALID,
+ /** Job is created and ready for submission. */
+ READY,
+ /** Job has been submitted and awaits processing. */
+ SUBMITTED,
+ /** Job has been queued for execution */
+ QUEUED,
+ /** Job is running */
+ RUNNING,
+ /** Job has completed successfully. */
+ COMPLETED,
+ /** Job has finished with errors. */
+ FAILED,
+ /** Job has been cancelled by the user. */
+ CANCELLED,
+ /** Job cannot be processed due to server error. */
+ SERVER_ERROR,
+ /** Job status cannot be determined. */
+ UNKNOWN;
+
+ /**
+ * Returns true if the status corresponds to the job completed due to normal
+ * termination, error or cancellation.
+ *
+ * @return {@value true} if status corresponds to a finished job.
+ */
+ public boolean isDone()
+ {
+ switch (this)
+ {
+ case INVALID:
+ case COMPLETED:
+ case FAILED:
+ case CANCELLED:
+ case SERVER_ERROR:
+ return true;
+ case READY:
+ case SUBMITTED:
+ case QUEUED:
+ case RUNNING:
+ case UNKNOWN:
+ return false;
+ default:
+ throw new AssertionError("non-exhaustive switch statement");
+ }
+ }
+
+ /**
+ * A precedence order of job statuses used to compute the overall task status.
+ */
+ public static final JobStatus[] statusPrecedence = {
+ JobStatus.INVALID, // all must be invalid for task to be invalid
+ JobStatus.COMPLETED, // all but invalid must be completed for task to be
+ // completed
+ JobStatus.UNKNOWN, // unknown prevents successful completion but not
+ // running or failure
+ JobStatus.READY,
+ JobStatus.SUBMITTED,
+ JobStatus.QUEUED,
+ JobStatus.RUNNING,
+ JobStatus.CANCELLED, // if any is terminated unsuccessfully, the task is
+ // failed
+ JobStatus.FAILED,
+ JobStatus.SERVER_ERROR
+ };
+}