Class ServiceLoaderHelper


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

      • getAllSPIImplementations

        @Nonnull
        @ReturnsMutableCopy
        public static <T> ICommonsList<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

        @Nonnull
        @ReturnsMutableCopy
        public static <T> ICommonsList<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

        @Nonnull
        @ReturnsMutableCopy
        public static <T> ICommonsList<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

        @Nonnull
        @ReturnsMutableCopy
        public static <T> ICommonsList<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

        @Nullable
        public static <T> 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

        @Nullable
        public static <T> 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

        @Nullable
        public static <T> 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

        @Nullable
        public static <T> 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.