JAL-3690 Catch and notify about worker cancellation separately.
authorMateusz Waronwy <mmzwarowny@dundee.ac.uk>
Wed, 21 Oct 2020 13:54:13 +0000 (15:54 +0200)
committerMateusz Waronwy <mmzwarowny@dundee.ac.uk>
Wed, 21 Oct 2020 13:54:13 +0000 (15:54 +0200)
src/jalview/api/AlignCalcListener.java
src/jalview/workers/AlignCalcManager2.java

index 96491fa..2e40f87 100644 (file)
@@ -7,5 +7,6 @@ public interface AlignCalcListener extends EventListener
   default void workerQueued(AlignCalcWorkerI worker) {}
   default void workerStarted(AlignCalcWorkerI worker) {}
   default void workerCompleted(AlignCalcWorkerI worker) {}
+  default void workerCancelled(AlignCalcWorkerI worker) {}
   default void workerExceptional(AlignCalcWorkerI worker, Throwable throwable) {}
 }
index dcaff10..e154f0f 100644 (file)
@@ -62,6 +62,10 @@ public class AlignCalcManager2 implements AlignCalcManagerI2
         get();
         success = true;
       }
+      catch (CancellationException e) {
+        Cache.log.debug(format("Worker %s cancelled%n", getWorker().getClass().getName()));
+        notifyCancelled(worker);
+      }
       catch (ExecutionException e)
       {
         exception = e.getCause();
@@ -295,6 +299,19 @@ public class AlignCalcManager2 implements AlignCalcManagerI2
       }
     }
   }
+  
+  private void notifyCancelled(AlignCalcWorkerI worker)
+  {
+    for (AlignCalcListener listener : listeners)
+    {
+      try {
+        listener.workerCancelled(worker);
+      } catch (RuntimeException e)
+      {
+        e.printStackTrace();
+      }
+    }
+  }
 
   private void notifyExceptional(AlignCalcWorkerI worker,
           Throwable throwable)