JAL-3690 Allow unregistered workers to be run with CalcManager.
authorMateusz <mmzwarowny@dundee.ac.uk>
Mon, 18 Jan 2021 16:50:46 +0000 (17:50 +0100)
committerMateusz <mmzwarowny@dundee.ac.uk>
Fri, 22 Jan 2021 14:11:53 +0000 (15:11 +0100)
src/jalview/workers/AlignCalcManager2.java

index 0f9b8e5..cd190bd 100644 (file)
@@ -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<AlignCalcListener> 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();
   }