3 import jalview.bin.Cache;
4 import jalview.datamodel.AlignedCodonFrame;
5 import jalview.datamodel.Alignment;
6 import jalview.datamodel.AlignmentI;
7 import jalview.datamodel.AlignmentView;
8 import jalview.datamodel.SequenceI;
9 import jalview.gui.AlignFrame;
10 import jalview.gui.WebserviceInfo;
11 import jalview.gui.FeatureRenderer.FeatureRendererSettings;
13 public abstract class AWSThread extends Thread
17 * view that this job was associated with
19 protected AlignmentI currentView = null;
21 * feature settings from view that job was associated with
23 protected FeatureRendererSettings featureSettings = null;
25 * metadata about this web service
27 protected WebserviceInfo wsInfo = null;
29 * original input data for this job
31 protected AlignmentView input = null;
33 * dataset sequence relationships to be propagated onto new results
35 protected AlignedCodonFrame[] codonframe = null;
37 * are there jobs still running in this thread.
39 protected boolean jobComplete = false;
41 * one or more jobs being managed by this thread.
43 protected AWsJob jobs[] = null;
45 * full name of service
47 protected String WebServiceName = null;
48 protected char defGapChar = '-';
50 * header prepended to all output from job
52 protected String OutputHeader;
55 * only used when reporting a web service out of memory error - the job ID will be concatenated to the URL
57 protected String WsUrl = null;
60 * generic web service job/subjob poll loop
64 JobStateSummary jstate = null;
71 jstate = new JobStateSummary();
72 for (int j = 0; j < jobs.length; j++)
75 if (!jobs[j].submitted && jobs[j].hasValidInput())
80 if (jobs[j].submitted && !jobs[j].subjobComplete)
85 if (!jobs[j].hasResponse())
88 "Timed out when communicating with server\nTry again later.\n"));
90 jalview.bin.Cache.log.debug("Job " + j + " Result state "
91 + jobs[j].getState() + "(ServerError="
92 + jobs[j].isServerError() + ")");
93 } catch (Exception ex)
95 // Deal with Transaction exceptions
96 wsInfo.appendProgressText(jobs[j].jobnum, "\n" + WebServiceName
97 + " Server exception!\n" + ex.getMessage());
98 // always output the exception's stack trace to the log
99 Cache.log.warn(WebServiceName + " job(" + jobs[j].jobnum
100 + ") Server exception.");
101 ex.printStackTrace();
103 if (jobs[j].allowedServerExceptions > 0)
105 jobs[j].allowedServerExceptions--;
106 Cache.log.debug("Sleeping after a server exception.");
110 } catch (InterruptedException ex1)
116 Cache.log.warn("Dropping job " + j + " " + jobs[j].jobId);
117 jobs[j].subjobComplete = true;
118 wsInfo.setStatus(jobs[j].jobnum,
119 WebserviceInfo.STATE_STOPPED_SERVERERROR);
121 } catch (OutOfMemoryError er)
124 jobs[j].subjobComplete = true;
125 jobs[j].clearResponse(); // may contain out of date result data
126 wsInfo.setStatus(jobs[j].jobnum,
127 WebserviceInfo.STATE_STOPPED_ERROR);
128 Cache.log.error("Out of memory when retrieving Job " + j
129 + " id:" + WsUrl + "/" + jobs[j].jobId, er);
130 new jalview.gui.OOMWarning("retrieving result for "
131 + WebServiceName, er);
135 jstate.updateJobPanelState(wsInfo, OutputHeader, jobs[j]);
137 // Decide on overall state based on collected jobs[] states
138 if (jstate.running > 0)
140 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
142 else if (jstate.queuing > 0)
144 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
149 if (jstate.finished > 0)
151 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
153 else if (jstate.error > 0)
155 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
157 else if (jstate.serror > 0)
159 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
167 } catch (InterruptedException e)
170 .debug("Interrupted sleep waiting for next job poll.", e);
172 // System.out.println("I'm alive "+alTitle);
175 if (jobComplete && jobs != null)
177 parseResult(); // tidy up and make results available to user
182 .debug("WebServiceJob poll loop finished with no jobs created.");
183 wsInfo.setFinishedNoResults();
193 public AWSThread(Runnable target)
198 public AWSThread(String name)
203 public AWSThread(ThreadGroup group, Runnable target)
205 super(group, target);
208 public AWSThread(ThreadGroup group, String name)
213 public AWSThread(Runnable target, String name)
218 public AWSThread(ThreadGroup group, Runnable target, String name)
220 super(group, target, name);
224 * query web service for status of job. on return, job.result must not be null
225 * - if it is then it will be assumed that the job status query timed out and
226 * a server exception will be logged.
230 * will be logged as a server exception for this job
232 public abstract void pollJob(AWsJob job) throws Exception;
235 * submit job to web service
239 public abstract void StartJob(AWsJob job);
242 * process the set of AWsJob objects into a set of results, and tidy up.
244 public abstract void parseResult();
247 * helper function to conserve dataset references to sequence objects returned
248 * from web services 1. Propagates AlCodonFrame data from
249 * <code>codonframe</code> to <code>al</code>
250 * TODO: refactor to datamodel
253 public void propagateDatasetMappings(Alignment al)
255 if (codonframe != null)
257 SequenceI[] alignment = al.getSequencesArray();
258 for (int sq = 0; sq < alignment.length; sq++)
260 for (int i = 0; i < codonframe.length; i++)
262 if (codonframe[i] != null
263 && codonframe[i].involvesSequence(alignment[sq]))
265 al.addCodonFrame(codonframe[i]);
266 codonframe[i] = null;
274 public AWSThread(ThreadGroup group, Runnable target, String name,
277 super(group, target, name, stackSize);
282 * @return gap character to use for any alignment generation
284 public char getGapChar()
292 * reference for copying mappings across
294 * gui attachment point
296 * input data for the calculation
297 * @param webServiceName
300 * url of the service being invoked
302 public AWSThread(AlignFrame alignFrame, WebserviceInfo wsinfo,
303 AlignmentView input, String webServiceName, String wsUrl)
305 this(alignFrame, wsinfo, input, wsUrl);
306 WebServiceName = webServiceName;
312 * - reference for copying mappings and display styles across
314 * - gui attachment point
316 * - input data for the calculation
318 * - url of the service being invoked
320 public AWSThread(AlignFrame alframe, WebserviceInfo wsinfo2,
321 AlignmentView alview, String wsurl2)
324 // this.alignFrame = alframe;
325 currentView = alframe.getCurrentView().getAlignment();
326 featureSettings = alframe.getFeatureRenderer().getSettings();
327 defGapChar = alframe.getViewport().getGapCharacter();
328 this.wsInfo = wsinfo2;
333 AlignedCodonFrame[] cf = alframe.getViewport().getAlignment()
337 codonframe = new AlignedCodonFrame[cf.length];
338 System.arraycopy(cf, 0, codonframe, 0, cf.length);