Class ServiceHelper

  • All Implemented Interfaces:

    
    public class ServiceHelper
    
                        

    Utility wrapper around ServiceLoader.load().

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      static <T> Collection<T> loadFactories(Class<T> clazz) Load all the services of a given type.
      static <T> Collection<T> loadFactories(Class<T> clazz, ClassLoader classLoader) Load all the services of a given type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • loadFactories

         static <T> Collection<T> loadFactories(Class<T> clazz)

        Load all the services of a given type.

        Parameters:
        clazz - the type of service
        Returns:

        the list of services, empty if none

      • loadFactories

         static <T> Collection<T> loadFactories(Class<T> clazz, ClassLoader classLoader)

        Load all the services of a given type.

        Utility mechanism around ServiceLoader.load()

        • If classloader is null, will try ServiceLoader.load(clazz)
        • If classloader is not null, will try ServiceLoader.load(clazz, classloader)

        If the above return nothing, will fall back to ServiceLoader.load(clazz, $this class loader$)

        Parameters:
        clazz - the type of service
        classLoader - the classloader to use, may be null
        Returns:

        the list of services, empty if none