public class SpiServiceLoader extends Object implements ServiceLoader
ServiceLoader implementation which uses META-INF/services registration.
In order to register a service, create a file META-INF/services/${service.interface.name}. The content of the file should
list fully qualified names of interface implementations, separated by new line character.| Constructor and Description |
|---|
SpiServiceLoader()
Create an instance of SPI servicSe loader
|
SpiServiceLoader(ClassLoader classLoader)
Creates an instance of SPI service loader.
|
| Modifier and Type | Method and Description |
|---|---|
<T> Collection<T> |
all(Class<T> serviceClass)
Loads all registered services for given
serviceClass. |
ClassLoader |
getClassLoader() |
<T> T |
onlyOne(Class<T> serviceClass)
Loads a registered service for given
serviceClass. |
<T> T |
onlyOne(Class<T> serviceClass,
Class<? extends T> defaultImplementationClass)
Loads a registered service for given
serviceClass. |
void |
setClassLoader(ClassLoader classLoader) |
public SpiServiceLoader()
public SpiServiceLoader(ClassLoader classLoader)
ClassLoader to load service implementations.classLoader - public <T> Collection<T> all(Class<T> serviceClass)
ServiceLoaderserviceClass.all in interface ServiceLoaderserviceClass - The service class.public <T> T onlyOne(Class<T> serviceClass)
ServiceLoaderserviceClass.onlyOne in interface ServiceLoaderserviceClass - The service class.public <T> T onlyOne(Class<T> serviceClass, Class<? extends T> defaultImplementationClass)
ServiceLoaderserviceClass. Reverts to the defaultImplementationClass if no
other service is registered. If defaultImplemenationClass is registered as well, it simply ignores it during
resolution.onlyOne in interface ServiceLoaderserviceClass - The service class.defaultImplementationClass - The default implementation class.public ClassLoader getClassLoader()
public void setClassLoader(ClassLoader classLoader)
Copyright © 2017 JBoss by Red Hat. All rights reserved.