- All Known Implementing Classes:
DefaultServiceFinder
public interface ServiceFinder
Finds service configurations.
Very similar to ServiceLoader but provides additional methods to
load configurations without being forced to load the classes.
Furthermore, it is not restricted to META-INF/services and the contents
of the configuration file. Supports dedicated classloaders for services as well.
Applications should use the ServiceFactory to allow replacement of the
finder (see Service-annotation)
- Author:
- harald
-
Method Summary
Modifier and TypeMethodDescriptioncreateNameMap(String serviceName) Creates a map of names to mapped services.createNameMapToAll(String serviceName) Creates a map of names to all mapped services.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.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.findServiceURLs(String serviceName) Finds URLs of a service by name.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 name.Gets the default classloader used by this finder.Gets the finder's service path it is responsible for.
-
Method Details
-
getClassLoader
ClassLoader getClassLoader()Gets the default classloader used by this finder.- Returns:
- the classloader, never null
-
getServicePath
String getServicePath()Gets the finder's service path it is responsible for.- Returns:
- the service path
-
findFirstServiceConfiguration
Finds the first service configurations by service name.
If similar configurations appear more than once on the classpath, the first is returned. Useful to override service default implementations.- Parameters:
serviceName- the service name, usually a classname- Returns:
- the service configuration entry, never null
- Throws:
TentackleRuntimeException- if no such service found
-
findFirstServiceProvider
Finds the first service provider by service name.
If similar configurations appear more than once on the classpath, the first is returned. Useful to override service default implementations.- Type Parameters:
T- the service type- Parameters:
service- the service class- Returns:
- the provider class
- Throws:
ClassNotFoundException- if some provider could not be loaded
-
findServiceConfigurations
Finds service configurations by service name.
Iterations over the returned map are ordered by discovery along the classpath.- Parameters:
serviceName- the service name, usually a classname- Returns:
- a map of the configured services and their corresponding URLs
-
findServiceProviders
Finds the service providers by service names.- Type Parameters:
T- the service type- Parameters:
service- the service class- Returns:
- the classes providing this service
- Throws:
ClassNotFoundException- if some provider could not be loaded
-
findServiceURLs
Finds URLs of a service by name.- Parameters:
serviceName- the service name, usually a classname- Returns:
- the service's resource urls
-
findUniqueServiceConfiguration
Finds a unique service configurations by service name.
It is checked that the service is defined exactly once. Useful for factories, singletons and alike.- Parameters:
serviceName- the service name, usually a classname- Returns:
- the service configuration entry
-
findUniqueServiceProvider
Finds the unique service provider by service name.- Type Parameters:
T- the service type- Parameters:
service- the service class- Returns:
- the provider class
- Throws:
ClassNotFoundException- if some provider could not be loaded
-
createNameMap
Creates a map of names to mapped services.They key of the map is the service name. The value is the name providing the service which comes first in the classpath.
- Parameters:
serviceName- the service class- Returns:
- the map
-
createNameMapToAll
Creates a map of names to all mapped services.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.
- Parameters:
serviceName- the service class- Returns:
- the map
-