JAL-3690 Introduce AlignCalcManager2 tests.
[jalview.git] / src / jalview / api / AlignCalcManagerI2.java
1 package jalview.api;
2
3 import java.util.List;
4
5 import jalview.datamodel.AlignmentAnnotation;
6
7 /**
8  * An abstract manager which controls the execution of interactive jobs.
9  * There is always one instance of AlignCancManager per AlignmenViewport
10  * which runs the jobs, notifies observers and ensures no race conditions.
11  * 
12  * @author mmwarowny
13  *
14  */
15 public interface AlignCalcManagerI2
16 {
17   /**
18    * Registers the worker with the manager and immediately schedules it
19    * for execution.
20    */
21   void registerWorker(AlignCalcWorkerI worker);
22   
23   /**
24    * Returns the list of all registered workers or an empty list if 
25    * there are none
26    */
27   List<AlignCalcWorkerI> getWorkers();
28   
29   /**
30    * Returns the list of all workers of a given class or an empty list
31    * if there are none. The classes are compared using 
32    * {@ink Class#equals(Object)} rather than {@code instanceof}.
33    */
34   List<AlignCalcWorkerI> getWorkersOfClass(Class<? extends AlignCalcWorkerI> cls);
35   
36   /**
37    * Removes the worker from the scheduler. It does not cancel workers
38    * already scheduled for execution.
39    */
40   void removeWorker(AlignCalcWorkerI worker);
41   
42   /**
43    * Removes all workers which are involved with the given annotation.
44    */
45   void removeWorkerForAnnotation(AlignmentAnnotation annot);
46   
47   /**
48    * Alias of removeWorkerForAnnotation
49    */
50   default void removeWorkersForAnnotation(AlignmentAnnotation annot) {
51     removeWorkerForAnnotation(annot);
52   }
53   
54   /**
55    * Removes all workers of a given class. The classes are compared using
56    * {@link Class#equals(Object)}. 
57    */
58   void removeWorkersOfClass(Class<? extends AlignCalcWorkerI> cls);
59   
60   /**
61    * Disables a worker so it won't be run during the following restarts.
62    */
63   void disableWorker(AlignCalcWorkerI worker);
64   
65   /**
66    * Restores the previously disabled worker back to operation.
67    */
68   void enableWorker(AlignCalcWorkerI worker);
69   
70   /**
71    * Checks whether the worker is disabled either due to failure or
72    * disabling it manually.
73    */
74   boolean isDisabled(AlignCalcWorkerI worker);
75   
76   /**
77    * Checks whether the given worker is currently running.
78    */
79   boolean isWorking(AlignCalcWorkerI worker);
80   
81   /**
82    * Checks whether the currently running worker (if any) is processing
83    * the given annotation.
84    */
85   boolean isWorkingWithAnnotation(AlignmentAnnotation annot);
86   
87   /**
88    * Checks whether this manager is running a worker.
89    */
90   boolean isWorking();
91   
92   /**
93    * Scheduler the worker for one-time execution. The worker does not need
94    * to be registered with this manager and will be scheduler regardless
95    * of being disabled. If the worker has already been scheduled, the
96    * previous one will be cancelled.
97    */
98   void startWorker(AlignCalcWorkerI worker);
99   
100   /**
101    * Schedules all registered and not-disabled workers for next execution.
102    */
103   void restartWorkers();
104   
105   /**
106    * Cancels the execution of the worker. Note, if the worker is already
107    * running, this method may, but doesn't have to, interrupt it in
108    * the middle of the work.
109    */
110   void cancelWorker(AlignCalcWorkerI worker);
111   
112   /**
113    * Connect the listener of the worker state changes.
114    */
115   void addAlignCalcListener(AlignCalcListener listener);
116   
117   /**
118    * Remove previously registered worker listener.
119    */
120   void removeAlignCalcListener(AlignCalcListener listener);
121   
122   /**
123    * Stops the manager from running new jobs and cleans-up all
124    * resources such as threads and thread pools.
125    */
126   void shutdown();
127 }