Class ServiceLoaderHelper

java.lang.Object
com.helger.base.spi.ServiceLoaderHelper
All Implemented Interfaces:
IHasConditionalLogger

@Immutable public final class ServiceLoaderHelper extends Object implements IHasConditionalLogger
ServiceLoader helper class.
Author:
boris, Philip Helger
  • Method Details

    • isSilentMode

      public static boolean isSilentMode()
      Returns:
      true if logging is disabled, false if it is enabled.
    • setSilentMode

      public static boolean setSilentMode(boolean bSilentMode)
      Enable or disable certain regular log messages.
      Parameters:
      bSilentMode - true to disable logging, false to enable logging
      Returns:
      The previous value of the silent mode.
    • getAllSPIImplementations

      @ReturnsMutableCopy public static <T> @NonNull List<T> getAllSPIImplementations(@NonNull Class<T> aSPIClass)
      Uses the ServiceLoader to load all SPI implementations of the passed class
      Type Parameters:
      T - The implementation type to be loaded
      Parameters:
      aSPIClass - The SPI interface class. May not be null.
      Returns:
      A list of all currently available plugins
    • getAllSPIImplementations

      @ReturnsMutableCopy public static <T> @NonNull List<T> getAllSPIImplementations(@NonNull Class<T> aSPIClass, @NonNull ClassLoader aClassLoader)
      Uses the ServiceLoader to load all SPI implementations of the passed class
      Type Parameters:
      T - The implementation type to be loaded
      Parameters:
      aSPIClass - The SPI interface class. May not be null.
      aClassLoader - The class loader to use for the SPI loader. May not be null.
      Returns:
      A list of all currently available plugins
    • getAllSPIImplementations

      @ReturnsMutableCopy public static <T> @NonNull List<T> getAllSPIImplementations(@NonNull Class<T> aSPIClass, @Nullable org.slf4j.Logger aLogger)
      Uses the ServiceLoader to load all SPI implementations of the passed class
      Type Parameters:
      T - The implementation type to be loaded
      Parameters:
      aSPIClass - The SPI interface class. May not be null.
      aLogger - An optional logger to use. May be null.
      Returns:
      A list of all currently available plugins
    • getAllSPIImplementations

      @ReturnsMutableCopy public static <T> @NonNull List<T> getAllSPIImplementations(@NonNull Class<T> aSPIClass, @NonNull ClassLoader aClassLoader, @Nullable org.slf4j.Logger aLogger)
      Uses the ServiceLoader to load all SPI implementations of the passed class
      Type Parameters:
      T - The implementation type to be loaded
      Parameters:
      aSPIClass - The SPI interface class. May not be null.
      aClassLoader - The class loader to use for the SPI loader. May not be null.
      aLogger - An optional logger to use. May be null.
      Returns:
      A collection of all currently available plugins. Never null.
    • getFirstSPIImplementation

      public static <T> @Nullable T getFirstSPIImplementation(@NonNull Class<T> aSPIClass)
      Uses the ServiceLoader to load all SPI implementations of the passed class and return only the first instance.
      Type Parameters:
      T - The implementation type to be loaded
      Parameters:
      aSPIClass - The SPI interface class. May not be null.
      Returns:
      A collection of all currently available plugins. Never null.
    • getFirstSPIImplementation

      public static <T> @Nullable T getFirstSPIImplementation(@NonNull Class<T> aSPIClass, @NonNull ClassLoader aClassLoader)
      Uses the ServiceLoader to load all SPI implementations of the passed class and return only the first instance.
      Type Parameters:
      T - The implementation type to be loaded
      Parameters:
      aSPIClass - The SPI interface class. May not be null.
      aClassLoader - The class loader to use for the SPI loader. May not be null.
      Returns:
      A collection of all currently available plugins. Never null.
    • getFirstSPIImplementation

      public static <T> @Nullable T getFirstSPIImplementation(@NonNull Class<T> aSPIClass, @Nullable org.slf4j.Logger aLogger)
      Uses the ServiceLoader to load all SPI implementations of the passed class and return only the first instance.
      Type Parameters:
      T - The implementation type to be loaded
      Parameters:
      aSPIClass - The SPI interface class. May not be null.
      aLogger - An optional logger to use. May be null.
      Returns:
      A collection of all currently available plugins. Never null.
    • getFirstSPIImplementation

      public static <T> @Nullable T getFirstSPIImplementation(@NonNull Class<T> aSPIClass, @NonNull ClassLoader aClassLoader, @Nullable org.slf4j.Logger aLogger)
      Uses the ServiceLoader to load all SPI implementations of the passed class and return only the first instance.
      Type Parameters:
      T - The implementation type to be loaded
      Parameters:
      aSPIClass - The SPI interface class. May not be null.
      aClassLoader - The class loader to use for the SPI loader. May not be null.
      aLogger - An optional logger to use. May be null.
      Returns:
      A collection of all currently available plugins. Never null.