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 * Implement this to customize how and which descriptors are stored
14 */
15 interface Customizer<M, T extends ModuleDescriptor<M>> {
16 /**
17 * Called before adding the descriptor to the internal tracker
18 *
19 * @param descriptor The new descriptor
20 * @return The descriptor to track
21 */
22 T adding(T descriptor);
23
24 /**
25 * Called after the descriptor has been removed from the internal tracker
26 *
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 *
41 * @return The module instances
42 */
43 Iterable<M> getModules();
44
45 /**
46 * @return The number of module descriptors currently tracked. Should only be used for reporting purposes as it
47 * only reflects the size at exactly the calling time.
48 */
49 int size();
50
51 /**
52 * Closes the tracker. Ensure you call this, or you may cause a memory leak.
53 */
54 void close();
55 }