Merge branch 'JAL-3878_ws-overhaul-3' into mmw/Release_2_12_ws_merge
[jalview.git] / src / jalview / ws2 / actions / api / TaskI.java
diff --git a/src/jalview/ws2/actions/api/TaskI.java b/src/jalview/ws2/actions/api/TaskI.java
new file mode 100644 (file)
index 0000000..cb84944
--- /dev/null
@@ -0,0 +1,54 @@
+package jalview.ws2.actions.api;
+
+import java.util.List;
+
+import jalview.ws2.api.JobStatus;
+
+/**
+ * {@code TaskI} objects represent running services. Tasks are created by
+ * concrete implementations of {@link ActionI} and provide a view of the state
+ * of the underlying job(s).
+ * 
+ * @author mmwarowny
+ *
+ * @param <T>
+ *          task result type
+ */
+public interface TaskI<T>
+{
+  /**
+   * Get the universal identifier of this task.
+   * 
+   * @return identifier
+   */
+  long getUid();
+
+  /**
+   * Get the current status of the task. The resultant status should be a
+   * combination of individual sub-job statuses.
+   * 
+   * @return global status of
+   */
+  JobStatus getStatus();
+
+  /**
+   * Get the current list of sub-jobs of that task.
+   * 
+   * @return sub-jobs
+   */
+  List<? extends JobI> getSubJobs();
+
+  /**
+   * Get the last result of the task or {@code null} if not present. Note that
+   * the result is subject to change for restartable tasks.
+   * 
+   * @return last task result
+   */
+  T getResult();
+
+  /**
+   * Cancel the task, stop all sub-jobs running on a server and stop all threads
+   * managing this task.
+   */
+  void cancel();
+}