Github user mattf-horton commented on a diff in the pull request:

    https://github.com/apache/metron/pull/530#discussion_r133530431
  
    --- Diff: 
bundles-lib/src/main/java/org/apache/metron/bundles/ExtensionManager.java ---
    @@ -103,61 +104,52 @@ private ExtensionManager(){}
       /**
        * @return The singleton instance of the ExtensionManager
        */
    -  public static ExtensionManager getInstance() {
    -    ExtensionManager result = extensionManager;
    -    if (result == null) {
    -      synchronized (ExtensionManager.class) {
    -        result = extensionManager;
    -        if (result == null) {
    -          extensionManager = new ExtensionManager();
    -          result = extensionManager;
    -        }
    +  public static ExtensionManager getInstance() throws 
NotInitializedException {
    +    synchronized (ExtensionManager.class) {
    +      if (extensionManager == null) {
    +        throw new NotInitializedException("ExtensionManager not 
initialized");
           }
    +      return extensionManager;
         }
    -    return result;
       }
     
       /**
        * Uninitializes the ExtensionManager.
        * TESTING ONLY
        */
    +  @VisibleForTesting
       public static void reset() {
         synchronized (ExtensionManager.class) {
    -      getInstance().forgetExtensions();
    +      initContext = null;
           extensionManager = null;
         }
       }
     
    -  private void forgetExtensions() {
    -      initContext = null;
    -  }
    -
    -
       /**
        * Loads all extension class types that can be found on the bootstrap 
classloader and by creating
        * classloaders for all BUNDLES found within the classpath.
        *
        * @param bundles the bundles to scan through in search of extensions
        */
    -  public void init(final List<Class> classes, final Bundle systemBundle, 
final Set<Bundle> bundles)
    +  public static void init(final List<Class> classes, final Bundle 
systemBundle, final Set<Bundle> bundles)
           throws NotInitializedException {
     
    -    InitContext ic = initContext;
    -    if (ic == null) {
    -      synchronized (this) {
    -        ic = initContext;
    -        if (ic == null) {
    -          initContext = discoverExtensions(classes, systemBundle, bundles);
    -          ic = initContext;
    -        }
    +    if (systemBundle == null) {
    +      throw new IllegalArgumentException("systemBundle is required");
    +    }
    +
    +    synchronized (ExtensionManager.class) {
    +      if (extensionManager != null) {
    +        throw new IllegalStateException("ExtensionManager already exists");
           }
    +      extensionManager = new ExtensionManager();
    +      initContext = extensionManager.discoverExtensions(classes, 
systemBundle, bundles);
    --- End diff --
    
    And to protect unsynchronized getInstance():
    ```java
          ExtensionManager em = new ExtensionManager();
          InitContext ic = em.discoverExtensions(classes, systemBundle, 
bundles);
          initContext = ic;
          extensionManager = em;
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to