S - The service typepublic final class SoftServiceLoader<S> extends java.lang.Object implements java.lang.Iterable<ServiceDefinition<S>>
Variation of ServiceLoader that allows soft loading and conditional loading of
META-INF/services classes.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
META_INF_SERVICES |
| Modifier and Type | Method and Description |
|---|---|
java.util.Optional<ServiceDefinition<S>> |
first() |
java.util.Optional<ServiceDefinition<S>> |
firstOr(java.lang.String alternative,
java.lang.ClassLoader classLoader) |
java.util.Iterator<ServiceDefinition<S>> |
iterator() |
static <S> SoftServiceLoader<S> |
load(java.lang.Class<S> service)
Creates a new
SoftServiceLoader using the thread context loader by default. |
static <S> SoftServiceLoader<S> |
load(java.lang.Class<S> service,
java.lang.ClassLoader loader)
Creates a new
SoftServiceLoader using the given type and class loader. |
static <S> SoftServiceLoader<S> |
load(java.lang.Class<S> service,
java.lang.ClassLoader loader,
java.util.function.Predicate<java.lang.String> condition)
Creates a new
SoftServiceLoader using the given type and class loader. |
protected ServiceDefinition<S> |
newService(java.lang.String name,
java.util.Optional<java.lang.Class> loadedClass) |
public static final java.lang.String META_INF_SERVICES
public static <S> SoftServiceLoader<S> load(java.lang.Class<S> service)
SoftServiceLoader using the thread context loader by default.S - The service generic typeservice - The service typepublic static <S> SoftServiceLoader<S> load(java.lang.Class<S> service, java.lang.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(java.lang.Class<S> service, java.lang.ClassLoader loader, java.util.function.Predicate<java.lang.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 java.util.Optional<ServiceDefinition<S>> first()
public java.util.Optional<ServiceDefinition<S>> firstOr(java.lang.String alternative, java.lang.ClassLoader classLoader)
alternative - An alternative type to use if the this type is not presentclassLoader - The classloaderpublic java.util.Iterator<ServiceDefinition<S>> iterator()
iterator in interface java.lang.Iterable<ServiceDefinition<S>>protected ServiceDefinition<S> newService(java.lang.String name, java.util.Optional<java.lang.Class> loadedClass)
name - The nameloadedClass - The loaded class