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 | Field and Description |
|---|---|
static String |
META_INF_SERVICES |
| Modifier and Type | Method and Description |
|---|---|
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. |
protected ServiceDefinition<S> |
newService(String name,
Optional<Class> loadedClass) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic 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 Iterator<ServiceDefinition<S>> iterator()
iterator in interface Iterable<ServiceDefinition<S>>protected ServiceDefinition<S> newService(String name, Optional<Class> loadedClass)
name - The nameloadedClass - The loaded class