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
5 * This file is part of Jalview.
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.
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.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 import jalview.bin.Cache;
21 import jalview.datamodel.AlignedCodonFrame;
22 import jalview.datamodel.Alignment;
23 import jalview.datamodel.AlignmentI;
24 import jalview.datamodel.AlignmentView;
25 import jalview.datamodel.SequenceI;
26 import jalview.gui.AlignFrame;
27 import jalview.gui.WebserviceInfo;
28 import jalview.gui.FeatureRenderer.FeatureRendererSettings;
30 public abstract class AWSThread extends Thread
34 * view that this job was associated with
36 protected AlignmentI currentView = null;
38 * feature settings from view that job was associated with
40 protected FeatureRendererSettings featureSettings = null;
42 * metadata about this web service
44 protected WebserviceInfo wsInfo = null;
46 * original input data for this job
48 protected AlignmentView input = null;
50 * dataset sequence relationships to be propagated onto new results
52 protected AlignedCodonFrame[] codonframe = null;
54 * are there jobs still running in this thread.
56 protected boolean jobComplete = false;
58 * one or more jobs being managed by this thread.
60 protected AWsJob jobs[] = null;
62 * full name of service
64 protected String WebServiceName = null;
65 protected char defGapChar = '-';
67 * header prepended to all output from job
69 protected String OutputHeader;
72 * only used when reporting a web service out of memory error - the job ID will be concatenated to the URL
74 protected String WsUrl = null;
77 * generic web service job/subjob poll loop
81 JobStateSummary jstate = null;
88 jstate = new JobStateSummary();
89 for (int j = 0; j < jobs.length; j++)
92 if (!jobs[j].submitted && jobs[j].hasValidInput())
97 if (jobs[j].submitted && !jobs[j].subjobComplete)
102 if (!jobs[j].hasResponse())
104 throw (new Exception(
105 "Timed out when communicating with server\nTry again later.\n"));
107 jalview.bin.Cache.log.debug("Job " + j + " Result state "
108 + jobs[j].getState() + "(ServerError="
109 + jobs[j].isServerError() + ")");
110 } catch (Exception ex)
112 // Deal with Transaction exceptions
113 wsInfo.appendProgressText(jobs[j].jobnum, "\n" + WebServiceName
114 + " Server exception!\n" + ex.getMessage());
115 // always output the exception's stack trace to the log
116 Cache.log.warn(WebServiceName + " job(" + jobs[j].jobnum
117 + ") Server exception.");
118 // todo: could limit trace to cause if this is a SOAPFaultException.
119 ex.printStackTrace();
121 if (jobs[j].allowedServerExceptions > 0)
123 jobs[j].allowedServerExceptions--;
124 Cache.log.debug("Sleeping after a server exception.");
128 } catch (InterruptedException ex1)
134 Cache.log.warn("Dropping job " + j + " " + jobs[j].jobId);
135 jobs[j].subjobComplete = true;
136 wsInfo.setStatus(jobs[j].jobnum,
137 WebserviceInfo.STATE_STOPPED_SERVERERROR);
139 } catch (OutOfMemoryError er)
142 jobs[j].subjobComplete = true;
143 jobs[j].clearResponse(); // may contain out of date result data
144 wsInfo.setStatus(jobs[j].jobnum,
145 WebserviceInfo.STATE_STOPPED_ERROR);
146 Cache.log.error("Out of memory when retrieving Job " + j
147 + " id:" + WsUrl + "/" + jobs[j].jobId, er);
148 new jalview.gui.OOMWarning("retrieving result for "
149 + WebServiceName, er);
153 jstate.updateJobPanelState(wsInfo, OutputHeader, jobs[j]);
155 // Decide on overall state based on collected jobs[] states
156 if (jstate.running > 0)
158 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
160 else if (jstate.queuing > 0)
162 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
167 if (jstate.finished > 0)
169 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
171 else if (jstate.error > 0)
173 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
175 else if (jstate.serror > 0)
177 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
185 } catch (InterruptedException e)
188 .debug("Interrupted sleep waiting for next job poll.", e);
190 // System.out.println("I'm alive "+alTitle);
193 if (jobComplete && jobs != null)
195 parseResult(); // tidy up and make results available to user
200 .debug("WebServiceJob poll loop finished with no jobs created.");
201 wsInfo.setFinishedNoResults();
211 public AWSThread(Runnable target)
216 public AWSThread(String name)
221 public AWSThread(ThreadGroup group, Runnable target)
223 super(group, target);
226 public AWSThread(ThreadGroup group, String name)
231 public AWSThread(Runnable target, String name)
236 public AWSThread(ThreadGroup group, Runnable target, String name)
238 super(group, target, name);
242 * query web service for status of job. on return, job.result must not be null
243 * - if it is then it will be assumed that the job status query timed out and
244 * a server exception will be logged.
248 * will be logged as a server exception for this job
250 public abstract void pollJob(AWsJob job) throws Exception;
253 * submit job to web service
257 public abstract void StartJob(AWsJob job);
260 * process the set of AWsJob objects into a set of results, and tidy up.
262 public abstract void parseResult();
265 * helper function to conserve dataset references to sequence objects returned
266 * from web services 1. Propagates AlCodonFrame data from
267 * <code>codonframe</code> to <code>al</code>
268 * TODO: refactor to datamodel
271 public void propagateDatasetMappings(Alignment al)
273 if (codonframe != null)
275 SequenceI[] alignment = al.getSequencesArray();
276 for (int sq = 0; sq < alignment.length; sq++)
278 for (int i = 0; i < codonframe.length; i++)
280 if (codonframe[i] != null
281 && codonframe[i].involvesSequence(alignment[sq]))
283 al.addCodonFrame(codonframe[i]);
284 codonframe[i] = null;
292 public AWSThread(ThreadGroup group, Runnable target, String name,
295 super(group, target, name, stackSize);
300 * @return gap character to use for any alignment generation
302 public char getGapChar()
310 * reference for copying mappings across
312 * gui attachment point
314 * input data for the calculation
315 * @param webServiceName
318 * url of the service being invoked
320 public AWSThread(AlignFrame alignFrame, WebserviceInfo wsinfo,
321 AlignmentView input, String webServiceName, String wsUrl)
323 this(alignFrame, wsinfo, input, wsUrl);
324 WebServiceName = webServiceName;
330 * - reference for copying mappings and display styles across
332 * - gui attachment point
334 * - input data for the calculation
336 * - url of the service being invoked
338 public AWSThread(AlignFrame alframe, WebserviceInfo wsinfo2,
339 AlignmentView alview, String wsurl2)
342 // this.alignFrame = alframe;
343 currentView = alframe.getCurrentView().getAlignment();
344 featureSettings = alframe.getFeatureRenderer().getSettings();
345 defGapChar = alframe.getViewport().getGapCharacter();
346 this.wsInfo = wsinfo2;
351 AlignedCodonFrame[] cf = alframe.getViewport().getAlignment()
355 codonframe = new AlignedCodonFrame[cf.length];
356 System.arraycopy(cf, 0, codonframe, 0, cf.length);