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.",ex);
102 if (jobs[j].allowedServerExceptions > 0)
104 jobs[j].allowedServerExceptions--;
105 Cache.log.debug("Sleeping after a server exception.");
109 } catch (InterruptedException ex1)
115 Cache.log.warn("Dropping job " + j + " " + jobs[j].jobId);
116 jobs[j].subjobComplete = true;
117 wsInfo.setStatus(jobs[j].jobnum,
118 WebserviceInfo.STATE_STOPPED_SERVERERROR);
120 } catch (OutOfMemoryError er)
123 jobs[j].subjobComplete = true;
124 jobs[j].clearResponse(); // may contain out of date result data
125 wsInfo.setStatus(jobs[j].jobnum,
126 WebserviceInfo.STATE_STOPPED_ERROR);
127 Cache.log.error("Out of memory when retrieving Job " + j
128 + " id:" + WsUrl + "/" + jobs[j].jobId, er);
129 new jalview.gui.OOMWarning("retrieving result for "
130 + WebServiceName, er);
134 jstate.updateJobPanelState(wsInfo, OutputHeader, jobs[j]);
136 // Decide on overall state based on collected jobs[] states
137 if (jstate.running > 0)
139 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
141 else if (jstate.queuing > 0)
143 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
148 if (jstate.finished > 0)
150 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
152 else if (jstate.error > 0)
154 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
156 else if (jstate.serror > 0)
158 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
166 } catch (InterruptedException e)
169 .debug("Interrupted sleep waiting for next job poll.", e);
171 // System.out.println("I'm alive "+alTitle);
174 if (jobComplete && jobs != null)
176 parseResult(); // tidy up and make results available to user
181 .debug("WebServiceJob poll loop finished with no jobs created.");
182 wsInfo.setFinishedNoResults();
192 public AWSThread(Runnable target)
197 public AWSThread(String name)
202 public AWSThread(ThreadGroup group, Runnable target)
204 super(group, target);
207 public AWSThread(ThreadGroup group, String name)
212 public AWSThread(Runnable target, String name)
217 public AWSThread(ThreadGroup group, Runnable target, String name)
219 super(group, target, name);
223 * query web service for status of job. on return, job.result must not be null
224 * - if it is then it will be assumed that the job status query timed out and
225 * a server exception will be logged.
229 * will be logged as a server exception for this job
231 public abstract void pollJob(AWsJob job) throws Exception;
234 * submit job to web service
238 public abstract void StartJob(AWsJob job);
241 * process the set of AWsJob objects into a set of results, and tidy up.
243 public abstract void parseResult();
246 * helper function to conserve dataset references to sequence objects returned
247 * from web services 1. Propagates AlCodonFrame data from
248 * <code>codonframe</code> to <code>al</code>
249 * TODO: refactor to datamodel
252 public void propagateDatasetMappings(Alignment al)
254 if (codonframe != null)
256 SequenceI[] alignment = al.getSequencesArray();
257 for (int sq = 0; sq < alignment.length; sq++)
259 for (int i = 0; i < codonframe.length; i++)
261 if (codonframe[i] != null
262 && codonframe[i].involvesSequence(alignment[sq]))
264 al.addCodonFrame(codonframe[i]);
265 codonframe[i] = null;
273 public AWSThread(ThreadGroup group, Runnable target, String name,
276 super(group, target, name, stackSize);
281 * @return gap character to use for any alignment generation
283 public char getGapChar()
291 * reference for copying mappings across
293 * gui attachment point
295 * input data for the calculation
296 * @param webServiceName
299 * url of the service being invoked
301 public AWSThread(AlignFrame alignFrame, WebserviceInfo wsinfo,
302 AlignmentView input, String webServiceName, String wsUrl)
304 this(alignFrame, wsinfo, input, wsUrl);
305 WebServiceName = webServiceName;
311 * - reference for copying mappings and display styles across
313 * - gui attachment point
315 * - input data for the calculation
317 * - url of the service being invoked
319 public AWSThread(AlignFrame alframe, WebserviceInfo wsinfo2,
320 AlignmentView alview, String wsurl2)
323 // this.alignFrame = alframe;
324 currentView = alframe.getCurrentView().getAlignment();
325 featureSettings = alframe.getFeatureRenderer().getSettings();
326 defGapChar = alframe.getViewport().getGapCharacter();
327 this.wsInfo = wsinfo2;
332 AlignedCodonFrame[] cf = alframe.getViewport().getAlignment()
336 codonframe = new AlignedCodonFrame[cf.length];
337 System.arraycopy(cf, 0, codonframe, 0, cf.length);