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 if (Cache.log.isDebugEnabled())
99 // Deal with Transaction exceptions
100 wsInfo.appendProgressText(jobs[j].jobnum, "\n" + WebServiceName
101 + " Server exception!\n" + ex.getMessage());
102 Cache.log.warn(WebServiceName + " job(" + jobs[j].jobnum
103 + ") Server exception: " + ex.getMessage());
105 if (jobs[j].allowedServerExceptions > 0)
107 jobs[j].allowedServerExceptions--;
108 Cache.log.debug("Sleeping after a server exception.");
112 } catch (InterruptedException ex1)
118 Cache.log.warn("Dropping job " + j + " " + jobs[j].jobId);
119 jobs[j].subjobComplete = true;
120 wsInfo.setStatus(jobs[j].jobnum,
121 WebserviceInfo.STATE_STOPPED_SERVERERROR);
123 } catch (OutOfMemoryError er)
126 jobs[j].subjobComplete = true;
127 jobs[j].clearResponse(); // may contain out of date result data
128 wsInfo.setStatus(jobs[j].jobnum,
129 WebserviceInfo.STATE_STOPPED_ERROR);
130 Cache.log.error("Out of memory when retrieving Job " + j
131 + " id:" + WsUrl + "/" + jobs[j].jobId, er);
132 new jalview.gui.OOMWarning("retrieving result for "
133 + WebServiceName, er);
137 jstate.updateJobPanelState(wsInfo, OutputHeader, jobs[j]);
139 // Decide on overall state based on collected jobs[] states
140 if (jstate.running > 0)
142 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
144 else if (jstate.queuing > 0)
146 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
151 if (jstate.finished > 0)
153 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
155 else if (jstate.error > 0)
157 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
159 else if (jstate.serror > 0)
161 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
169 } catch (InterruptedException e)
172 .debug("Interrupted sleep waiting for next job poll.", e);
174 // System.out.println("I'm alive "+alTitle);
177 if (jobComplete && jobs != null)
179 parseResult(); // tidy up and make results available to user
184 .debug("WebServiceJob poll loop finished with no jobs created.");
185 wsInfo.setFinishedNoResults();
195 public AWSThread(Runnable target)
200 public AWSThread(String name)
205 public AWSThread(ThreadGroup group, Runnable target)
207 super(group, target);
210 public AWSThread(ThreadGroup group, String name)
215 public AWSThread(Runnable target, String name)
220 public AWSThread(ThreadGroup group, Runnable target, String name)
222 super(group, target, name);
226 * query web service for status of job. on return, job.result must not be null
227 * - if it is then it will be assumed that the job status query timed out and
228 * a server exception will be logged.
232 * will be logged as a server exception for this job
234 public abstract void pollJob(AWsJob job) throws Exception;
237 * submit job to web service
241 public abstract void StartJob(AWsJob job);
244 * process the set of AWsJob objects into a set of results, and tidy up.
246 public abstract void parseResult();
249 * helper function to conserve dataset references to sequence objects returned
250 * from web services 1. Propagates AlCodonFrame data from
251 * <code>codonframe</code> to <code>al</code>
252 * TODO: refactor to datamodel
255 public void propagateDatasetMappings(Alignment al)
257 if (codonframe != null)
259 SequenceI[] alignment = al.getSequencesArray();
260 for (int sq = 0; sq < alignment.length; sq++)
262 for (int i = 0; i < codonframe.length; i++)
264 if (codonframe[i] != null
265 && codonframe[i].involvesSequence(alignment[sq]))
267 al.addCodonFrame(codonframe[i]);
268 codonframe[i] = null;
276 public AWSThread(ThreadGroup group, Runnable target, String name,
279 super(group, target, name, stackSize);
284 * @return gap character to use for any alignment generation
286 public char getGapChar()
294 * reference for copying mappings across
296 * gui attachment point
298 * input data for the calculation
299 * @param webServiceName
302 * url of the service being invoked
304 public AWSThread(AlignFrame alignFrame, WebserviceInfo wsinfo,
305 AlignmentView input, String webServiceName, String wsUrl)
307 this(alignFrame, wsinfo, input, wsUrl);
308 WebServiceName = webServiceName;
314 * - reference for copying mappings and display styles across
316 * - gui attachment point
318 * - input data for the calculation
320 * - url of the service being invoked
322 public AWSThread(AlignFrame alframe, WebserviceInfo wsinfo2,
323 AlignmentView alview, String wsurl2)
326 // this.alignFrame = alframe;
327 currentView = alframe.getCurrentView().getAlignment();
328 featureSettings = alframe.getFeatureRenderer().getSettings();
329 defGapChar = alframe.getViewport().getGapCharacter();
330 this.wsInfo = wsinfo2;
335 AlignedCodonFrame[] cf = alframe.getViewport().getAlignment()
339 codonframe = new AlignedCodonFrame[cf.length];
340 System.arraycopy(cf, 0, codonframe, 0, cf.length);