From ed5f6c684bc266a5f1569e6f393e1f7a2a0ddb3b Mon Sep 17 00:00:00 2001 From: Mateusz Waronwy Date: Wed, 21 Oct 2020 15:54:13 +0200 Subject: [PATCH] JAL-3690 Catch and notify about worker cancellation separately. --- src/jalview/api/AlignCalcListener.java | 1 + src/jalview/workers/AlignCalcManager2.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) 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) -- 1.7.10.2