JAL-3878 Separate gui elements from operations.
[jalview.git] / src / jalview / ws2 / WebServiceWorkerI.java
index 1c40eb8..38c82a2 100644 (file)
@@ -3,71 +3,37 @@ package jalview.ws2;
 import java.io.IOException;
 import java.util.List;
 
-import javax.print.attribute.standard.JobState;
+import jalview.ws2.utils.WSJobList;
 
-import jalview.util.MathUtils;
+public interface WebServiceWorkerI extends PollableTaskI
+{  
+  long getUID();
 
-public interface WebServiceWorkerI
-{
-  public class WSJob
-  {
-    public final long uid = MathUtils.getUID();
-    
-    protected WSJobState state = WSJobState.UNKNOWN;
-
-    protected String jobID = "";
-
-    protected int jobNum = 0;
+  WSJobList getJobs();
 
-    protected int allowedExceptions = 3;
+  void start() throws IOException;
 
-    public long getUID() {
-      return uid;
-    }
-    
-    public WSJobState getState()
-    {
-      return state;
-    }
+  boolean poll() throws IOException;
 
-    public void setState(WSJobState state)
-    {
-      this.state = state;
-    }
-
-    public String getJobID()
-    {
-      return jobID;
-    }
+  WebServiceI getWebService();
 
-    public void setJobID(String jobID) {
-      this.jobID = jobID;
-    }
-    
-    public int getJobNum()
-    {
-      return jobNum;
-    }
-
-    public int getAllowedExceptions()
+  default boolean isDone()
+  {
+    if (getJobs().size() == 0)
+      return false;
+    for (WSJob job : getJobs())
     {
-      return allowedExceptions;
-    }
-    
-    public boolean deductAllowedExceptions() {
-      return allowedExceptions-- > 0;
-    }
-    
-    public void resetAllowedExceptions() {
-      allowedExceptions = 3;
+      if (!job.getStatus().isDone() && !job.getStatus().isFailed())
+        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();
+  
+  public void addListener(WebServiceWorkerListener listener);
 }