From: Mateusz Warowny Date: Fri, 9 Jul 2021 10:38:17 +0000 (+0200) Subject: JAL-3690 Remove references to old AlignCalcManager. X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=0b438477b16470202bddfecb54e0587036b37202;p=jalview.git JAL-3690 Remove references to old AlignCalcManager. --- diff --git a/src/jalview/api/AlignCalcManagerI.java b/src/jalview/api/AlignCalcManagerI.java deleted file mode 100644 index 005ecd7..0000000 --- a/src/jalview/api/AlignCalcManagerI.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) - * Copyright (C) $$Year-Rel$$ The Jalview Authors - * - * This file is part of Jalview. - * - * Jalview is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 - * of the License, or (at your option) any later version. - * - * Jalview is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Jalview. If not, see . - * The Jalview Authors are detailed in the 'AUTHORS' file. - */ -package jalview.api; - -import jalview.datamodel.AlignmentAnnotation; - -import java.util.List; - -public interface AlignCalcManagerI -{ - - /** - * tell manager that a worker is initialised and has started to run - * - * @param worker - */ - void notifyStarted(AlignCalcWorkerI worker); - - /** - * tell manager that a thread running worker's run() loop is ready to start - * processing data - * - * @param worker - * @return true if worker should start processing, false if another thread is - * in progress - */ - boolean notifyWorking(AlignCalcWorkerI worker); - - /** - * notify manager that the worker has completed, and results may be ready to - * collect - * - * @param worker - */ - void workerComplete(AlignCalcWorkerI worker); - - /** - * indicate that a worker like this cannot run on the platform and shouldn't - * be started again - * - * @param worker - */ - void disableWorker(AlignCalcWorkerI worker); - - /** - * indicate that a worker like this may be run on the platform. - * - * @param worker - * of class to be removed from the execution blacklist - */ - void enableWorker(AlignCalcWorkerI worker); - - /** - * Answers true if the worker is disabled from running - * - * @param worker - * @return - */ - boolean isDisabled(AlignCalcWorkerI worker); - - /** - * launch a new worker - * - * @param worker - */ - void startWorker(AlignCalcWorkerI worker); - - /** - * - * @param worker - * @return true if the worker is currently running - */ - boolean isWorking(AlignCalcWorkerI worker); - - /** - * if any worker thread is operational, return true! - * - * @return - */ - boolean isWorking(); - - /** - * register a restartable worker - * - * @param worker - */ - void registerWorker(AlignCalcWorkerI worker); - - /** - * restart any registered workers - */ - void restartWorkers(); - - /** - * - * @param alignmentAnnotation - * @return true if a currently registered and working worker indicates its - * involvement with the given alignmentAnnotation - */ - boolean workingInvolvedWith(AlignmentAnnotation alignmentAnnotation); - - /** - * kick any known instances of the given worker class to update their - * annotation - * - * @param workerClass - */ - void updateAnnotationFor(Class workerClass); - - /** - * return any registered workers of the given class - * - * @param workerClass - * @return null or one or more workers of the given class - */ - List getRegisteredWorkersOfClass( - Class workerClass); - - /** - * work out if there is an instance of a worker that is *waiting* to start - * calculating - * - * @param workingClass - * @return true if workingClass is already waiting to calculate. false if it - * is calculating, or not queued. - */ - boolean isPending(AlignCalcWorkerI workingClass); - - /** - * deregister and otherwise remove any registered and working instances of the - * given worker type - * - * @param typeToRemove - */ - void removeWorkersOfClass( - Class typeToRemove); - - /** - * Removes the worker that produces the given annotation, provided it is - * marked as 'deletable'. Some workers may need to continue to run as the - * results of their calculations are needed, e.g. for colour schemes. - * - * @param ann - */ - void removeWorkerForAnnotation(AlignmentAnnotation ann); -} diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 4aec9d2..1a08b1b 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -23,7 +23,6 @@ package jalview.viewmodel; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.analysis.Conservation; import jalview.analysis.TreeModel; -import jalview.api.AlignCalcManagerI; import jalview.api.AlignCalcManagerI2; import jalview.api.AlignCalcWorkerI; import jalview.api.AlignExportSettingsI; @@ -58,7 +57,6 @@ import jalview.util.MapList; import jalview.util.MappingUtils; import jalview.util.MessageManager; import jalview.viewmodel.styles.ViewStyle; -import jalview.workers.AlignCalcManager; import jalview.workers.AlignCalcManager2; import jalview.workers.ComplementConsensusThread; import jalview.workers.ConsensusThread; diff --git a/src/jalview/workers/AlignCalcManager.java b/src/jalview/workers/AlignCalcManager.java deleted file mode 100644 index ec80576..0000000 --- a/src/jalview/workers/AlignCalcManager.java +++ /dev/null @@ -1,410 +0,0 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) - * Copyright (C) $$Year-Rel$$ The Jalview Authors - * - * This file is part of Jalview. - * - * Jalview is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 - * of the License, or (at your option) any later version. - * - * Jalview is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Jalview. If not, see . - * The Jalview Authors are detailed in the 'AUTHORS' file. - */ -package jalview.workers; - -import jalview.api.AlignCalcManagerI; -import jalview.api.AlignCalcWorkerI; -import jalview.bin.Cache; -import jalview.datamodel.AlignmentAnnotation; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class AlignCalcManager implements AlignCalcManagerI -{ - /* - * list of registered workers - */ - private final List restartable = Collections - .synchronizedList(new ArrayList()); - - /* - * types of worker _not_ to run (for example, because they have - * previously thrown errors) - */ - private final List> blackList = Collections - .synchronizedList(new ArrayList>()); - - /* - * global record of calculations in progress - */ - private final List inProgress = Collections - .synchronizedList(new ArrayList()); - - /* - * record of calculations pending or in progress in the current context - */ - private final Map, List> updating = - new Hashtable, List>(); - - /* - * workers that have run to completion so are candidates for visual-only - * update of their results - */ - private HashSet canUpdate = new HashSet<>();; - - private static boolean listContains(List upd, - AlignCalcWorkerI worker) - { - // avoid use of 'Contains' in case - for (AlignCalcWorkerI _otherworker : upd) - { - if (_otherworker == upd) - { - return true; - } - } - return false; - } - @Override - public void notifyStarted(AlignCalcWorkerI worker) - { - synchronized (updating) - { - List upd = updating.get(worker.getClass()); - if (upd == null) - { - updating.put(worker.getClass(), upd = Collections - .synchronizedList(new ArrayList())); - } - synchronized (upd) - { - if (listContains(upd, worker)) - { - Cache.log.debug( - "Ignoring second call to notifyStart for worker " - + worker); - } - else - { - upd.add(worker); - } - } - } - } - - /* - * (non-Javadoc) - * - * @see jalview.api.AlignCalcManagerI#isPending(jalview.api.AlignCalcWorkerI) - */ - @Override - public boolean isPending(AlignCalcWorkerI workingClass) - { - synchronized (updating) - { - List upd = updating.get(workingClass.getClass()); - return upd != null && upd.size() > 1; - } - } - - @Override - public boolean notifyWorking(AlignCalcWorkerI worker) - { - synchronized (inProgress) - { - if (listContains(inProgress, worker)) - { - return false; // worker is already working, so ask caller to wait around - } - else - { - inProgress.add(worker); - } - } - return true; - } - - @Override - public void workerComplete(AlignCalcWorkerI worker) - { - synchronized (inProgress) - { - Cache.log.debug("Worker " + worker + " marked as complete."); - inProgress.remove(worker); - List upd = updating.get(worker.getClass()); - if (upd != null) - { - synchronized (upd) - { - upd.remove(worker); - } - canUpdate.add(worker); - } - } - } - - @Override - public void disableWorker(AlignCalcWorkerI worker) - { - synchronized (blackList) - { - blackList.add(worker.getClass()); - } - } - - @Override - public boolean isDisabled(AlignCalcWorkerI worker) - { - synchronized (blackList) - { - return blackList.contains(worker.getClass()); - } - } - - @Override - public void startWorker(AlignCalcWorkerI worker) - { - if (!isDisabled(worker)) - { - Thread tw = new Thread(() -> { - try - { - worker.run(); - } catch (Throwable e) - { - e.printStackTrace(); - } - }); - tw.setName(worker.getClass().toString()); - tw.start(); - } - } - - @Override - public boolean isWorking(AlignCalcWorkerI worker) - { - synchronized (inProgress) - {// System.err.println("isWorking : worker "+(worker!=null ? - // worker.getClass():"null")+ " "+hashCode()); - return worker != null && inProgress.contains(worker); - } - } - - @Override - public boolean isWorking() - { - synchronized (inProgress) - { - // System.err.println("isWorking "+hashCode()); - return inProgress.size() > 0; - } - } - - public int getQueueLength() { - return inProgress.size(); - } - - @Override - public void registerWorker(AlignCalcWorkerI worker) - { - synchronized (restartable) - { - if (!listContains(restartable, worker)) - { - restartable.add(worker); - } - startWorker(worker); - } - } - - @Override - public void restartWorkers() - { - synchronized (restartable) - { - for (AlignCalcWorkerI worker : restartable) - { - startWorker(worker); - } - } - } - - @Override - public boolean workingInvolvedWith( - AlignmentAnnotation alignmentAnnotation) - { - synchronized (inProgress) - { - for (AlignCalcWorkerI worker : inProgress) - { - if (worker.involves(alignmentAnnotation)) - { - return true; - } - } - } - synchronized (updating) - { - for (List workers : updating.values()) - { - for (AlignCalcWorkerI worker : workers) - { - if (worker.involves(alignmentAnnotation)) - { - return true; - } - } - } - } - return false; - } - - @Override - public void updateAnnotationFor( - Class workerClass) - { - - AlignCalcWorkerI[] workers; - synchronized (canUpdate) - { - workers = canUpdate.toArray(new AlignCalcWorkerI[0]); - } - for (AlignCalcWorkerI worker : workers) - { - if (workerClass.equals(worker.getClass())) - { - worker.updateAnnotation(); - } - } - } - - @Override - public List getRegisteredWorkersOfClass( - Class workerClass) - { - List workingClass = new ArrayList<>(); - synchronized (canUpdate) - { - for (AlignCalcWorkerI worker : canUpdate) - { - if (workerClass.equals(worker.getClass())) - { - workingClass.add(worker); - } - } - } - return (workingClass.size() == 0) ? null : workingClass; - } - - @Override - public void enableWorker(AlignCalcWorkerI worker) - { - synchronized (blackList) - { - blackList.remove(worker.getClass()); - } - } - - @Override - public void removeWorkersOfClass( - Class typeToRemove) - { - List removable = new ArrayList<>(); - Set toremovannot = new HashSet<>(); - synchronized (restartable) - { - for (AlignCalcWorkerI worker : restartable) - { - if (typeToRemove.equals(worker.getClass())) - { - removable.add(worker); - toremovannot.add(worker); - } - } - restartable.removeAll(removable); - } - synchronized (canUpdate) - { - for (AlignCalcWorkerI worker : canUpdate) - { - if (typeToRemove.equals(worker.getClass())) - { - removable.add(worker); - toremovannot.add(worker); - } - } - canUpdate.removeAll(removable); - } - // TODO: finish testing this extension - - /* - * synchronized (inProgress) { // need to kill or mark as dead any running - * threads... (inProgress.get(typeToRemove)); } - * - * if (workers == null) { return; } for (AlignCalcWorkerI worker : workers) - * { - * - * if (isPending(worker)) { worker.abortAndDestroy(); startWorker(worker); } - * else { System.err.println("Pending exists for " + workerClass); } } - */ - } - - /** - * Deletes the worker that update the given annotation, provided it is marked - * as deletable. - */ - @Override - public void removeWorkerForAnnotation(AlignmentAnnotation ann) - { - /* - * first just find those to remove (to avoid - * ConcurrentModificationException) - */ - List toRemove = new ArrayList<>(); - for (AlignCalcWorkerI worker : restartable) - { - if (worker.involves(ann)) - { - if (worker.isDeletable()) - { - toRemove.add(worker); - } - } - } - - /* - * remove all references to deleted workers so any references - * they hold to annotation data can be garbage collected - */ - for (AlignCalcWorkerI worker : toRemove) - { - restartable.remove(worker); - blackList.remove(worker.getClass()); - inProgress.remove(worker); - canUpdate.remove(worker); - synchronized (updating) - { - List upd = updating.get(worker.getClass()); - if (upd != null) - { - upd.remove(worker); - } - } - } - } -} diff --git a/src/jalview/workers/AlignCalcWorker.java b/src/jalview/workers/AlignCalcWorker.java index c94032f..16fc467 100644 --- a/src/jalview/workers/AlignCalcWorker.java +++ b/src/jalview/workers/AlignCalcWorker.java @@ -20,7 +20,6 @@ */ package jalview.workers; -import jalview.api.AlignCalcManagerI; import jalview.api.AlignCalcManagerI2; import jalview.api.AlignCalcWorkerI; import jalview.api.AlignViewportI; diff --git a/test/jalview/gui/AlignViewportTest.java b/test/jalview/gui/AlignViewportTest.java index 9c1a412..f675f68 100644 --- a/test/jalview/gui/AlignViewportTest.java +++ b/test/jalview/gui/AlignViewportTest.java @@ -57,7 +57,6 @@ import jalview.structure.StructureSelectionManager; import jalview.util.MapList; import jalview.viewmodel.AlignmentViewport; import jalview.viewmodel.ViewportRanges; -import jalview.workers.AlignCalcManager; public class AlignViewportTest { @@ -330,7 +329,6 @@ public class AlignViewportTest { try { - System.out.print(((AlignCalcManager) viewport.getCalcManager()).getQueueLength()); wait(50); } catch (InterruptedException e) { diff --git a/test/jalview/workers/AlignCalcManagerTest.java b/test/jalview/workers/AlignCalcManagerTest.java index f0fcdba..fca61d0 100644 --- a/test/jalview/workers/AlignCalcManagerTest.java +++ b/test/jalview/workers/AlignCalcManagerTest.java @@ -24,7 +24,6 @@ import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertTrue; -import jalview.api.AlignCalcManagerI; import jalview.api.AlignCalcManagerI2; import jalview.api.AlignCalcWorkerI; import jalview.api.FeatureRenderer;