2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 import jalview.bin.Cache;
22 import jalview.datamodel.AlignedCodonFrame;
23 import jalview.datamodel.Alignment;
24 import jalview.datamodel.AlignmentI;
25 import jalview.datamodel.AlignmentView;
26 import jalview.datamodel.SequenceI;
27 import jalview.gui.AlignFrame;
28 import jalview.gui.WebserviceInfo;
29 import jalview.gui.FeatureRenderer.FeatureRendererSettings;
31 public abstract class AWSThread extends Thread
35 * view that this job was associated with
37 protected AlignmentI currentView = null;
40 * feature settings from view that job was associated with
42 protected FeatureRendererSettings featureSettings = null;
45 * metadata about this web service
47 protected WebserviceInfo wsInfo = null;
50 * original input data for this job
52 protected AlignmentView input = null;
55 * dataset sequence relationships to be propagated onto new results
57 protected AlignedCodonFrame[] codonframe = null;
60 * are there jobs still running in this thread.
62 protected boolean jobComplete = false;
65 * one or more jobs being managed by this thread.
67 protected AWsJob jobs[] = null;
70 * full name of service
72 protected String WebServiceName = null;
74 protected char defGapChar = '-';
77 * header prepended to all output from job
79 protected String OutputHeader;
82 * only used when reporting a web service out of memory error - the job ID
83 * will be concatenated to the URL
85 protected String WsUrl = null;
88 * generic web service job/subjob poll loop
92 JobStateSummary jstate = null;
99 jstate = new JobStateSummary();
100 for (int j = 0; j < jobs.length; j++)
103 if (!jobs[j].submitted && jobs[j].hasValidInput())
108 if (jobs[j].submitted && !jobs[j].subjobComplete)
113 if (!jobs[j].hasResponse())
115 throw (new Exception(
116 "Timed out when communicating with server\nTry again later.\n"));
118 jalview.bin.Cache.log.debug("Job " + j + " Result state "
119 + jobs[j].getState() + "(ServerError="
120 + jobs[j].isServerError() + ")");
121 } catch (Exception ex)
123 // Deal with Transaction exceptions
124 wsInfo.appendProgressText(jobs[j].jobnum, "\n" + WebServiceName
125 + " Server exception!\n" + ex.getMessage());
126 // always output the exception's stack trace to the log
127 Cache.log.warn(WebServiceName + " job(" + jobs[j].jobnum
128 + ") Server exception.");
129 // todo: could limit trace to cause if this is a SOAPFaultException.
130 ex.printStackTrace();
132 if (jobs[j].allowedServerExceptions > 0)
134 jobs[j].allowedServerExceptions--;
135 Cache.log.debug("Sleeping after a server exception.");
139 } catch (InterruptedException ex1)
145 Cache.log.warn("Dropping job " + j + " " + jobs[j].jobId);
146 jobs[j].subjobComplete = true;
147 wsInfo.setStatus(jobs[j].jobnum,
148 WebserviceInfo.STATE_STOPPED_SERVERERROR);
150 } catch (OutOfMemoryError er)
153 jobs[j].subjobComplete = true;
154 jobs[j].clearResponse(); // may contain out of date result data
155 wsInfo.setStatus(jobs[j].jobnum,
156 WebserviceInfo.STATE_STOPPED_ERROR);
157 Cache.log.error("Out of memory when retrieving Job " + j
158 + " id:" + WsUrl + "/" + jobs[j].jobId, er);
159 new jalview.gui.OOMWarning("retrieving result for "
160 + WebServiceName, er);
164 jstate.updateJobPanelState(wsInfo, OutputHeader, jobs[j]);
166 // Decide on overall state based on collected jobs[] states
167 updateGlobalStatus(jstate);
173 } catch (InterruptedException e)
176 .debug("Interrupted sleep waiting for next job poll.", e);
178 // System.out.println("I'm alive "+alTitle);
181 if (jobComplete && jobs != null)
183 parseResult(); // tidy up and make results available to user
188 .debug("WebServiceJob poll loop finished with no jobs created.");
189 wsInfo.setStatus(wsInfo.STATE_STOPPED_ERROR);
190 wsInfo.appendProgressText("No jobs ran.");
191 wsInfo.setFinishedNoResults();
195 protected void updateGlobalStatus(JobStateSummary jstate)
197 if (jstate.running > 0)
199 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
201 else if (jstate.queuing > 0)
203 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
208 if (jstate.finished > 0)
210 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
212 else if (jstate.error > 0)
214 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
216 else if (jstate.serror > 0)
218 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
228 public AWSThread(Runnable target)
233 public AWSThread(String name)
238 public AWSThread(ThreadGroup group, Runnable target)
240 super(group, target);
243 public AWSThread(ThreadGroup group, String name)
248 public AWSThread(Runnable target, String name)
253 public AWSThread(ThreadGroup group, Runnable target, String name)
255 super(group, target, name);
259 * query web service for status of job. on return, job.result must not be null
260 * - if it is then it will be assumed that the job status query timed out and
261 * a server exception will be logged.
265 * will be logged as a server exception for this job
267 public abstract void pollJob(AWsJob job) throws Exception;
270 * submit job to web service
274 public abstract void StartJob(AWsJob job);
277 * process the set of AWsJob objects into a set of results, and tidy up.
279 public abstract void parseResult();
282 * helper function to conserve dataset references to sequence objects returned
283 * from web services 1. Propagates AlCodonFrame data from
284 * <code>codonframe</code> to <code>al</code> TODO: refactor to datamodel
288 public void propagateDatasetMappings(Alignment al)
290 if (codonframe != null)
292 SequenceI[] alignment = al.getSequencesArray();
293 for (int sq = 0; sq < alignment.length; sq++)
295 for (int i = 0; i < codonframe.length; i++)
297 if (codonframe[i] != null
298 && codonframe[i].involvesSequence(alignment[sq]))
300 al.addCodonFrame(codonframe[i]);
301 codonframe[i] = null;
309 public AWSThread(ThreadGroup group, Runnable target, String name,
312 super(group, target, name, stackSize);
317 * @return gap character to use for any alignment generation
319 public char getGapChar()
327 * reference for copying mappings across
329 * gui attachment point
331 * input data for the calculation
332 * @param webServiceName
335 * url of the service being invoked
337 public AWSThread(AlignFrame alignFrame, WebserviceInfo wsinfo,
338 AlignmentView input, String webServiceName, String wsUrl)
340 this(alignFrame, wsinfo, input, wsUrl);
341 WebServiceName = webServiceName;
345 * Extracts additional info from alignment view's context.
348 * - reference for copying mappings and display styles across
350 * - gui attachment point - may be null
352 * - input data for the calculation
354 * - url of the service being invoked
356 public AWSThread(AlignFrame alframe, WebserviceInfo wsinfo2,
357 AlignmentView alview, String wsurl2)
360 // this.alignFrame = alframe;
361 currentView = alframe.getCurrentView().getAlignment();
362 featureSettings = alframe.getFeatureRenderer().getSettings();
363 defGapChar = alframe.getViewport().getGapCharacter();
364 this.wsInfo = wsinfo2;
369 AlignedCodonFrame[] cf = alframe.getViewport().getAlignment()
373 codonframe = new AlignedCodonFrame[cf.length];
374 System.arraycopy(cf, 0, codonframe, 0, cf.length);