Class CompositeServiceLoader

  • All Implemented Interfaces:
    ServiceLoader
    Direct Known Subclasses:
    ServiceLoaderKF

    public class CompositeServiceLoader
    extends SimpleServiceLoader
    A composite service loader contains a list a service loaders. It searches the requested services in its children sequentially respecting the order they are added.
    • Constructor Detail

      • CompositeServiceLoader

        public CompositeServiceLoader()
        Creates a new empty composite service loader.
    • Method Detail

      • addServiceLoader

        public void addServiceLoader​(ServiceLoader serviceLoader)
        Adds a service loader at the end of the list a service loaders used by this composite service loader.
        Parameters:
        serviceLoader - the service loader to add.
        Throws:
        NullPointerException - if the given service loader is null.
      • getService

        @Nullable
        public <T> T getService​(Class<T> service)
        Description copied from interface: ServiceLoader
        Gets the instance of the given service.

        If there is already an instance in cache, it is returned otherwise a new one is created.

        May return null if the service is not defined.

        Specified by:
        getService in interface ServiceLoader
        Overrides:
        getService in class SimpleServiceLoader
        Type Parameters:
        T - the service type.
        Parameters:
        service - the service.
        Returns:
        the instance of the given service.