public class ServiceLoader<S> extends Object implements Iterable<S>
Modifier and Type | Method and Description |
---|---|
S |
createInstance(String line) |
Set<S> |
getProviders() |
Iterator<S> |
iterator()
Lazily loads the available providers of this loader's service.
|
static <S> ServiceLoader<S> |
load(Class<S> service)
Creates a new service loader for the given service type, using the current
thread's context class loader.
|
static <S> ServiceLoader<S> |
load(Class<S> service,
ClassLoader loader)
Creates a new service loader for the given service type and class loader.
|
static <S> ServiceLoader<S> |
loadInstalled(Class<S> service)
Creates a new service loader for the given service type, using the
extension class loader.
|
void |
reload()
Clear this loader's provider cache so that all providers will be reloaded.
|
String |
toString()
Returns a string describing this service.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public static <S> ServiceLoader<S> load(Class<S> service)
ServiceLoader.load(service)</code>
is equivalent to
ServiceLoader.load(service,
Thread.currentThread().getContextClassLoader())
service
- The interface or abstract class representing the servicepublic static <S> ServiceLoader<S> load(Class<S> service, ClassLoader loader)
service
- The interface or abstract class representing the serviceloader
- The class loader to be used to load provider-configuration
files and provider classes, or null if the system class loader
(or, failing that, the bootstrap class loader) is to be usedpublic static <S> ServiceLoader<S> loadInstalled(Class<S> service)
ServiceLoader.load(service, extClassLoader)
If the extension class loader cannot be found then the system class loader
is used; if there is no system class loader then the bootstrap class
loader is used.
This method is intended for use when only installed providers are desired.
The resulting service will only find and load providers that have been
installed into the current Java virtual machine; providers on the
application's class path will be ignored.service
- The interface or abstract class representing the servicepublic void reload()
public S createInstance(String line) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, NoClassDefFoundError, InstantiationException, IllegalAccessException
public Iterator<S> iterator()
Copyright © 2016 JBoss by Red Hat. All rights reserved.