From: Mateusz Date: Mon, 18 Jan 2021 16:50:46 +0000 (+0100) Subject: JAL-3690 Allow unregistered workers to be run with CalcManager. X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=268fe732beac21f9addc11f7d94a95ac2243ee31;p=jalview.git JAL-3690 Allow unregistered workers to be run with CalcManager. --- diff --git a/src/jalview/workers/AlignCalcManager2.java b/src/jalview/workers/AlignCalcManager2.java index 0f9b8e5..cd190bd 100644 --- a/src/jalview/workers/AlignCalcManager2.java +++ b/src/jalview/workers/AlignCalcManager2.java @@ -69,7 +69,7 @@ public class AlignCalcManager2 implements AlignCalcManagerI2 protected abstract void submit(); - abstract void cancel(); + abstract void cancel(); } @@ -240,14 +240,18 @@ public class AlignCalcManager2 implements AlignCalcManagerI2 private final List listeners = new CopyOnWriteArrayList<>(); + private WorkerManager createManager(AlignCalcWorkerI worker) { + if (worker instanceof PollableAlignCalcWorkerI) + return new PollableWorkerManager((PollableAlignCalcWorkerI) worker); + else + return new SimpleWorkerManager(worker); + } @Override public void registerWorker(AlignCalcWorkerI worker) { Objects.requireNonNull(worker); - WorkerManager manager = (worker instanceof PollableAlignCalcWorkerI) ? - new PollableWorkerManager((PollableAlignCalcWorkerI) worker) : - new SimpleWorkerManager(worker); + WorkerManager manager = createManager(worker); registered.putIfAbsent(worker, manager); startWorker(worker); } @@ -391,7 +395,8 @@ public class AlignCalcManager2 implements AlignCalcManagerI2 var manager = registered.get(worker); if (manager == null) { - throw new NoSuchElementException(); + Cache.log.warn("Starting unregistered worker " + worker); + manager = createManager(worker); } manager.restart(); }