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);
}