JAL-3878 Create base interfaces for new web services.
[jalview.git] / src / jalview / ws2 / WebServiceWorkerI.java
index 1c40eb8..da6e540 100644 (file)
@@ -9,65 +9,29 @@ import jalview.util.MathUtils;
 
 public interface WebServiceWorkerI
 {
-  public class WSJob
-  {
-    public final long uid = MathUtils.getUID();
-    
-    protected WSJobState state = WSJobState.UNKNOWN;
+  long getUID();
 
-    protected String jobID = "";
+  List<WSJob> getJobs();
 
-    protected int jobNum = 0;
+  void startJobs() throws IOException;
 
-    protected int allowedExceptions = 3;
+  boolean pollJobs() throws IOException;
 
-    public long getUID() {
-      return uid;
-    }
-    
-    public WSJobState getState()
-    {
-      return state;
-    }
-
-    public void setState(WSJobState state)
-    {
-      this.state = state;
-    }
-
-    public String getJobID()
-    {
-      return jobID;
-    }
-
-    public void setJobID(String jobID) {
-      this.jobID = jobID;
-    }
-    
-    public int getJobNum()
-    {
-      return jobNum;
-    }
+  WebServiceI getWebService();
 
-    public int getAllowedExceptions()
-    {
-      return allowedExceptions;
-    }
-    
-    public boolean deductAllowedExceptions() {
-      return allowedExceptions-- > 0;
-    }
-    
-    public void resetAllowedExceptions() {
-      allowedExceptions = 3;
+  default boolean isDone() {
+    if (getJobs().size() == 0)
+      return false;
+    for (WSJob job : getJobs()) {
+      if (!job.getStatus().isDone())
+        return false;
     }
+    return true;
   }
 
-  public long getUID();
-
-  public List<WSJob> getJobs();
-
-  public WSJobID startJob(WSJob job) throws IOException;
-
-  public boolean pollJob(WSJob job) throws IOException;
+  /*
+   * Called by the executor when the worker transitions to the done state
+   * either normally or exceptionally.
+   */
+  void done();
 }