- private class AnnotationWorker implements WebServiceWorkerI
- {
- private long uid = MathUtils.getUID();
-
- private WSJobList jobs = new WSJobList();
-
- private HashMap<Long, Integer> exceptionCount = new HashMap<>();
-
- private static final int MAX_RETRY = 5;
-
- @Override
- public long getUID()
- {
- return uid;
- }
-
- @Override
- public WebServiceI getWebService()
- {
- return service;
- }
-
- @Override
- public List<WSJob> getJobs()
- {
- return Collections.unmodifiableList(jobs);
- }
-
- @Override
- public void start() throws IOException
- {
-
- }
-
- @Override
- public boolean poll() throws IOException
- {
- boolean done = true;
- for (WSJob job : getJobs())
- {
- if (!job.getStatus().isDone() && !job.getStatus().isFailed())
- {
- Cache.log.debug(format("Polling job %s", job));
- try
- {
- service.updateProgress(job);
- exceptionCount.remove(job.getUid());
- } catch (IOException e)
- {
- Cache.log.error(format("Polling job %s failed.", 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 void done()
- {
- // TODO Auto-generated method stub
-
- }
-
- }