Github user ottobackwards commented on a diff in the pull request:

    https://github.com/apache/metron/pull/530#discussion_r133079542
  
    --- Diff: 
bundles-lib/src/main/java/org/apache/metron/bundles/ExtensionManager.java ---
    @@ -0,0 +1,540 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.metron.bundles;
    +
    +
    +import com.google.common.collect.ImmutableList;
    +import com.google.common.collect.ImmutableMap;
    +import com.google.common.collect.ImmutableSet;
    +import java.util.ArrayList;
    +import java.util.Collections;
    +import java.util.HashMap;
    +import java.util.HashSet;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Set;
    +import org.apache.commons.vfs2.FileObject;
    +import org.apache.commons.vfs2.FileSystemException;
    +import org.apache.commons.vfs2.FileSystemManager;
    +import org.apache.metron.bundles.bundle.Bundle;
    +import org.apache.metron.bundles.bundle.BundleCoordinates;
    +import org.apache.metron.bundles.bundle.BundleDetails;
    +import org.apache.metron.bundles.util.BundleProperties;
    +import org.apache.metron.bundles.util.DummyFileObject;
    +import org.apache.metron.bundles.util.FileUtils;
    +import org.apache.metron.bundles.util.ImmutableCollectionUtils;
    +import org.apache.metron.bundles.util.StringUtils;
    +import 
org.apache.metron.bundles.annotation.behavior.RequiresInstanceClassLoading;
    +
    +import org.atteo.classindex.ClassIndex;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.io.IOException;
    +import java.lang.reflect.Modifier;
    +import java.net.URI;
    +import java.net.URISyntaxException;
    +import java.net.URL;
    +import java.net.URLClassLoader;
    +import java.util.concurrent.ConcurrentHashMap;
    +
    +/**
    + * A Singleton class for scanning through the classpath to load all 
extension components using
    + * the ClassIndex and running through all classloaders (root, BUNDLEs).
    + *
    + *
    + * @ThreadSafe - is immutable
    + */
    +@SuppressWarnings("rawtypes")
    +public class ExtensionManager {
    +
    +  private static volatile ExtensionManager extensionManager;
    +  private volatile InitContext initContext;
    +
    +  private static final Logger logger = 
LoggerFactory.getLogger(ExtensionManager.class);
    +
    +  public static final BundleCoordinates SYSTEM_BUNDLE_COORDINATE = new 
BundleCoordinates(
    +      BundleCoordinates.DEFAULT_GROUP, "system", 
BundleCoordinates.DEFAULT_VERSION);
    +
    +  private static final class InitContext {
    +
    +    // Maps a service definition (interface) to those classes that 
implement the interface
    +    private final Map<Class, Set<Class>> definitionMap;
    +    private final Map<String, List<Bundle>> classNameBundleLookup;
    +    private final Map<BundleCoordinates, Bundle> 
bundleCoordinateBundleLookup;
    +    private final Map<ClassLoader, Bundle> classLoaderBundleLookup;
    +    private final Set<String> requiresInstanceClassLoading;
    +    private final Map<String, ClassLoader> instanceClassloaderLookup;
    +
    +    private InitContext(Map<Class, Set<Class>> definitionMap,
    +        Map<String, List<Bundle>> classNameBundleLookup,
    +        Map<BundleCoordinates, Bundle> bundleCoordinateBundleLookup,
    +        Map<ClassLoader, Bundle> classLoaderBundleLookup,
    +        Set<String> requiresInstanceClassLoading,
    +        Map<String, ClassLoader> instanceClassloaderLookup) {
    +
    +      this.definitionMap = 
ImmutableCollectionUtils.immutableMapOfSets(definitionMap);
    +      this.classNameBundleLookup = ImmutableCollectionUtils
    +          .immutableMapOfLists(classNameBundleLookup);
    +      this.bundleCoordinateBundleLookup = 
ImmutableMap.copyOf(bundleCoordinateBundleLookup);
    +      this.classLoaderBundleLookup = 
ImmutableMap.copyOf(classLoaderBundleLookup);
    +      this.requiresInstanceClassLoading = 
ImmutableSet.copyOf(requiresInstanceClassLoading);
    +      this.instanceClassloaderLookup = new 
ConcurrentHashMap<>(instanceClassloaderLookup);
    +    }
    +  }
    +
    +  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;
    +        }
    +      }
    +    }
    +    return result;
    +  }
    +
    +  /**
    +   * Uninitializes the ExtensionManager.
    +   * TESTING ONLY
    +   */
    +  public static void reset() {
    +    synchronized (ExtensionManager.class) {
    +      getInstance().forgetExtensions();
    +      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)
    +      throws NotInitializedException {
    +
    +    InitContext ic = initContext;
    +    if (ic == null) {
    +      synchronized (this) {
    --- End diff --
    
    done


---
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