Class ExtensionsLoader

java.lang.Object
org.apache.druid.guice.ExtensionsLoader

public class ExtensionsLoader extends Object
Manages the loading of Druid extensions. Used in two cases: for CLI extensions from Main, and for DruidModule extensions during initialization. The design, however, should support any kind of extension that may be needed in the future. The extensions are cached so that they can be reported by various REST APIs.
  • Field Details

  • Constructor Details

    • ExtensionsLoader

      @Inject public ExtensionsLoader(ExtensionsConfig config, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
  • Method Details

    • instance

      public static ExtensionsLoader instance(com.google.inject.Injector injector)
    • config

      public ExtensionsConfig config()
    • getLoadedImplementations

      public <T> Collection<T> getLoadedImplementations(Class<T> clazz)
      Returns a collection of implementations loaded.
      Type Parameters:
      T - the service type
      Parameters:
      clazz - service class
    • getLoadedModules

      public Collection<DruidModule> getLoadedModules()
      Returns:
      a collection of implementations loaded.
    • getLoadersMap

      public Map<Pair<File,Boolean>,StandardURLClassLoader> getLoadersMap()
    • getFromExtensions

      public <T> Collection<T> getFromExtensions(Class<T> serviceClass)
      Look for implementations for the given class from both classpath and extensions directory, using ServiceLoader. A user should never put the same two extensions in classpath and extensions directory, if he/she does that, the one that is in the classpath will be loaded, the other will be ignored.
      Parameters:
      serviceClass - The class to look the implementations of (e.g., DruidModule)
      Returns:
      A collection that contains implementations (of distinct concrete classes) of the given class. The order of elements in the returned collection is not specified and not guaranteed to be the same for different calls to getFromExtensions().
    • getModules

      public Collection<DruidModule> getModules()
    • initializeExtensionFilesToLoad

      public void initializeExtensionFilesToLoad()
      Find all the extension files that should be loaded by druid.

      If user explicitly specifies druid.extensions.loadList, then it will look for those extensions under root extensions directory. If one of them is not found, druid will fail loudly.

      If user doesn't specify druid.extension.toLoad (or its value is empty), druid will load all the extensions under the root extensions directory.

    • getExtensionFilesToLoad

      public File[] getExtensionFilesToLoad()
    • getClassLoaderForExtension

      public StandardURLClassLoader getClassLoaderForExtension(File extension, boolean useExtensionClassloaderFirst)
      Parameters:
      extension - The File instance of the extension we want to load
      Returns:
      a StandardURLClassLoader that loads all the jars on which the extension is dependent
    • getClassLoaderForExtension

      public StandardURLClassLoader getClassLoaderForExtension(File extension, boolean useExtensionClassloaderFirst, List<String> extensionDependencyStack)
      Parameters:
      extension - The File instance of the extension we want to load
      useExtensionClassloaderFirst - Whether to return a StandardURLClassLoader that checks extension classloaders first for classes
      extensionDependencyStack - If the extension is requested as a dependency of another extension, a list containing the dependency stack of the dependent extension (for checking circular dependencies). Otherwise this is a empty list.
      Returns:
      a StandardURLClassLoader that loads all the jars on which the extension is dependent
    • getURLsForClasspath

      public static List<URL> getURLsForClasspath(String cp)