JAL-3690 - introduce shutdown method that cleans up manager's resources.
[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    * Removes all workers of a given class. The classes are compared using
49    * {@link Class#equals(Object)}. 
50    */
51   void removeWorkersOfClass(Class<? extends AlignCalcWorkerI> cls);
52   
53   /**
54    * Disables a worker so it won't be run during the following restarts.
55    */
56   void disableWorker(AlignCalcWorkerI worker);
57   
58   /**
59    * Restores the previously disabled worker back to operation.
60    */
61   void enableWorker(AlignCalcWorkerI worker);
62   
63   /**
64    * Checks whether the worker is disabled either due to failure or
65    * disabling it manually.
66    */
67   boolean isDisabled(AlignCalcWorkerI worker);
68   
69   /**
70    * Checks whether the given worker is currently running.
71    */
72   boolean isWorking(AlignCalcWorkerI worker);
73   
74   /**
75    * Checks whether the currently running worker (if any) is processing
76    * the given annotation.
77    */
78   boolean isWorkingWithAnnotation(AlignmentAnnotation annot);
79   
80   /**
81    * Checks whether this manager is running a worker.
82    */
83   boolean isWorking();
84   
85   /**
86    * Scheduler the worker for one-time execution. The worker does not need
87    * to be registered with this manager and will be scheduler regardless
88    * of being disabled. If the worker has already been scheduled, the
89    * previous one will be cancelled.
90    */
91   void startWorker(AlignCalcWorkerI worker);
92   
93   /**
94    * Schedules all registered and not-disabled workers for next execution.
95    */
96   void restartWorkers();
97   
98   /**
99    * Cancels the execution of the worker. Note, if the worker is already
100    * running, this method may, but doesn't have to, interrupt it in
101    * the middle of the work.
102    */
103   void cancelWorker(AlignCalcWorkerI worker);
104   
105   /**
106    * Connect the listener of the worker state changes.
107    */
108   void addAlignCalcListener(AlignCalcListener listener);
109   
110   /**
111    * Remove previously registered worker listener.
112    */
113   void removeAlignCalcListener(AlignCalcListener listener);
114   
115   /**
116    * Stops the manager from running new jobs and cleans-up all
117    * resources such as threads and thread pools.
118    */
119   void shutdown();
120 }