f5f9377534a64f0958dc3c9be2af2cb34483e54e
[jalview.git] / src / jalview / ws / AWsJob.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.ws;
22
23 /**
24  * Generic properties for an individual job within a Web Service Client thread.
25  * Derived from jalview web services version 1 statuses, and revised for Jws2.
26  */
27
28 public abstract class AWsJob
29 {
30   protected int jobnum = 0;
31
32   protected String jobId;
33
34   /**
35    * @param jobId
36    *          the jobId to set
37    */
38   public void setJobId(String jobId)
39   {
40     this.jobId = jobId;
41   }
42
43   /**
44    * has job been cancelled
45    */
46   protected boolean cancelled = false;
47
48   /**
49    * number of exceptions left before job dies
50    */
51   int allowedServerExceptions = 3;
52
53   /**
54    * @param allowedServerExceptions
55    *          the allowedServerExceptions to set
56    */
57   public void setAllowedServerExceptions(int allowedServerExceptions)
58   {
59     this.allowedServerExceptions = allowedServerExceptions;
60   }
61
62   /**
63    * has job been submitted to server ? if false, then no state info is
64    * available.
65    */
66   protected boolean submitted = false;
67
68   /**
69    * @param jobnum
70    *          the jobnum to set
71    */
72   public void setJobnum(int jobnum)
73   {
74     this.jobnum = jobnum;
75   }
76
77   /**
78    * @param submitted
79    *          the submitted to set
80    */
81   public void setSubmitted(boolean submitted)
82   {
83     this.submitted = submitted;
84   }
85
86   /**
87    * @param subjobComplete
88    *          the subjobComplete to set
89    */
90   public void setSubjobComplete(boolean subjobComplete)
91   {
92     this.subjobComplete = subjobComplete;
93   }
94
95   /**
96    * @return the jobnum
97    */
98   public int getJobnum()
99   {
100     return jobnum;
101   }
102
103   /**
104    * @return the jobId
105    */
106   public String getJobId()
107   {
108     return jobId;
109   }
110
111   /**
112    * @return the cancelled
113    */
114   public boolean isCancelled()
115   {
116     return cancelled;
117   }
118
119   /**
120    * @return the allowedServerExceptions
121    */
122   public int getAllowedServerExceptions()
123   {
124     return allowedServerExceptions;
125   }
126
127   /**
128    * @return the submitted
129    */
130   public boolean isSubmitted()
131   {
132     return submitted;
133   }
134
135   /**
136    * @return the subjobComplete
137    */
138   public boolean isSubjobComplete()
139   {
140     return subjobComplete;
141   }
142
143   /**
144    * are all sub-jobs complete
145    */
146   protected boolean subjobComplete = false;
147
148   public AWsJob()
149   {
150   }
151
152   /**
153    * 
154    * @return true if job has completed and valid results are available
155    */
156   abstract public boolean hasResults();
157
158   /**
159    * 
160    * @return boolean true if job can be submitted.
161    */
162   public abstract boolean hasValidInput();
163
164   /**
165    * 
166    * @return true if job is running
167    */
168   abstract public boolean isRunning();
169
170   /**
171    * 
172    * @return true if job is queued
173    */
174   abstract public boolean isQueued();
175
176   /**
177    * 
178    * @return true if job has finished
179    */
180   abstract public boolean isFinished();
181
182   /**
183    * 
184    * @return true if the job failed due to some problem with the input data or
185    *         parameters.
186    */
187   abstract public boolean isFailed();
188
189   /**
190    * 
191    * @return true if job failed due to an unhandled technical issue
192    */
193   abstract public boolean isBroken();
194
195   /**
196    * 
197    * @return true if there was a problem contacting the server.
198    */
199   abstract public boolean isServerError();
200
201   /**
202    * 
203    * @return true if the job has status text.
204    */
205   abstract public boolean hasStatus();
206
207   /**
208    * 
209    * @return status text for job to be displayed to user.
210    */
211   abstract public String getStatus();
212
213   abstract public boolean hasResponse();
214
215   abstract public void clearResponse();
216
217   abstract public String getState();
218
219   /**
220    * generates response using the abstract service flags.
221    * 
222    * @return a standard state response
223    */
224   protected String _defaultState()
225   {
226
227     String state = "";
228     return state;
229   }
230 }