Package com.helger.base.spi
Class ServiceLoaderHelper
java.lang.Object
com.helger.base.spi.ServiceLoaderHelper
- All Implemented Interfaces:
IHasConditionalLogger
ServiceLoader helper class.- Author:
- boris, Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> @NonNull List<T> getAllSPIImplementations(@NonNull Class<T> aSPIClass) Uses theServiceLoaderto load all SPI implementations of the passed classstatic <T> @NonNull List<T> getAllSPIImplementations(@NonNull Class<T> aSPIClass, @NonNull ClassLoader aClassLoader) Uses theServiceLoaderto load all SPI implementations of the passed classstatic <T> @NonNull List<T> getAllSPIImplementations(@NonNull Class<T> aSPIClass, @NonNull ClassLoader aClassLoader, @Nullable org.slf4j.Logger aLogger) Uses theServiceLoaderto load all SPI implementations of the passed classstatic <T> @NonNull List<T> getAllSPIImplementations(@NonNull Class<T> aSPIClass, @Nullable org.slf4j.Logger aLogger) Uses theServiceLoaderto load all SPI implementations of the passed classstatic <T> @Nullable TgetFirstSPIImplementation(@NonNull Class<T> aSPIClass) Uses theServiceLoaderto load all SPI implementations of the passed class and return only the first instance.static <T> @Nullable TgetFirstSPIImplementation(@NonNull Class<T> aSPIClass, @NonNull ClassLoader aClassLoader) Uses theServiceLoaderto load all SPI implementations of the passed class and return only the first instance.static <T> @Nullable TgetFirstSPIImplementation(@NonNull Class<T> aSPIClass, @NonNull ClassLoader aClassLoader, @Nullable org.slf4j.Logger aLogger) Uses theServiceLoaderto load all SPI implementations of the passed class and return only the first instance.static <T> @Nullable TgetFirstSPIImplementation(@NonNull Class<T> aSPIClass, @Nullable org.slf4j.Logger aLogger) Uses theServiceLoaderto load all SPI implementations of the passed class and return only the first instance.static booleanstatic booleansetSilentMode(boolean bSilentMode) Enable or disable certain regular log messages.
-
Method Details
-
isSilentMode
public static boolean isSilentMode()- Returns:
trueif logging is disabled,falseif it is enabled.
-
setSilentMode
public static boolean setSilentMode(boolean bSilentMode) Enable or disable certain regular log messages.- Parameters:
bSilentMode-trueto disable logging,falseto enable logging- Returns:
- The previous value of the silent mode.
-
getAllSPIImplementations
@ReturnsMutableCopy public static <T> @NonNull List<T> getAllSPIImplementations(@NonNull Class<T> aSPIClass) Uses theServiceLoaderto 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 benull.- 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 theServiceLoaderto 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 benull.aClassLoader- The class loader to use for the SPI loader. May not benull.- 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 theServiceLoaderto 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 benull.aLogger- An optional logger to use. May benull.- 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 theServiceLoaderto 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 benull.aClassLoader- The class loader to use for the SPI loader. May not benull.aLogger- An optional logger to use. May benull.- Returns:
- A collection of all currently available plugins. Never
null.
-
getFirstSPIImplementation
Uses theServiceLoaderto 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 benull.- 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 theServiceLoaderto 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 benull.aClassLoader- The class loader to use for the SPI loader. May not benull.- 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 theServiceLoaderto 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 benull.aLogger- An optional logger to use. May benull.- 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 theServiceLoaderto 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 benull.aClassLoader- The class loader to use for the SPI loader. May not benull.aLogger- An optional logger to use. May benull.- Returns:
- A collection of all currently available plugins. Never
null.
-