Class SoftServiceLoader<S>
java.lang.Object
io.micronaut.core.io.service.SoftServiceLoader<S>
- Type Parameters:
S- The service type
- All Implemented Interfaces:
Iterable<ServiceDefinition<S>>
Variation of ServiceLoader that allows soft loading and conditional loading of
META-INF/services classes.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classStatic optimizations for service loaders.static interfaceService collector for loading services of the given type.static final classAServiceDefinitionimplementation that creates instances using the same instantiation strategy asinstantiate(Class): it first attempts to invoke a no-argument constructor via aMethodHandles.Lookupmethod handle, and if that fails due to access restrictions or similar conditions, it falls back to reflective instantiation using.invalid reference
java.lang.Class#getDeclaredConstructor()static interfaceService loader that usesSoftServiceLoader.StaticDefinition. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionCollects all initialized instances.voidcollectAll(Collection<S> values) Collects all initialized instances.voidcollectAll(Collection<S> values, @Nullable Predicate<S> predicate) Collects all initialized instances.collectAll(@Nullable Predicate<S> predicate) Collects all initialized instances.first()firstOr(String alternative, ClassLoader classLoader) iterator()static <S> SoftServiceLoader<S> Creates a newSoftServiceLoaderusing the thread context loader by default.static <S> SoftServiceLoader<S> load(Class<S> service, @Nullable ClassLoader loader) Creates a newSoftServiceLoaderusing the given type and class loader.static <S> SoftServiceLoader<S> load(Class<S> service, @Nullable ClassLoader loader, @Nullable Predicate<String> condition) Creates a newSoftServiceLoaderusing the given type and class loader.static <S> SoftServiceLoader.ServiceCollector<S> newCollector(String serviceName, Predicate<String> lineCondition, ClassLoader classLoader, Function<String, S> transformer) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
META_INF_SERVICES
- See Also:
-
-
Method Details
-
load
Creates a newSoftServiceLoaderusing the thread context loader by default.- Type Parameters:
S- The service generic type- Parameters:
service- The service type- Returns:
- A new service loader
-
load
Creates a newSoftServiceLoaderusing the given type and class loader.- Type Parameters:
S- The service generic type- Parameters:
service- The service typeloader- The class loader- Returns:
- A new service loader
-
load
public static <S> SoftServiceLoader<S> load(Class<S> service, @Nullable ClassLoader loader, @Nullable Predicate<String> condition) Creates a newSoftServiceLoaderusing the given type and class loader.- Type Parameters:
S- The service generic type- Parameters:
service- The service typeloader- The class loader to usecondition- APredicateto use to conditionally load the service. The predicate is passed the service class name- Returns:
- A new service loader
-
disableFork
-
first
- Returns:
- Return the first such instance
-
firstAvailable
- Returns:
- Return the first such instance, or
Optional.empty()if there is no definition or none of the definitions are present on the classpath.
-
firstOr
- Parameters:
alternative- An alternative type to use if this type is not presentclassLoader- The classloader- Returns:
- Return the first such instance
-
collectAll
Collects all initialized instances.- Parameters:
values- The collection to be populated.predicate- The predicated to filter the instances or null if not needed.
-
collectAll
Collects all initialized instances.- Parameters:
values- The collection to be populated.
-
collectAll
-
collectAll
-
iterator
-
newCollector
public static <S> SoftServiceLoader.ServiceCollector<S> newCollector(String serviceName, Predicate<String> lineCondition, ClassLoader classLoader, Function<String, S> transformer)
-