Class ServiceLoaderUtils

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <S> java.util.ServiceLoader<S> load​(java.lang.Class<S> serviceType, java.lang.ClassLoader classLoader, boolean cached)  
      static <S> S loadFirstService​(java.lang.Class<S> serviceType)
      Load the first instance of Service interface instances list
      static <S> S loadFirstService​(java.lang.Class<S> serviceType, boolean cached)
      Load the first instance of Service interface instances list
      static <S> S loadFirstService​(java.lang.Class<S> serviceType, java.lang.ClassLoader classLoader)
      Load the first instance of Service interface instances list
      static <S> S loadFirstService​(java.lang.Class<S> serviceType, java.lang.ClassLoader classLoader, boolean cached)
      Load the first instance of Service interface instances list
      static <S> S loadLastService​(java.lang.Class<S> serviceType)
      Loads the last in the list of objects implementing the service type, if present.
      static <S> S loadLastService​(java.lang.Class<S> serviceType, boolean cached)
      Loads the last in the list of objects implementing the service type, if present.
      static <S> S loadLastService​(java.lang.Class<S> serviceType, java.lang.ClassLoader classLoader)
      Loads the last in the list of objects implementing the service type, if present.
      static <S> S loadLastService​(java.lang.Class<S> serviceType, java.lang.ClassLoader classLoader, boolean cached)
      Loads the last in the list of objects implementing the service type, if present.
      static <S> S[] loadServices​(java.lang.Class<S> serviceType)
      Using the hierarchy of ClassLoader, each level of ClassLoader ( ClassLoader , its parent ClassLoader and higher) will be able to load the configuration file META-INF/services serviceType under its class path.
      static <S> S[] loadServices​(java.lang.Class<S> serviceType, boolean cached)
      Using the hierarchy of ClassLoader, each level of ClassLoader ( ClassLoader , its parent ClassLoader and higher) will be able to load the configuration file META-INF/services serviceType under its class path.
      static <S> S[] loadServices​(java.lang.Class<S> serviceType, java.lang.ClassLoader classLoader)
      Using the hierarchy of ClassLoader, each level of ClassLoader ( ClassLoader , its parent ClassLoader and higher) will be able to load the configuration file META-INF/services serviceType under its class path.
      static <S> S[] loadServices​(java.lang.Class<S> serviceType, java.lang.ClassLoader classLoader, boolean cached)
      Using the hierarchy of ClassLoader, each level of ClassLoader ( ClassLoader , its parent ClassLoader and higher) will be able to load the configuration file META-INF/services serviceType under its class path.
      static <S> java.util.List<S> loadServicesList​(java.lang.Class<S> serviceType)
      Using the hierarchy of ClassLoader, each level of ClassLoader ( ClassLoader , its parent ClassLoader and higher) will be able to load the configuration file META-INF/services serviceType under its class path.
      static <S> java.util.List<S> loadServicesList​(java.lang.Class<S> serviceType, boolean cached)
      Using the hierarchy of ClassLoader, each level of ClassLoader ( ClassLoader , its parent ClassLoader and higher) will be able to load the configuration file META-INF/services serviceType under its class path.
      static <S> java.util.List<S> loadServicesList​(java.lang.Class<S> serviceType, java.lang.ClassLoader classLoader)
      Using the hierarchy of ClassLoader, each level of ClassLoader ( ClassLoader , its parent ClassLoader and higher) will be able to load the configuration file META-INF/services serviceType under its class path.
      static <S> java.util.List<S> loadServicesList​(java.lang.Class<S> serviceType, java.lang.ClassLoader classLoader, boolean cached)
      Using the hierarchy of ClassLoader, each level of ClassLoader ( ClassLoader , its parent ClassLoader and higher) will be able to load the configuration file META-INF/services serviceType under its class path.
      • Methods inherited from class java.lang.Object

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

      • ServiceLoaderUtils

        public ServiceLoaderUtils()
    • Method Detail

      • loadServicesList

        public static <S> java.util.List<S> loadServicesList​(java.lang.Class<S> serviceType)
                                                      throws java.lang.IllegalArgumentException
        Using the hierarchy of ClassLoader, each level of ClassLoader ( ClassLoader , its parent ClassLoader and higher) will be able to load the configuration file META-INF/services serviceType under its class path. The configuration file of each service type can define multiple lists of implementation classes.

        Type Parameters:
        S - service type
        Parameters:
        serviceType - service type
        Returns:
        service type all implementation objects of readonly list
        Throws:
        java.lang.IllegalArgumentException - If it refers to the implementation class that does not define serviceType in the configuration file /META-INF/services/serviceType
      • loadServicesList

        public static <S> java.util.List<S> loadServicesList​(java.lang.Class<S> serviceType,
                                                             java.lang.ClassLoader classLoader)
                                                      throws java.lang.IllegalArgumentException
        Using the hierarchy of ClassLoader, each level of ClassLoader ( ClassLoader , its parent ClassLoader and higher) will be able to load the configuration file META-INF/services serviceType under its class path. The configuration file of each service type can define multiple lists of implementation classes.

        Type Parameters:
        S - service type
        Parameters:
        serviceType - service type
        classLoader - ClassLoader
        Returns:
        service type all implementation objects of readonly list
        Throws:
        java.lang.IllegalArgumentException - If it refers to the implementation class that does not define serviceType in the configuration file /META-INF/services/serviceType
      • loadServicesList

        public static <S> java.util.List<S> loadServicesList​(java.lang.Class<S> serviceType,
                                                             boolean cached)
                                                      throws java.lang.IllegalArgumentException
        Using the hierarchy of ClassLoader, each level of ClassLoader ( ClassLoader , its parent ClassLoader and higher) will be able to load the configuration file META-INF/services serviceType under its class path. The configuration file of each service type can define multiple lists of implementation classes.

        Type Parameters:
        S - service type
        Parameters:
        serviceType - service type
        cached - the list of services to be cached
        Returns:
        service type all implementation objects of readonly list
        Throws:
        java.lang.IllegalArgumentException - If it refers to the implementation class that does not define serviceType in the configuration file /META-INF/services/serviceType
      • loadServicesList

        public static <S> java.util.List<S> loadServicesList​(java.lang.Class<S> serviceType,
                                                             java.lang.ClassLoader classLoader,
                                                             boolean cached)
                                                      throws java.lang.IllegalArgumentException
        Using the hierarchy of ClassLoader, each level of ClassLoader ( ClassLoader , its parent ClassLoader and higher) will be able to load the configuration file META-INF/services serviceType under its class path. The configuration file of each service type can define multiple lists of implementation classes.

        Type Parameters:
        S - service type
        Parameters:
        serviceType - service type
        classLoader - ClassLoader
        cached - the list of services to be cached
        Returns:
        service type all implementation objects of readonly list
        Throws:
        java.lang.IllegalArgumentException - If it refers to the implementation class that does not define serviceType in the configuration file /META-INF/services/serviceType
      • loadServices

        public static <S> S[] loadServices​(java.lang.Class<S> serviceType)
                                    throws java.lang.IllegalArgumentException
        Using the hierarchy of ClassLoader, each level of ClassLoader ( ClassLoader , its parent ClassLoader and higher) will be able to load the configuration file META-INF/services serviceType under its class path. The configuration file of each service type can define multiple lists of implementation classes.

        Type Parameters:
        S - service type
        Parameters:
        serviceType - service type
        Returns:
        service type all implementation objects
        Throws:
        java.lang.IllegalArgumentException - If it refers to the implementation class that does not define serviceType in the configuration file /META-INF/services/serviceType
      • loadServices

        public static <S> S[] loadServices​(java.lang.Class<S> serviceType,
                                           java.lang.ClassLoader classLoader)
                                    throws java.lang.IllegalArgumentException
        Using the hierarchy of ClassLoader, each level of ClassLoader ( ClassLoader , its parent ClassLoader and higher) will be able to load the configuration file META-INF/services serviceType under its class path. The configuration file of each service type can define multiple lists of implementation classes.

        Type Parameters:
        S - service type
        Parameters:
        serviceType - service type
        classLoader - ClassLoader
        Returns:
        service type all implementation objects
        Throws:
        java.lang.IllegalArgumentException - If it refers to the implementation class that does not define serviceType in the configuration file /META-INF/services/serviceType
      • loadServices

        public static <S> S[] loadServices​(java.lang.Class<S> serviceType,
                                           boolean cached)
                                    throws java.lang.IllegalArgumentException
        Using the hierarchy of ClassLoader, each level of ClassLoader ( ClassLoader , its parent ClassLoader and higher) will be able to load the configuration file META-INF/services serviceType under its class path. The configuration file of each service type can define multiple lists of implementation classes.

        Type Parameters:
        S - service type
        Parameters:
        serviceType - service type
        cached - the list of services to be cached
        Returns:
        service type all implementation objects
        Throws:
        java.lang.IllegalArgumentException - If it refers to the implementation class that does not define serviceType in the configuration file /META-INF/services/serviceType
      • loadServices

        public static <S> S[] loadServices​(java.lang.Class<S> serviceType,
                                           java.lang.ClassLoader classLoader,
                                           boolean cached)
                                    throws java.lang.IllegalArgumentException
        Using the hierarchy of ClassLoader, each level of ClassLoader ( ClassLoader , its parent ClassLoader and higher) will be able to load the configuration file META-INF/services serviceType under its class path. The configuration file of each service type can define multiple lists of implementation classes.

        Type Parameters:
        S - service type
        Parameters:
        serviceType - service type
        classLoader - ClassLoader
        cached - the list of services to be cached
        Returns:
        service type all implementation objects
        Throws:
        java.lang.IllegalArgumentException - If it refers to the implementation class that does not define serviceType in the configuration file /META-INF/services/serviceType
      • loadFirstService

        public static <S> S loadFirstService​(java.lang.Class<S> serviceType)
                                      throws java.lang.IllegalArgumentException
        Load the first instance of Service interface instances list

        Design Purpose : Using the hierarchy of ClassLoader, each level of ClassLoader will be able to access the configuration files under its class path /META-INF/services/serviceType. Then, override the first implementation class of the configuration file under the class path of ClassLoader, thereby providing a mechanism for overriding the implementation class.

        Type Parameters:
        S - service type
        Parameters:
        serviceType - service type
        Returns:
        If it exists, loads the first in the list of implementation objects of service type.
        Throws:
        java.lang.IllegalArgumentException - If the implementation class that does not define serviceType is in the configuration file META-INF/services/serviceType, IllegalArgumentException will be thrown
      • loadFirstService

        public static <S> S loadFirstService​(java.lang.Class<S> serviceType,
                                             boolean cached)
                                      throws java.lang.IllegalArgumentException
        Load the first instance of Service interface instances list

        Design Purpose : Using the hierarchy of ClassLoader, each level of ClassLoader will be able to access the configuration files under its class path /META-INF/services/serviceType. Then, override the first implementation class of the configuration file under the class path of ClassLoader, thereby providing a mechanism for overriding the implementation class.

        Type Parameters:
        S - service type
        Parameters:
        serviceType - service type
        cached - the list of services to be cached
        Returns:
        If it exists, loads the first in the list of implementation objects of service type.
        Throws:
        java.lang.IllegalArgumentException - If the implementation class that does not define serviceType is in the configuration file META-INF/services/serviceType, IllegalArgumentException will be thrown
      • loadFirstService

        public static <S> S loadFirstService​(java.lang.Class<S> serviceType,
                                             java.lang.ClassLoader classLoader)
                                      throws java.lang.IllegalArgumentException
        Load the first instance of Service interface instances list

        Design Purpose : Using the hierarchy of ClassLoader, each level of ClassLoader will be able to access the configuration files under its class path /META-INF/services/serviceType. Then, override the first implementation class of the configuration file under the class path of ClassLoader, thereby providing a mechanism for overriding the implementation class.

        Type Parameters:
        S - service type
        Parameters:
        serviceType - service type
        Returns:
        If it exists, loads the first in the list of implementation objects of service type.
        Throws:
        java.lang.IllegalArgumentException - If the implementation class that does not define serviceType is in the configuration file META-INF/services/serviceType, IllegalArgumentException will be thrown
      • loadFirstService

        public static <S> S loadFirstService​(java.lang.Class<S> serviceType,
                                             java.lang.ClassLoader classLoader,
                                             boolean cached)
                                      throws java.lang.IllegalArgumentException
        Load the first instance of Service interface instances list

        Design Purpose : Using the hierarchy of ClassLoader, each level of ClassLoader will be able to access the configuration files under its class path /META-INF/services/serviceType. Then, override the first implementation class of the configuration file under the class path of ClassLoader, thereby providing a mechanism for overriding the implementation class.

        Type Parameters:
        S - service type
        Parameters:
        serviceType - service type
        cached - the list of services to be cached
        Returns:
        If it exists, loads the first in the list of implementation objects of service type.
        Throws:
        java.lang.IllegalArgumentException - If the implementation class that does not define serviceType is in the configuration file META-INF/services/serviceType, IllegalArgumentException will be thrown
      • loadLastService

        public static <S> S loadLastService​(java.lang.Class<S> serviceType)
                                     throws java.lang.IllegalArgumentException
        Loads the last in the list of objects implementing the service type, if present.

        Design Purpose : Using the hierarchy of ClassLoader, once the configuration file is loaded in the parent's ClassLoader at a higher level (here the highest-level ClassLoader is Bootstrap ClassLoader) /META-INF/services/serviceType If the last implementation class is used, the lower-level Class Loader will not be able to override the previous definition。

        Type Parameters:
        S - service type
        Parameters:
        serviceType - service type
        Returns:
        Loads the last in the list of objects implementing the service type, if present.
        Throws:
        java.lang.IllegalArgumentException - see loadServicesList(Class, ClassLoader)
      • loadLastService

        public static <S> S loadLastService​(java.lang.Class<S> serviceType,
                                            boolean cached)
                                     throws java.lang.IllegalArgumentException
        Loads the last in the list of objects implementing the service type, if present.

        Design Purpose : Using the hierarchy of ClassLoader, once the configuration file is loaded in the parent's ClassLoader at a higher level (here the highest-level ClassLoader is Bootstrap ClassLoader) /META-INF/services/serviceType If the last implementation class is used, the lower-level Class Loader will not be able to override the previous definition。

        Type Parameters:
        S - service type
        Parameters:
        serviceType - service type
        cached - the list of services to be cached
        Returns:
        Loads the last in the list of objects implementing the service type, if present.
        Throws:
        java.lang.IllegalArgumentException - see loadServicesList(Class, ClassLoader)
      • loadLastService

        public static <S> S loadLastService​(java.lang.Class<S> serviceType,
                                            java.lang.ClassLoader classLoader)
                                     throws java.lang.IllegalArgumentException
        Loads the last in the list of objects implementing the service type, if present.

        Design Purpose : Using the hierarchy of ClassLoader, once the configuration file is loaded in the parent's ClassLoader at a higher level (here the highest-level ClassLoader is Bootstrap ClassLoader) /META-INF/services/serviceType If the last implementation class is used, the lower-level Class Loader will not be able to override the previous definition。

        Type Parameters:
        S - service type
        Parameters:
        serviceType - service type
        classLoader - ClassLoader
        Returns:
        Loads the last in the list of objects implementing the service type, if present.
        Throws:
        java.lang.IllegalArgumentException - see loadServicesList(Class, ClassLoader)
      • loadLastService

        public static <S> S loadLastService​(java.lang.Class<S> serviceType,
                                            java.lang.ClassLoader classLoader,
                                            boolean cached)
                                     throws java.lang.IllegalArgumentException
        Loads the last in the list of objects implementing the service type, if present.

        Design Purpose : Using the hierarchy of ClassLoader, once the configuration file is loaded in the parent's ClassLoader at a higher level (here the highest-level ClassLoader is Bootstrap ClassLoader) /META-INF/services/serviceType If the last implementation class is used, the lower-level Class Loader will not be able to override the previous definition。

        Type Parameters:
        S - service type
        Parameters:
        serviceType - service type
        Returns:
        Loads the last in the list of objects implementing the service type, if present.
        Throws:
        java.lang.IllegalArgumentException - see loadServicesList(Class, ClassLoader)
      • load

        public static <S> java.util.ServiceLoader<S> load​(java.lang.Class<S> serviceType,
                                                          java.lang.ClassLoader classLoader,
                                                          boolean cached)