Interface ServiceFinder

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 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

      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. 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

      <T> Class<T> findFirstServiceProvider(Class<T> service) throws ClassNotFoundException
      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

      Map<String,URL> findServiceConfigurations(String serviceName)
      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

      <T> Collection<Class<T>> findServiceProviders(Class<T> service) throws ClassNotFoundException
      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

      Collection<URL> findServiceURLs(String serviceName)
      Finds URLs of a service by name.
      Parameters:
      serviceName - the service name, usually a classname
      Returns:
      the service's resource urls
    • findUniqueServiceConfiguration

      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. Useful for factories, singletons and alike.
      Parameters:
      serviceName - the service name, usually a classname
      Returns:
      the service configuration entry
    • findUniqueServiceProvider

      <T> Class<T> findUniqueServiceProvider(Class<T> service) throws ClassNotFoundException
      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

      Map<String,String> createNameMap(String serviceName)
      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

      Map<String,Set<String>> createNameMapToAll(String serviceName)
      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