JAL-3878 Add methods to get and remove workers by their calc name.
[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    * Returns the list of all workers for the given name or an empty list
38    * if there are none.
39    */
40   List<AlignCalcWorkerI> getWorkersForName(String name);
41
42   /**
43    * Removes the worker from the scheduler. It does not cancel workers
44    * already scheduled for execution.
45    */
46   void removeWorker(AlignCalcWorkerI worker);
47
48   /**
49    * Removes all workers which are involved with the given annotation.
50    */
51   void removeWorkerForAnnotation(AlignmentAnnotation annot);
52
53   /**
54    * Alias of removeWorkerForAnnotation
55    */
56   default void removeWorkersForAnnotation(AlignmentAnnotation annot) {
57     removeWorkerForAnnotation(annot);
58   }
59
60   /**
61    * Removes all workers with matching name.
62    */
63   void removeWorkersForName(String name);
64
65   /**
66    * Removes all workers of a given class. The classes are compared using
67    * {@link Class#equals(Object)}.
68    */
69   void removeWorkersOfClass(Class<? extends AlignCalcWorkerI> cls);
70
71   /**
72    * Disables a worker so it won't be run during the following restarts.
73    */
74   void disableWorker(AlignCalcWorkerI worker);
75
76   /**
77    * Restores the previously disabled worker back to operation.
78    */
79   void enableWorker(AlignCalcWorkerI worker);
80
81   /**
82    * Checks whether the worker is disabled either due to failure or
83    * disabling it manually.
84    */
85   boolean isDisabled(AlignCalcWorkerI worker);
86
87   /**
88    * Checks whether the given worker is currently running.
89    */
90   boolean isWorking(AlignCalcWorkerI worker);
91
92   /**
93    * Checks whether the currently running worker (if any) is processing
94    * the given annotation.
95    */
96   boolean isWorkingWithAnnotation(AlignmentAnnotation annot);
97
98   /**
99    * Checks whether this manager is running a worker.
100    */
101   boolean isWorking();
102
103   /**
104    * Scheduler the worker for one-time execution. The worker does not need
105    * to be registered with this manager and will be scheduler regardless
106    * of being disabled. If the worker has already been scheduled, the
107    * previous one will be cancelled.
108    */
109   void startWorker(AlignCalcWorkerI worker);
110
111   /**
112    * Schedules all registered and not-disabled workers for next execution.
113    */
114   void restartWorkers();
115
116   /**
117    * Cancels the execution of the worker. Note, if the worker is already
118    * running, this method may, but doesn't have to, interrupt it in
119    * the middle of the work.
120    */
121   void cancelWorker(AlignCalcWorkerI worker);
122
123   /**
124    * Connect the listener of the worker state changes.
125    */
126   void addAlignCalcListener(AlignCalcListener listener);
127
128   /**
129    * Remove previously registered worker listener.
130    */
131   void removeAlignCalcListener(AlignCalcListener listener);
132
133   /**
134    * Stops the manager from running new jobs and cleans-up all
135    * resources such as threads and thread pools.
136    */
137   void shutdown();
138 }