From 268fe732beac21f9addc11f7d94a95ac2243ee31 Mon Sep 17 00:00:00 2001 From: Mateusz Date: Mon, 18 Jan 2021 17:50:46 +0100 Subject: [PATCH] JAL-3690 Allow unregistered workers to be run with CalcManager. --- src/jalview/workers/AlignCalcManager2.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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(); } -- 1.7.10.2