JAL-3878 Add javadocs to created classes and reformat code.
[jalview.git] / src / jalview / ws2 / WebServiceWorkerI.java
1 package jalview.ws2;
2
3 import java.io.IOException;
4 import java.util.List;
5
6 import jalview.ws2.utils.WSJobList;
7
8 /**
9  * {@link WebServiceWorkerI} interface is an extension of {@link PollableTaskI}
10  * that adds getter methods for fields that are specific for the web service
11  * tasks such as uid, sub-jobs and underlying web service client as well as a
12  * method to add listeners to the worker events. {@link WebServiceWorkerI}
13  * objects perform operations needed to start, poll and finalize jobs running on
14  * the server as well as store sub-jobs created in the process. They use their
15  * associated {@link WebServiceI} object to submit and poll the jobs and fetch
16  * and parse the result when it's ready.
17  * 
18  * @author mmwarowny
19  *
20  */
21 public interface WebServiceWorkerI extends PollableTaskI
22 {
23   /**
24    * Get unique identifier of this worker. Identifier should be randomly
25    * generated on object creation and must remain unchanged. Unique id can be
26    * generated using {@link jalview.util.MathUtils#getUID}.
27    * 
28    * @return worker unique id
29    */
30   long getUID();
31
32   /**
33    * Get the sub-jobs created by the worker during job submission.
34    * 
35    * @return sub-jobs
36    */
37   WSJobList getJobs();
38
39   /**
40    * Gather and parse input data and submit one or more jobs to the web service
41    * using associated {@link WebServiceI} object.
42    */
43   void start() throws IOException;
44
45   boolean poll() throws IOException;
46
47   WebServiceI getWebService();
48
49   /**
50    * Check if all sub-jobs finished execution and return whether this task has
51    * completed.
52    */
53   default boolean isDone()
54   {
55     if (getJobs().size() == 0)
56       return false;
57     for (WSJob job : getJobs())
58     {
59       if (!job.getStatus().isDone() && !job.getStatus().isFailed())
60         return false;
61     }
62     return true;
63   }
64
65   void done();
66
67   /**
68    * Add worker listeners to this worker that will be notified about any state
69    * changes to this worker.
70    * 
71    * @param listener
72    *          listener to add
73    */
74   public void addListener(WebServiceWorkerListener listener);
75 }