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 service 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)
ServiceLoader
serviceClass
all
in interface ServiceLoader
public <T> T onlyOne(Class<T> serviceClass)
ServiceLoader
serviceClass
onlyOne
in interface ServiceLoader
public <T> T onlyOne(Class<T> serviceClass, Class<? extends T> defaultImplementationClass)
ServiceLoader
serviceClass
. 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 ServiceLoader
public ClassLoader getClassLoader()
public void setClassLoader(ClassLoader classLoader)
Copyright © 2013 JBoss by Red Hat. All rights reserved.