JAL-4199 Replace AbstractPollingTask with BaseTask
[jalview.git] / src / jalview / ws2 / actions / api / TaskI.java
1 package jalview.ws2.actions.api;
2
3 import java.util.List;
4
5 import jalview.ws2.api.JobStatus;
6
7 /**
8  * {@code TaskI} objects represent running services. Tasks are created by
9  * concrete implementations of {@link ActionI} and provide a view of the state
10  * of the underlying job(s).
11  * 
12  * @author mmwarowny
13  *
14  * @param <T>
15  *          task result type
16  */
17 public interface TaskI<T>
18 {
19   /**
20    * Get the universal identifier of this task.
21    * 
22    * @return identifier
23    */
24   long getUid();
25
26   /**
27    * Get the current status of the task. The resultant status should be a
28    * combination of individual sub-job statuses.
29    * 
30    * @return global status of
31    */
32   JobStatus getStatus();
33
34   /**
35    * Get the current list of sub-jobs of that task.
36    * 
37    * @return sub-jobs
38    */
39   List<? extends JobI> getSubJobs();
40
41   void addTaskEventListener(TaskEventListener<T> listener);
42
43   void removeTaskEventListener(TaskEventListener<T> listener);
44
45   /**
46    * Get the last result of the task or {@code null} if not present. Note that
47    * the result is subject to change for restartable tasks.
48    * 
49    * @return last task result
50    */
51   T getResult();
52
53   public void init() throws Exception;
54
55   public boolean poll() throws Exception;
56
57   public void complete() throws Exception;
58
59   /**
60    * Cancel the task, stop all sub-jobs running on a server and stop all threads
61    * managing this task.
62    */
63   void cancel();
64 }