1 package com.atlassian.plugin.tracker;
2
3 import com.atlassian.plugin.ModuleDescriptor;
4
5 /**
6 * Tracks enabled plugin module descriptors, focusing on fast reads. Patterned off the
7 * {@link org.osgi.util.tracker.ServiceTracker}.
8 *
9 * @since 2.6.0
10 */
11 public interface PluginModuleTracker<M, T extends ModuleDescriptor<M>>
12 {
13 /**
14 * Implement this to customize how and which descriptors are stored
15 */
16 interface Customizer<M, T extends ModuleDescriptor<M>>
17 {
18 /**
19 * Called before adding the descriptor to the internal tracker
20 * @param descriptor The new descriptor
21 * @return The descriptor to track
22 */
23 T adding(T descriptor);
24
25 /**
26 * Called after the descriptor has been removed from the internal tracker
27 * @param descriptor The descriptor that was removed
28 */
29 void removed(T descriptor);
30
31 }
32
33 /**
34 * @return a snapshot of the currently tracked enabled module descriptors
35 */
36 Iterable<T> getModuleDescriptors();
37
38 /**
39 * Gets a snapshot of the currently tracked enabled module instances
40 * @return The module instances
41 */
42 Iterable<M> getModules();
43
44 /**
45 * @return The number of module descriptors currently tracked. Should only be used for reporting purposes as it
46 * only reflects the size at exactly the calling time.
47 */
48 int size();
49
50 /**
51 * Closes the tracker. Ensure you call this, or you may cause a memory leak.
52 */
53 void close();
54 }