JAL-3690 separate startup and poll code in SeqAnnotationCalcWorker
[jalview.git] / src / jalview / workers / AlignCalcManager2.java
index 7a19321..0057500 100644 (file)
@@ -183,6 +183,8 @@ public class AlignCalcManager2 implements AlignCalcManagerI2
             }
             else if (!completed)
             {
+              Cache.log.debug(format("Polling worker %s",
+                      worker.getClass().getName()));
               if (worker.poll())
               {
                 Cache.log.debug(format("Worker %s finished",
@@ -198,14 +200,12 @@ public class AlignCalcManager2 implements AlignCalcManagerI2
           }
           if (completed)
           {
-            try
-            {
-              future.cancel(false);
-            }
-            catch (NullPointerException ignored)
-            {
-              // extremely unlikely to happen
-            }
+            Cache.log.debug(format("Finalizing completed worker %s",
+                    worker.getClass().getName()));
+            worker.done();
+            // almost impossible, but the future may be null at this point
+            // let it throw NPE to cancel forcefully
+            future.cancel(false);
           }
         }
       };
@@ -224,6 +224,9 @@ public class AlignCalcManager2 implements AlignCalcManagerI2
       task.cancel(false);
       executor.submit(() -> {
         worker.cancel();
+        Cache.log.debug(format("Finalizing cancelled worker %s",
+                worker.getClass().getName()));
+        worker.done();
       });
     }
   }