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