From: Mateusz Waronwy Date: Wed, 21 Oct 2020 13:54:13 +0000 (+0200) Subject: JAL-3690 Catch and notify about worker cancellation separately. X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=ed5f6c684bc266a5f1569e6f393e1f7a2a0ddb3b;p=jalview.git JAL-3690 Catch and notify about worker cancellation separately. --- diff --git a/src/jalview/api/AlignCalcListener.java b/src/jalview/api/AlignCalcListener.java index 96491fa..2e40f87 100644 --- a/src/jalview/api/AlignCalcListener.java +++ b/src/jalview/api/AlignCalcListener.java @@ -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) {} } diff --git a/src/jalview/workers/AlignCalcManager2.java b/src/jalview/workers/AlignCalcManager2.java index dcaff10..e154f0f 100644 --- a/src/jalview/workers/AlignCalcManager2.java +++ b/src/jalview/workers/AlignCalcManager2.java @@ -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)