public class ServiceHelper extends Object
ServiceLoader.load()
.Modifier and Type | Method and Description |
---|---|
static <T> Collection<T> |
loadFactories(Class<T> clazz)
Load all the services of a given type.
|
static <T> Collection<T> |
loadFactories(Class<T> clazz,
ClassLoader classLoader)
Load all the services of a given type.
|
static <F,T> T |
loadFactoryService(Class<F> factoryClass,
Function<F,T> factoryBuilder,
Supplier<T> defaultBuilder)
Load a service provided by a service factory.
|
static <T,F extends Supplier<T>> |
loadFactoryService(Class<F> factoryClass,
Supplier<T> defaultBuilder)
Load a service provided by a service factory where the factory is itself a
Supplier . |
static <F> F |
loadService(Class<F> factoryClass,
Supplier<F> defaultBuilder)
Load a service.
|
public static <F> F loadService(Class<F> factoryClass, Supplier<F> defaultBuilder)
F
- the type of factory.factoryClass
- the type of factory.defaultBuilder
- if no factory is found, build the service.public static <F,T> T loadFactoryService(Class<F> factoryClass, Function<F,T> factoryBuilder, Supplier<T> defaultBuilder)
F
- the type of service factory.T
- the type of service.factoryClass
- the type of service factory.factoryBuilder
- given a factory, build the service.defaultBuilder
- if no factory is found, build the service.public static <T,F extends Supplier<T>> T loadFactoryService(Class<F> factoryClass, Supplier<T> defaultBuilder)
Supplier
.T
- the type of service.F
- the type of service factoryfactoryClass
- The type of service factory.defaultBuilder
- if no factory is found, build the service.public static <T> Collection<T> loadFactories(Class<T> clazz)
T
- the type of serviceclazz
- the type of servicepublic static <T> Collection<T> loadFactories(Class<T> clazz, ClassLoader classLoader)
Utility mechanism around ServiceLoader.load()
null
, will try ServiceLoader.load(clazz)
null
, will try ServiceLoader.load(clazz, classloader)
If the above return nothing, will fall back to ServiceLoader.load(clazz, $this class loader$)
T
- the type of serviceclazz
- the type of serviceclassLoader
- the classloader to use, may be nullCopyright © 2024. All rights reserved.