From: Mateusz Warowny Date: Thu, 21 Oct 2021 14:52:48 +0000 (+0200) Subject: JAL-3878 Add methods to get and remove workers by their calc name. X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=753bf06169312d77bfde25bad81f87511abe072a JAL-3878 Add methods to get and remove workers by their calc name. --- diff --git a/src/jalview/api/AlignCalcManagerI2.java b/src/jalview/api/AlignCalcManagerI2.java index 0bd6c3c..1e54e3e 100644 --- a/src/jalview/api/AlignCalcManagerI2.java +++ b/src/jalview/api/AlignCalcManagerI2.java @@ -8,7 +8,7 @@ import jalview.datamodel.AlignmentAnnotation; * An abstract manager which controls the execution of interactive jobs. * There is always one instance of AlignCancManager per AlignmenViewport * which runs the jobs, notifies observers and ensures no race conditions. - * + * * @author mmwarowny * */ @@ -19,76 +19,87 @@ public interface AlignCalcManagerI2 * for execution. */ void registerWorker(AlignCalcWorkerI worker); - + /** - * Returns the list of all registered workers or an empty list if + * Returns the list of all registered workers or an empty list if * there are none */ List getWorkers(); - + /** * Returns the list of all workers of a given class or an empty list - * if there are none. The classes are compared using + * if there are none. The classes are compared using * {@ink Class#equals(Object)} rather than {@code instanceof}. */ List getWorkersOfClass(Class cls); - + + /** + * Returns the list of all workers for the given name or an empty list + * if there are none. + */ + List getWorkersForName(String name); + /** * Removes the worker from the scheduler. It does not cancel workers * already scheduled for execution. */ void removeWorker(AlignCalcWorkerI worker); - + /** * Removes all workers which are involved with the given annotation. */ void removeWorkerForAnnotation(AlignmentAnnotation annot); - + /** * Alias of removeWorkerForAnnotation */ default void removeWorkersForAnnotation(AlignmentAnnotation annot) { removeWorkerForAnnotation(annot); } - + + /** + * Removes all workers with matching name. + */ + void removeWorkersForName(String name); + /** * Removes all workers of a given class. The classes are compared using - * {@link Class#equals(Object)}. + * {@link Class#equals(Object)}. */ void removeWorkersOfClass(Class cls); - + /** * Disables a worker so it won't be run during the following restarts. */ void disableWorker(AlignCalcWorkerI worker); - + /** * Restores the previously disabled worker back to operation. */ void enableWorker(AlignCalcWorkerI worker); - + /** * Checks whether the worker is disabled either due to failure or * disabling it manually. */ boolean isDisabled(AlignCalcWorkerI worker); - + /** * Checks whether the given worker is currently running. */ boolean isWorking(AlignCalcWorkerI worker); - + /** * Checks whether the currently running worker (if any) is processing * the given annotation. */ boolean isWorkingWithAnnotation(AlignmentAnnotation annot); - + /** * Checks whether this manager is running a worker. */ boolean isWorking(); - + /** * Scheduler the worker for one-time execution. The worker does not need * to be registered with this manager and will be scheduler regardless @@ -96,29 +107,29 @@ public interface AlignCalcManagerI2 * previous one will be cancelled. */ void startWorker(AlignCalcWorkerI worker); - + /** * Schedules all registered and not-disabled workers for next execution. */ void restartWorkers(); - + /** * Cancels the execution of the worker. Note, if the worker is already * running, this method may, but doesn't have to, interrupt it in * the middle of the work. */ void cancelWorker(AlignCalcWorkerI worker); - + /** * Connect the listener of the worker state changes. */ void addAlignCalcListener(AlignCalcListener listener); - + /** * Remove previously registered worker listener. */ void removeAlignCalcListener(AlignCalcListener listener); - + /** * Stops the manager from running new jobs and cleans-up all * resources such as threads and thread pools. diff --git a/src/jalview/workers/AlignCalcManager2.java b/src/jalview/workers/AlignCalcManager2.java index 8d4796d..5c25668 100644 --- a/src/jalview/workers/AlignCalcManager2.java +++ b/src/jalview/workers/AlignCalcManager2.java @@ -312,6 +312,20 @@ public class AlignCalcManager2 implements AlignCalcManagerI2 } @Override + public List getWorkersForName(String name) + { + List collected = new ArrayList<>(); + for (var worker : getWorkers()) + { + if (worker.getCalcName().equals(name)) + { + collected.add(worker); + } + } + return collected; + } + + @Override public void removeWorker(AlignCalcWorkerI worker) { if (worker.isDeletable()) @@ -351,6 +365,21 @@ public class AlignCalcManager2 implements AlignCalcManagerI2 } @Override + public void removeWorkersForName(String name) + { + synchronized (registered) + { + for (var worker : getWorkers()) + { + if (worker.getCalcName().equals(name)) + { + removeWorker(worker); + } + } + } + } + + @Override public void disableWorker(AlignCalcWorkerI worker) { // Null pointer check might be needed