public final class EnhancedServiceLoader extends Object
ServiceLoader
class.
While the strategy for searching impementations is identical, the following enhancments exist:
load(Class)
method caches the instances for each service. (Use reload(Class)
to get
uncached services.)
Class.newInstance()
(unflexible), but, alternatively,
by configuring a (static) class field or a (static, zero-parameter) method that provide the service instance.
ServiceLoader
implementing the Iterable<S>
, load(Class)
returns an Iterable<S>
.
DEFAULT
is a singelton that loads services through the system class loader.
Modifier and Type | Field and Description |
---|---|
static EnhancedServiceLoader |
DEFAULT
An instance that loads services through the system class loader.
|
Constructor and Description |
---|
EnhancedServiceLoader(ClassLoader loader)
Initializes an instance that will load services through a given class loader.
|
Modifier and Type | Method and Description |
---|---|
<S> Iterable<S> |
load(Class<S> service) |
<S> Iterable<S> |
reload(Class<S> service) |
public static final EnhancedServiceLoader DEFAULT
public EnhancedServiceLoader(ClassLoader loader)
public <S> Iterable<S> load(Class<S> service) throws ServiceConfigurationError
ServiceConfigurationError
public <S> Iterable<S> reload(Class<S> service) throws ServiceConfigurationError
ServiceConfigurationError
- Some of the services are badly configuredCopyright © 2018 Arno Unkrig. All rights reserved.