-
- public void run() {
-
- while (!jobComplete) {
- int running=0;
- int queuing=0;
- int finished=0;
- int error=0;
- int serror=0;
- for (int j=0; j<jobs.length; j++) {
-
- if (!jobs[j].submitted && jobs[j].seqs.getSeqs()!=null)
- StartJob(jobs[j]);
-
- if (jobs[j].submitted && !jobs[j].subjobComplete) {
- try {
- if ((jobs[j].result = server.getResult(jobs[j].jobId)) == null) {
- throw (new Exception(
- "Timed out when communicating with server\nTry again later.\n"));
- }
- jalview.bin.Cache.log.debug("Job "+j+" Result state " + jobs[j].result.getState()
- + "(ServerError=" + jobs[j].result.isServerError() + ")");
- } catch (Exception ex) {
- // Deal with Transaction exceptions
- wsInfo.appendProgressText(jobs[j].jobnum, "\n" + WebServiceName
- + " Server exception!\n" + ex.getMessage());
- Cache.log.warn(WebServiceName + " job(" + jobs[j].jobnum
- + ") Server exception: " + ex.getMessage());
-
- if (jobs[j].allowedServerExceptions > 0) {
- jobs[j].allowedServerExceptions--;
- Cache.log.debug("Sleeping after a server exception.");
- try {
- Thread.sleep(5000);
- }
- catch (InterruptedException ex1) {
- }
- } else {
- Cache.log.warn("Dropping job "+j+" "+jobs[j].jobId);
- jobs[j].subjobComplete=true;
- wsInfo.setStatus(jobs[j].jobnum, WebserviceInfo.STATE_STOPPED_SERVERERROR);
- }
- }
- catch (OutOfMemoryError er) {
- jobComplete = true;
- jobs[j].subjobComplete=true;
- jobs[j].result=null; // may contain out of date result object
- wsInfo.setStatus(jobs[j].jobnum,
- WebserviceInfo.STATE_STOPPED_ERROR);
- JOptionPane
- .showInternalMessageDialog(
- Desktop.desktop,
- "Out of memory handling result for job !!"
- + "\nSee help files for increasing Java Virtual Machine memory.",
- "Out of memory", JOptionPane.WARNING_MESSAGE);
- Cache.log.error("Out of memory when retrieving Job "+j+" id:" + WsUrl+"/"+jobs[j].jobId, er);
- System.gc();
- }
- }
- if (jobs[j].result!=null) {
- String progheader="";
- // Parse state of job[j]
- if (jobs[j].result.isRunning()) {
- running++;
- wsInfo.setStatus(jobs[j].jobnum,WebserviceInfo.STATE_RUNNING);
- } else if (jobs[j].result.isQueued()) {
- queuing++;
- wsInfo.setStatus(jobs[j].jobnum,WebserviceInfo.STATE_QUEUING);
- } else if (jobs[j].result.isFinished()) {
- finished++;
- jobs[j].subjobComplete = true;
- wsInfo.setStatus(jobs[j].jobnum,WebserviceInfo.STATE_STOPPED_OK);
- } else if (jobs[j].result.isFailed()) {
- progheader += "Job failed.\n";
- jobs[j].subjobComplete=true;
- wsInfo.setStatus(jobs[j].jobnum,WebserviceInfo.STATE_STOPPED_ERROR);
- error++;
- } else if (jobs[j].result.isServerError()) {
- serror++;
- jobs[j].subjobComplete = true;
- wsInfo.setStatus(jobs[j].jobnum,WebserviceInfo.STATE_STOPPED_SERVERERROR);
- } else if (jobs[j].result.isBroken() || jobs[j].result.isFailed()) {
- error++;
- jobs[j].subjobComplete=true;
- wsInfo.setStatus(jobs[j].jobnum,WebserviceInfo.STATE_STOPPED_ERROR);
- }
- // and pass on any sub-job messages to the user
- wsInfo.setProgressText(jobs[j].jobnum, OutputHeader);
- wsInfo.appendProgressText(jobs[j].jobnum, progheader);
- if (jobs[j].result.getStatus() != null) {
- wsInfo.appendProgressText(jobs[j].jobnum, jobs[j].result.getStatus());
- }
- } else {
- if (jobs[j].submitted && jobs[j].subjobComplete) {
- if (jobs[j].allowedServerExceptions==0) {
- serror++;
- } else if (jobs[j].result==null) {
- error++;
- }
- }
- }
- }
- // Decide on overall state based on collected jobs[] states
- if (running>0) {
- wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
- } else if (queuing>0) {
- wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
- } else {
- jobComplete=true;
- if (finished>0) {
- wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
- } else if (error>0) {
- wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
- } else if (serror>0) {
- wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
- }
- }
- if (!jobComplete) {
- try {
- Thread.sleep(5000);
- }
- catch (InterruptedException e) {
- Cache.log.debug("Interrupted sleep waiting for next job poll.",e);
- }
- // System.out.println("I'm alive "+alTitle);
- }
- }
- if (jobComplete) {
- parseResult(); // tidy up and make results available to user
- }