S
- The service typepublic final class SoftServiceLoader<S> extends Object implements Iterable<ServiceDefinition<S>>
Variation of ServiceLoader
that allows soft loading and conditional loading of
META-INF/services classes.
Modifier and Type | Class and Description |
---|---|
static class |
SoftServiceLoader.Optimizations
Static optimizations for service loaders.
|
static interface |
SoftServiceLoader.ServiceCollector<S>
Service collector for loading services of the given type.
|
static class |
SoftServiceLoader.StaticDefinition<S>
A
ServiceDefinition implementation that uses a MethodHandles.Lookup object to find a public constructor. |
static interface |
SoftServiceLoader.StaticServiceLoader<S>
Service loader that uses
SoftServiceLoader.StaticDefinition . |
Modifier and Type | Field and Description |
---|---|
static String |
META_INF_SERVICES |
Modifier and Type | Method and Description |
---|---|
void |
collectAll(Collection<S> values)
Collects all initialized instances.
|
void |
collectAll(Collection<S> values,
Predicate<S> predicate)
Collects all initialized instances.
|
Optional<ServiceDefinition<S>> |
first() |
Optional<ServiceDefinition<S>> |
firstOr(String alternative,
ClassLoader classLoader) |
Iterator<ServiceDefinition<S>> |
iterator() |
static <S> SoftServiceLoader<S> |
load(Class<S> service)
Creates a new
SoftServiceLoader using the thread context loader by default. |
static <S> SoftServiceLoader<S> |
load(Class<S> service,
ClassLoader loader)
Creates a new
SoftServiceLoader using the given type and class loader. |
static <S> SoftServiceLoader<S> |
load(Class<S> service,
ClassLoader loader,
Predicate<String> condition)
Creates a new
SoftServiceLoader using the given type and class loader. |
static <S> SoftServiceLoader.ServiceCollector<S> |
newCollector(String serviceName,
Predicate<String> lineCondition,
ClassLoader classLoader,
Function<String,S> transformer) |
protected ServiceDefinition<S> |
newService(String name,
Optional<Class> loadedClass) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public static final String META_INF_SERVICES
public static <S> SoftServiceLoader<S> load(Class<S> service)
SoftServiceLoader
using the thread context loader by default.S
- The service generic typeservice
- The service typepublic static <S> SoftServiceLoader<S> load(Class<S> service, ClassLoader loader)
SoftServiceLoader
using the given type and class loader.S
- The service generic typeservice
- The service typeloader
- The class loaderpublic static <S> SoftServiceLoader<S> load(Class<S> service, ClassLoader loader, Predicate<String> condition)
SoftServiceLoader
using the given type and class loader.S
- The service generic typeservice
- The service typeloader
- The class loader to usecondition
- A Predicate
to use to conditionally load the service. The predicate is passed the service class namepublic Optional<ServiceDefinition<S>> first()
public Optional<ServiceDefinition<S>> firstOr(String alternative, ClassLoader classLoader)
alternative
- An alternative type to use if the this type is not presentclassLoader
- The classloaderpublic void collectAll(@NonNull Collection<S> values, @Nullable Predicate<S> predicate)
values
- The collection to be populated.predicate
- The predicated to filter the instances or null if not needed.public void collectAll(@NonNull Collection<S> values)
values
- The collection to be populated.public Iterator<ServiceDefinition<S>> iterator()
iterator
in interface Iterable<ServiceDefinition<S>>
protected ServiceDefinition<S> newService(String name, Optional<Class> loadedClass)
name
- The nameloadedClass
- The loaded classpublic static <S> SoftServiceLoader.ServiceCollector<S> newCollector(String serviceName, Predicate<String> lineCondition, ClassLoader classLoader, Function<String,S> transformer)