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 // todo: could limit trace to cause if this is a SOAPFaultException.
102 ex.printStackTrace();
104 if (jobs[j].allowedServerExceptions > 0)
106 jobs[j].allowedServerExceptions--;
107 Cache.log.debug("Sleeping after a server exception.");
111 } catch (InterruptedException ex1)
117 Cache.log.warn("Dropping job " + j + " " + jobs[j].jobId);
118 jobs[j].subjobComplete = true;
119 wsInfo.setStatus(jobs[j].jobnum,
120 WebserviceInfo.STATE_STOPPED_SERVERERROR);
122 } catch (OutOfMemoryError er)
125 jobs[j].subjobComplete = true;
126 jobs[j].clearResponse(); // may contain out of date result data
127 wsInfo.setStatus(jobs[j].jobnum,
128 WebserviceInfo.STATE_STOPPED_ERROR);
129 Cache.log.error("Out of memory when retrieving Job " + j
130 + " id:" + WsUrl + "/" + jobs[j].jobId, er);
131 new jalview.gui.OOMWarning("retrieving result for "
132 + WebServiceName, er);
136 jstate.updateJobPanelState(wsInfo, OutputHeader, jobs[j]);
138 // Decide on overall state based on collected jobs[] states
139 if (jstate.running > 0)
141 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
143 else if (jstate.queuing > 0)
145 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
150 if (jstate.finished > 0)
152 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
154 else if (jstate.error > 0)
156 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
158 else if (jstate.serror > 0)
160 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
168 } catch (InterruptedException e)
171 .debug("Interrupted sleep waiting for next job poll.", e);
173 // System.out.println("I'm alive "+alTitle);
176 if (jobComplete && jobs != null)
178 parseResult(); // tidy up and make results available to user
183 .debug("WebServiceJob poll loop finished with no jobs created.");
184 wsInfo.setFinishedNoResults();
194 public AWSThread(Runnable target)
199 public AWSThread(String name)
204 public AWSThread(ThreadGroup group, Runnable target)
206 super(group, target);
209 public AWSThread(ThreadGroup group, String name)
214 public AWSThread(Runnable target, String name)
219 public AWSThread(ThreadGroup group, Runnable target, String name)
221 super(group, target, name);
225 * query web service for status of job. on return, job.result must not be null
226 * - if it is then it will be assumed that the job status query timed out and
227 * a server exception will be logged.
231 * will be logged as a server exception for this job
233 public abstract void pollJob(AWsJob job) throws Exception;
236 * submit job to web service
240 public abstract void StartJob(AWsJob job);
243 * process the set of AWsJob objects into a set of results, and tidy up.
245 public abstract void parseResult();
248 * helper function to conserve dataset references to sequence objects returned
249 * from web services 1. Propagates AlCodonFrame data from
250 * <code>codonframe</code> to <code>al</code>
251 * TODO: refactor to datamodel
254 public void propagateDatasetMappings(Alignment al)
256 if (codonframe != null)
258 SequenceI[] alignment = al.getSequencesArray();
259 for (int sq = 0; sq < alignment.length; sq++)
261 for (int i = 0; i < codonframe.length; i++)
263 if (codonframe[i] != null
264 && codonframe[i].involvesSequence(alignment[sq]))
266 al.addCodonFrame(codonframe[i]);
267 codonframe[i] = null;
275 public AWSThread(ThreadGroup group, Runnable target, String name,
278 super(group, target, name, stackSize);
283 * @return gap character to use for any alignment generation
285 public char getGapChar()
293 * reference for copying mappings across
295 * gui attachment point
297 * input data for the calculation
298 * @param webServiceName
301 * url of the service being invoked
303 public AWSThread(AlignFrame alignFrame, WebserviceInfo wsinfo,
304 AlignmentView input, String webServiceName, String wsUrl)
306 this(alignFrame, wsinfo, input, wsUrl);
307 WebServiceName = webServiceName;
313 * - reference for copying mappings and display styles across
315 * - gui attachment point
317 * - input data for the calculation
319 * - url of the service being invoked
321 public AWSThread(AlignFrame alframe, WebserviceInfo wsinfo2,
322 AlignmentView alview, String wsurl2)
325 // this.alignFrame = alframe;
326 currentView = alframe.getCurrentView().getAlignment();
327 featureSettings = alframe.getFeatureRenderer().getSettings();
328 defGapChar = alframe.getViewport().getGapCharacter();
329 this.wsInfo = wsinfo2;
334 AlignedCodonFrame[] cf = alframe.getViewport().getAlignment()
338 codonframe = new AlignedCodonFrame[cf.length];
339 System.arraycopy(cf, 0, codonframe, 0, cf.length);