Jalview 2.6 source licence
[jalview.git] / src / jalview / ws / AWsJob.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3  * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
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  */
18 package jalview.ws;
19
20 /**
21  * Generic properties for an individual job within a Web Service Client thread.
22  * Derived from jalview web services version 1 statuses, and revised for Jws2.
23  */
24
25 public abstract class AWsJob
26 {
27   protected int jobnum = 0;
28
29   protected String jobId;
30
31   /**
32    * @param jobId the jobId to set
33    */
34   public void setJobId(String jobId)
35   {
36     this.jobId = jobId;
37   }
38
39   /**
40    * has job been cancelled
41    */
42   protected boolean cancelled = false;
43
44   /**
45    * number of exceptions left before job dies
46    */
47   int allowedServerExceptions = 3;
48
49   /**
50    * @param allowedServerExceptions the allowedServerExceptions to set
51    */
52   public void setAllowedServerExceptions(int allowedServerExceptions)
53   {
54     this.allowedServerExceptions = allowedServerExceptions;
55   }
56
57   /**
58    * has job been submitted to server ? if false, then no state info is
59    * available.
60    */
61   protected boolean submitted = false;
62
63   /**
64    * @param jobnum the jobnum to set
65    */
66   public void setJobnum(int jobnum)
67   {
68     this.jobnum = jobnum;
69   }
70
71   /**
72    * @param submitted the submitted to set
73    */
74   public void setSubmitted(boolean submitted)
75   {
76     this.submitted = submitted;
77   }
78
79   /**
80    * @param subjobComplete the subjobComplete to set
81    */
82   public void setSubjobComplete(boolean subjobComplete)
83   {
84     this.subjobComplete = subjobComplete;
85   }
86
87   /**
88    * @return the jobnum
89    */
90   public int getJobnum()
91   {
92     return jobnum;
93   }
94
95   /**
96    * @return the jobId
97    */
98   public String getJobId()
99   {
100     return jobId;
101   }
102
103   /**
104    * @return the cancelled
105    */
106   public boolean isCancelled()
107   {
108     return cancelled;
109   }
110
111   /**
112    * @return the allowedServerExceptions
113    */
114   public int getAllowedServerExceptions()
115   {
116     return allowedServerExceptions;
117   }
118
119   /**
120    * @return the submitted
121    */
122   public boolean isSubmitted()
123   {
124     return submitted;
125   }
126
127   /**
128    * @return the subjobComplete
129    */
130   public boolean isSubjobComplete()
131   {
132     return subjobComplete;
133   }
134
135   /**
136    * are all sub-jobs complete
137    */
138   protected boolean subjobComplete = false;
139
140   public AWsJob()
141   {
142   }
143
144   /**
145    * 
146    * @return true if job has completed and valid results are available
147    */
148   abstract public boolean hasResults();
149
150   /**
151    * 
152    * @return boolean true if job can be submitted.
153    */
154   public abstract boolean hasValidInput();
155
156   /**
157    * 
158    * @return true if job is running
159    */
160   abstract public boolean isRunning();
161
162   /**
163    * 
164    * @return true if job is queued
165    */
166   abstract public boolean isQueued();
167
168   /**
169    * 
170    * @return true if job has finished
171    */
172   abstract public boolean isFinished();
173
174   /**
175    * 
176    * @return true if the job failed due to some problem with the input data or
177    *         parameters.
178    */
179   abstract public boolean isFailed();
180
181   /**
182    * 
183    * @return true if job failed due to an unhandled technical issue
184    */
185   abstract public boolean isBroken();
186
187   /**
188    * 
189    * @return true if there was a problem contacting the server.
190    */
191   abstract public boolean isServerError();
192
193   /**
194    * 
195    * @return true if the job has status text.
196    */
197   abstract public boolean hasStatus();
198
199   /**
200    * 
201    * @return status text for job to be displayed to user.
202    */
203   abstract public String getStatus();
204
205   abstract public boolean hasResponse();
206   abstract public void clearResponse();
207   abstract public String getState();
208   /**
209    * generates response using the abstract service flags.
210    * @return a standard state response 
211    */
212   protected String _defaultState() {
213     
214     String state = "";
215     return state;
216   }
217 }