View Javadoc
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 {@code ServiceTracker}.
7    *
8    * @since 2.6.0
9    */
10  public interface PluginModuleTracker<M, T extends ModuleDescriptor<M>> {
11      /**
12       * Implement this to customize how and which descriptors are stored
13       */
14      interface Customizer<M, T extends ModuleDescriptor<M>> {
15          /**
16           * Called before adding the descriptor to the internal tracker
17           *
18           * @param descriptor The new descriptor
19           * @return The descriptor to track
20           */
21          T adding(T descriptor);
22  
23          /**
24           * Called after the descriptor has been removed from the internal tracker
25           *
26           * @param descriptor The descriptor that was removed
27           */
28          void removed(T descriptor);
29  
30      }
31  
32      /**
33       * @return a snapshot of the currently tracked enabled module descriptors
34       */
35      Iterable<T> getModuleDescriptors();
36  
37      /**
38       * Gets a snapshot of the currently tracked enabled module instances
39       *
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  }