Class SimpleServiceLoader

    • Constructor Detail

      • SimpleServiceLoader

        public SimpleServiceLoader()
        Instantiates a new default service loader.
    • Method Detail

      • 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
        Type Parameters:
        T - the service type.
        Parameters:
        service - the service.
        Returns:
        the instance of the given service.
      • checkServicePermission

        protected <T> void checkServicePermission​(Class<T> service,
                                                  String action)
        Checks that an action on a service is permitted.
        Type Parameters:
        T - the service type.
        Parameters:
        service - the service.
        action - the action.
      • createAlternativeImplementation

        @Nullable
        protected <T> T createAlternativeImplementation​(Class<T> service)
                                                 throws ServiceLoadingException
        Creates an implementation for the given service and save it in the cache.
        Type Parameters:
        T - the service type.
        Parameters:
        service - the service.
        Returns:
        a new instance of the given service or null.
        Throws:
        ServiceLoadingException - if an error occurs while instantiating the service instance.
      • putService

        protected <T> void putService​(Class<T> service,
                                      T instance)
        Put a service in the services map in a synchronized context.
        Type Parameters:
        T - the service type.
        Parameters:
        service - the service.
        instance - the service instance.