Package io.micronaut.core.io.service
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
Modifier and TypeClassDescriptionstatic final class
Static optimizations for service loaders.static interface
Service collector for loading services of the given type.static final class
AServiceDefinition
implementation that uses aMethodHandles.Lookup
object to find a public constructor.static interface
Service loader that usesSoftServiceLoader.StaticDefinition
. -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionCollects all initialized instances.void
collectAll
(@NonNull Collection<S> values) Collects all initialized instances.void
collectAll
(@NonNull Collection<S> values, @Nullable Predicate<S> predicate) Collects all initialized instances.collectAll
(Predicate<S> predicate) Collects all initialized instances.first()
firstOr
(String alternative, ClassLoader classLoader) iterator()
static <S> SoftServiceLoader<S>
Creates a newSoftServiceLoader
using the thread context loader by default.static <S> SoftServiceLoader<S>
load
(Class<S> service, ClassLoader loader) Creates a newSoftServiceLoader
using the given type and class loader.static <S> SoftServiceLoader<S>
load
(Class<S> service, ClassLoader loader, Predicate<String> condition) Creates a newSoftServiceLoader
using 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
META_INF_SERVICES
- See Also:
-
-
Method Details
-
load
Creates a newSoftServiceLoader
using 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 newSoftServiceLoader
using 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, ClassLoader loader, Predicate<String> condition) Creates a newSoftServiceLoader
using the given type and class loader.- Type Parameters:
S
- The service generic type- Parameters:
service
- The service typeloader
- The class loader to usecondition
- APredicate
to 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 the this type is not presentclassLoader
- The classloader- Returns:
- Return the first such instance
-
collectAll
public void collectAll(@NonNull @NonNull Collection<S> values, @Nullable @Nullable Predicate<S> predicate) 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
Collects all initialized instances.- Returns:
- The instances of this service.
-
collectAll
Collects all initialized instances.- Parameters:
predicate
- The predicated to filter the instances or null if not needed.- Returns:
- The instances of this service.
-
iterator
-
newCollector
public static <S> SoftServiceLoader.ServiceCollector<S> newCollector(String serviceName, Predicate<String> lineCondition, ClassLoader classLoader, Function<String, S> transformer)
-