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