@Service(value=ServiceFinder.class) public class DefaultServiceFinder extends Object implements ServiceFinder
ServiceFinder.
| Constructor and Description |
|---|
DefaultServiceFinder()
Creates a default service finder.
The classloader used is Thread.currentThread().getContextClassLoader().The servicepath is "META_INF/services/". |
DefaultServiceFinder(ClassLoader loader,
String servicePath)
Creates a service finder.
|
DefaultServiceFinder(String servicePath)
Creates a default service finder.
The classloader used is Thread.currentThread().getContextClassLoader(). |
| Modifier and Type | Method and Description |
|---|---|
Map<String,String> |
createNameMap(String serviceName)
Creates a map of classnames to mapped services.
|
Map<String,Set<String>> |
createNameMapToAll(String serviceName)
Creates a map of names to all mapped services.
|
Map.Entry<String,URL> |
findFirstServiceConfiguration(String serviceName)
Finds the first service configurations by service name.
If similar configurations appear more than once on the classpath, the first is returned. |
<T> Class<T> |
findFirstServiceProvider(Class<T> service)
Finds the first service provider by service name.
If similar configurations appear more than once on the classpath, the first is returned. |
Map<String,URL> |
findServiceConfigurations(String serviceName)
Finds service configurations by service name.
Iterations over the returned map are ordered by discovery along the classpath. |
<T> Collection<Class<T>> |
findServiceProviders(Class<T> service)
Finds the service providers by service names.
|
Enumeration<URL> |
findServiceURLs(String serviceName)
Finds URLs of a service by name.
|
Map.Entry<String,URL> |
findUniqueServiceConfiguration(String serviceName)
Finds a unique service configurations by service name.
It is checked that the service is defined exactly once. |
<T> Class<T> |
findUniqueServiceProvider(Class<T> service)
Finds the unique service provider by service class.
|
ClassLoader |
getClassLoader()
Gets the classloader used by this finder.
|
protected ClassLoader |
getClassLoader(String serviceName)
Gets the classloader for the given service name.
|
String |
getServicePath()
Gets the finder' service path it is responsible for.
|
protected String |
normalizeLine(String line)
Normalizes a line.
Trailing and leading spaces are ignored. |
protected void |
parseURL(URL url,
String serviceName,
Map<String,URL> services)
Parses a service URL.
The implementation assumes the provider configuration file in property-file format. |
public DefaultServiceFinder(ClassLoader loader, String servicePath)
loader - optional classloader, null if use ClassLoader.getSystemClassLoader()servicePath - optional service path prefix, null if "META_INF/services/"public DefaultServiceFinder(String servicePath)
Thread.currentThread().getContextClassLoader().servicePath - optional service path prefix, null if "META_INF/services/"public DefaultServiceFinder()
Thread.currentThread().getContextClassLoader()."META_INF/services/".public ClassLoader getClassLoader()
getClassLoader in interface ServiceFinderpublic String getServicePath()
getServicePath in interface ServiceFinderpublic Enumeration<URL> findServiceURLs(String serviceName)
findServiceURLs in interface ServiceFinderserviceName - the service name, usually a classnamepublic Map<String,URL> findServiceConfigurations(String serviceName)
findServiceConfigurations in interface ServiceFinderserviceName - the service name, usually a classnamepublic Map.Entry<String,URL> findFirstServiceConfiguration(String serviceName)
findFirstServiceConfiguration in interface ServiceFinderserviceName - the service name, usually a classnamepublic Map.Entry<String,URL> findUniqueServiceConfiguration(String serviceName)
findUniqueServiceConfiguration in interface ServiceFinderserviceName - the service name, usually a classnamepublic <T> Collection<Class<T>> findServiceProviders(Class<T> service) throws ClassNotFoundException
findServiceProviders in interface ServiceFinderT - the service typeservice - the service classClassNotFoundException - if some provider could not be loadedpublic <T> Class<T> findFirstServiceProvider(Class<T> service) throws ClassNotFoundException
findFirstServiceProvider in interface ServiceFinderT - the service typeservice - the service classClassNotFoundException - if some provider could not be loadedpublic <T> Class<T> findUniqueServiceProvider(Class<T> service) throws ClassNotFoundException
findUniqueServiceProvider in interface ServiceFinderT - the service typeservice - the service classClassNotFoundException - if some provider could not be loadedpublic Map<String,String> createNameMap(String serviceName)
They key of the map is the service name. The value is the name providing the service which comes first in the classpath.
createNameMap in interface ServiceFinderserviceName - the service classpublic Map<String,Set<String>> createNameMapToAll(String serviceName)
They key of the map is the service name. The value is a list of names providing the service ordered by discovery along the classpath.
createNameMapToAll in interface ServiceFinderserviceName - the service classprotected ClassLoader getClassLoader(String serviceName)
serviceName - the service nameprotected void parseURL(URL url, String serviceName, Map<String,URL> services)
ServiceLoader.url - the url of the provider definitionserviceName - the name of the serviceservices - the implementing services mapprotected String normalizeLine(String line)
line - the source lineTentackle - distributed, domain- and model-driven