From: Mateusz Warowny Date: Tue, 23 Nov 2021 13:53:00 +0000 (+0100) Subject: JAL-3878 Move common poll method to upper class AbstractWorker X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=841485c28403b4a8e00c9bddae9caa9411667b8a;p=jalview.git JAL-3878 Move common poll method to upper class AbstractWorker --- diff --git a/src/jalview/ws2/operations/AbstractPollableWorker.java b/src/jalview/ws2/operations/AbstractPollableWorker.java index 973199e..b4311b9 100644 --- a/src/jalview/ws2/operations/AbstractPollableWorker.java +++ b/src/jalview/ws2/operations/AbstractPollableWorker.java @@ -14,51 +14,6 @@ import jalview.ws2.WSJobStatus; public abstract class AbstractPollableWorker extends AbstractWorker implements PollableTaskI { - - private Map exceptionCount = new HashMap<>(); - - private static final int MAX_RETRY = 5; - - @Override - public boolean poll() - { - boolean done = true; - for (WSJob job : getJobs()) - { - if (!job.getStatus().isDone() && !job.getStatus().isFailed()) - { - Cache.log.debug(format("Polling job %s.", job)); - try - { - getOperation().getWebService().updateProgress(job); - exceptionCount.remove(job.getUid()); - } catch (IOException e) - { - Cache.log.error(format("Polling job %s failed.", job), e); - listeners.firePollException(job, e); - int count = exceptionCount.getOrDefault(job.getUid(), - MAX_RETRY); - if (--count <= 0) - { - job.setStatus(WSJobStatus.SERVER_ERROR); - Cache.log.warn(format( - "Attempts limit exceeded. Droping job %s.", job)); - } - exceptionCount.put(job.getUid(), count); - } catch (OutOfMemoryError e) - { - job.setStatus(WSJobStatus.BROKEN); - Cache.log.error( - format("Out of memory when retrieving job %s", job), e); - } - Cache.log.debug( - format("Job %s status is %s", job, job.getStatus())); - } - done &= job.getStatus().isDone() || job.getStatus().isFailed(); - } - return done; - } - @Override public boolean isDone() { diff --git a/src/jalview/ws2/operations/AbstractWorker.java b/src/jalview/ws2/operations/AbstractWorker.java index 926b7ce..5186849 100644 --- a/src/jalview/ws2/operations/AbstractWorker.java +++ b/src/jalview/ws2/operations/AbstractWorker.java @@ -1,7 +1,15 @@ package jalview.ws2.operations; +import static java.lang.String.format; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import jalview.bin.Cache; import jalview.util.MathUtils; import jalview.ws2.WSJob; +import jalview.ws2.WSJobStatus; public abstract class AbstractWorker implements WebServiceWorkerI { @@ -17,4 +25,48 @@ public abstract class AbstractWorker implements WebServiceWorkerI { listeners.addListener(listener); } + + + private Map exceptionCount = new HashMap<>(); + + private static final int MAX_RETRY = 5; + + public boolean poll() + { + boolean done = true; + for (WSJob job : getJobs()) + { + if (!job.getStatus().isDone() && !job.getStatus().isFailed()) + { + Cache.log.debug(format("Polling job %s.", job)); + try + { + getOperation().getWebService().updateProgress(job); + exceptionCount.remove(job.getUid()); + } catch (IOException e) + { + Cache.log.error(format("Polling job %s failed.", job), e); + listeners.firePollException(job, e); + int count = exceptionCount.getOrDefault(job.getUid(), + MAX_RETRY); + if (--count <= 0) + { + job.setStatus(WSJobStatus.SERVER_ERROR); + Cache.log.warn(format( + "Attempts limit exceeded. Droping job %s.", job)); + } + exceptionCount.put(job.getUid(), count); + } catch (OutOfMemoryError e) + { + job.setStatus(WSJobStatus.BROKEN); + Cache.log.error( + format("Out of memory when retrieving job %s", job), e); + } + Cache.log.debug( + format("Job %s status is %s", job, job.getStatus())); + } + done &= job.getStatus().isDone() || job.getStatus().isFailed(); + } + return done; + } }