public class ServiceLoader
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
ServiceLoader.RankedService |
Modifier and Type | Field and Description |
---|---|
private static java.util.regex.Pattern |
COMMENT |
private static java.lang.ClassLoader |
contextClassLoader
The default context class loader to use for all threads, or
null to automatically select the context class loader. |
private boolean |
dynamic |
private LoadErrorHandler |
handler |
private java.lang.ClassLoader |
loader |
private static java.util.Map<java.lang.Object,ServiceLoader.RankedService> |
services
The dynamic set of services available in an OSGi environment.
|
private static java.util.regex.Pattern |
WHITESPACE |
Constructor and Description |
---|
ServiceLoader() |
ServiceLoader(java.lang.ClassLoader loader) |
ServiceLoader(java.lang.ClassLoader loader,
LoadErrorHandler handler) |
ServiceLoader(java.lang.ClassLoader loader,
LoadErrorHandler handler,
boolean dynamic) |
Modifier and Type | Method and Description |
---|---|
(package private) static void |
addService(java.lang.Object reference,
java.lang.Object service,
int rank) |
private void |
collectServiceClassNames(java.net.URL resource,
java.util.Collection<java.lang.String> names) |
java.util.Enumeration<java.net.URL> |
findServiceResources(java.lang.String filePattern)
Returns all the available service resources matching the
given pattern, such as all instances of tika-mimetypes.xml
on the classpath, or all org.apache.tika.parser.Parser
service files.
|
(package private) static java.lang.ClassLoader |
getContextClassLoader()
Returns the context class loader of the current thread.
|
LoadErrorHandler |
getLoadErrorHandler()
Returns the load error handler used by this loader.
|
java.io.InputStream |
getResourceAsStream(java.lang.String name)
Returns an input stream for reading the specified resource from the
configured class loader.
|
<T> java.lang.Class<? extends T> |
getServiceClass(java.lang.Class<T> iface,
java.lang.String name)
Loads and returns the named service class that's expected to implement
the given interface.
|
protected <T> java.util.List<java.lang.String> |
identifyStaticServiceProviders(java.lang.Class<T> iface)
Returns the defined static service providers of the given type, without
attempting to load them.
|
boolean |
isDynamic()
Returns if the service loader is static or dynamic
|
<T> java.util.List<T> |
loadDynamicServiceProviders(java.lang.Class<T> iface)
Returns the available dynamic service providers of the given type.
|
<T> java.util.List<T> |
loadServiceProviders(java.lang.Class<T> iface)
Returns all the available service providers of the given type.
|
<T> java.util.List<T> |
loadStaticServiceProviders(java.lang.Class<T> iface)
Returns the available static service providers of the given type.
|
(package private) static java.lang.Object |
removeService(java.lang.Object reference) |
static void |
setContextClassLoader(java.lang.ClassLoader loader)
Sets the context class loader to use for all threads that access
this class.
|
private static volatile java.lang.ClassLoader contextClassLoader
null
to automatically select the context class loader.private static final java.util.Map<java.lang.Object,ServiceLoader.RankedService> services
TikaActivator
class and used as an additional
source of service instances in the loadServiceProviders(Class)
method.private final java.lang.ClassLoader loader
private final LoadErrorHandler handler
private final boolean dynamic
private static final java.util.regex.Pattern COMMENT
private static final java.util.regex.Pattern WHITESPACE
public ServiceLoader(java.lang.ClassLoader loader, LoadErrorHandler handler, boolean dynamic)
public ServiceLoader(java.lang.ClassLoader loader, LoadErrorHandler handler)
public ServiceLoader(java.lang.ClassLoader loader)
public ServiceLoader()
static java.lang.ClassLoader getContextClassLoader()
null
if no loader
is availablepublic static void setContextClassLoader(java.lang.ClassLoader loader)
loader
- default context class loader,
or null
to automatically pick the loaderstatic void addService(java.lang.Object reference, java.lang.Object service, int rank)
static java.lang.Object removeService(java.lang.Object reference)
public boolean isDynamic()
public LoadErrorHandler getLoadErrorHandler()
public java.io.InputStream getResourceAsStream(java.lang.String name)
name
- resource namenull
if the resource was not foundClassLoader.getResourceAsStream(String)
public <T> java.lang.Class<? extends T> getServiceClass(java.lang.Class<T> iface, java.lang.String name) throws java.lang.ClassNotFoundException
LoadErrorHandler
, a
ClassNotFoundException
is always returned for unknown
classes or classes of the wrong typeiface
- service interfacename
- service class namejava.lang.ClassNotFoundException
- if the service class can not be found
or does not implement the given interfaceClass.forName(String, boolean, ClassLoader)
public java.util.Enumeration<java.net.URL> findServiceResources(java.lang.String filePattern)
public <T> java.util.List<T> loadServiceProviders(java.lang.Class<T> iface)
iface
- service provider interfacepublic <T> java.util.List<T> loadDynamicServiceProviders(java.lang.Class<T> iface)
iface
- service provider interfaceprotected <T> java.util.List<java.lang.String> identifyStaticServiceProviders(java.lang.Class<T> iface)
iface
- service provider interfacepublic <T> java.util.List<T> loadStaticServiceProviders(java.lang.Class<T> iface)
iface
- service provider interfaceprivate void collectServiceClassNames(java.net.URL resource, java.util.Collection<java.lang.String> names) throws java.io.IOException
java.io.IOException