bb203fc73a8041881c4b51f5c0c82afea72acbcb
[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 import jalview.ws.params.ArgumentI;
24 import jalview.ws.params.WsParamSetI;
25
26 import java.util.Hashtable;
27 import java.util.List;
28 import java.util.Map;
29
30 /**
31  * Generic properties for an individual job within a Web Service Client thread.
32  * Derived from jalview web services version 1 statuses, and revised for Jws2.
33  */
34
35 public abstract class AWsJob
36 {
37   protected int jobnum = 0;
38
39   protected String jobId;
40
41   /**
42    * @param jobId
43    *          the jobId to set
44    */
45   public void setJobId(String jobId)
46   {
47     this.jobId = jobId;
48   }
49
50   /**
51    * has job been cancelled
52    */
53   protected boolean cancelled = false;
54
55   /**
56    * number of exceptions left before job dies
57    */
58   int allowedServerExceptions = 3;
59
60   /**
61    * @param allowedServerExceptions
62    *          the allowedServerExceptions to set
63    */
64   public void setAllowedServerExceptions(int allowedServerExceptions)
65   {
66     this.allowedServerExceptions = allowedServerExceptions;
67   }
68
69   /**
70    * has job been submitted to server ? if false, then no state info is
71    * available.
72    */
73   protected boolean submitted = false;
74
75   /**
76    * @param jobnum
77    *          the jobnum to set
78    */
79   public void setJobnum(int jobnum)
80   {
81     this.jobnum = jobnum;
82   }
83
84   /**
85    * @param submitted
86    *          the submitted to set
87    */
88   public void setSubmitted(boolean submitted)
89   {
90     this.submitted = submitted;
91   }
92
93   /**
94    * @param subjobComplete
95    *          the subjobComplete to set
96    */
97   public void setSubjobComplete(boolean subjobComplete)
98   {
99     this.subjobComplete = subjobComplete;
100   }
101
102   /**
103    * @return the jobnum
104    */
105   public int getJobnum()
106   {
107     return jobnum;
108   }
109
110   /**
111    * @return the jobId
112    */
113   public String getJobId()
114   {
115     return jobId;
116   }
117
118   /**
119    * @return the cancelled
120    */
121   public boolean isCancelled()
122   {
123     return cancelled;
124   }
125
126   /**
127    * @return the allowedServerExceptions
128    */
129   public int getAllowedServerExceptions()
130   {
131     return allowedServerExceptions;
132   }
133
134   /**
135    * @return the submitted
136    */
137   public boolean isSubmitted()
138   {
139     return submitted;
140   }
141
142   /**
143    * @return the subjobComplete
144    */
145   public boolean isSubjobComplete()
146   {
147     return subjobComplete;
148   }
149
150   /**
151    * are all sub-jobs complete
152    */
153   protected boolean subjobComplete = false;
154
155   protected WsParamSetI preset = null;
156
157   protected List<ArgumentI> arguments = null;
158
159   protected Hashtable<String, Map> SeqNames = new Hashtable();
160
161   public AWsJob()
162   {
163   }
164
165   /**
166    * 
167    * @return true if job has completed and valid results are available
168    */
169   abstract public boolean hasResults();
170
171   /**
172    * 
173    * @return boolean true if job can be submitted.
174    */
175   public abstract boolean hasValidInput();
176
177   /**
178    * 
179    * @return true if job is running
180    */
181   abstract public boolean isRunning();
182
183   /**
184    * 
185    * @return true if job is queued
186    */
187   abstract public boolean isQueued();
188
189   /**
190    * 
191    * @return true if job has finished
192    */
193   abstract public boolean isFinished();
194
195   /**
196    * 
197    * @return true if the job failed due to some problem with the input data or
198    *         parameters.
199    */
200   abstract public boolean isFailed();
201
202   /**
203    * 
204    * @return true if job failed due to an unhandled technical issue
205    */
206   abstract public boolean isBroken();
207
208   /**
209    * 
210    * @return true if there was a problem contacting the server.
211    */
212   abstract public boolean isServerError();
213
214   /**
215    * 
216    * @return true if the job has status text.
217    */
218   abstract public boolean hasStatus();
219
220   /**
221    * 
222    * @return status text for job to be displayed to user.
223    */
224   abstract public String getStatus();
225
226   abstract public boolean hasResponse();
227
228   abstract public void clearResponse();
229
230   abstract public String getState();
231
232   /**
233    * generates response using the abstract service flags.
234    * 
235    * @return a standard state response
236    */
237   protected String _defaultState()
238   {
239
240     String state = "";
241     return state;
242   }
243
244   public void setPreset(WsParamSetI jobpreset)
245   {
246     preset = jobpreset;
247   }
248
249   public void setArguments(List<ArgumentI> paramset)
250   {
251     arguments = paramset;
252
253   }
254 }