com.devexperts.services
Class Services

java.lang.Object
  extended by com.devexperts.services.Services

public class Services
extends Object

Utility class that contains service-loading functionality.


Field Summary
static String META_INF_SERVICES
           
 
Constructor Summary
protected Services()
          Deprecated. 
 
Method Summary
static
<T> T
createService(Class<T> serviceClass, ClassLoader loader, String implClassName)
          Creates service that implements given class.
static
<T> Iterable<T>
createServices(Class<T> serviceClass, ClassLoader loader)
           
static
<T> List<Class<? extends T>>
loadServiceClasses(Class<T> serviceClass, ClassLoader loader)
           
static void startup()
          Deprecated. No replacement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

META_INF_SERVICES

public static final String META_INF_SERVICES
See Also:
Constant Field Values
Constructor Detail

Services

@Deprecated
protected Services()
Deprecated. 

Method Detail

startup

public static void startup()
Deprecated. No replacement.

Loads and starts all classes that provide StartupService service. This happens once per JVM, regardless of the number of calls to this method.


createService

public static <T> T createService(Class<T> serviceClass,
                                  ClassLoader loader,
                                  String implClassName)
Creates service that implements given class. The implementation class name to instantiate is determined with the following lookup procedure:
  1. If implClassName != null then it is used.
  2. If loader == null and system property with name serviceClass.getName() is defined then it is used.
  3. If "META-INF/services/" + serviceClass.getName() resource is defined within the specified loader then its first line is used.
If loader == null, then the resulting implementation class name from steps 1 or 2 can have value of the form <jar-file-or-url>!<class-name>, where both parts are optional and jar-file is distinguished from class name by ".jar" suffix. Otherwise, if loader != null, implementation class name can only refer to the actual name of the class and the specified loader is used.

If loader is not otherwise defined as parameter or in implementation class name, then the first non-null class loader is taken from the below list:

  1. serviceClass.getClassLoader()
  2. Thread.currentThread().getContextClassLoader()
  3. The class loader of this Services class is used as the last option.

Parameters:
serviceClass - Service class.
loader - Default class loader (may be null). If it is null, then the lookup procedure is used.
implClassName - Implementation class name (may be null). If it is null, then the lookup procedure is used.
Returns:
Service instance or null if service cannot be found or created.

createServices

public static <T> Iterable<T> createServices(Class<T> serviceClass,
                                             ClassLoader loader)

loadServiceClasses

public static <T> List<Class<? extends T>> loadServiceClasses(Class<T> serviceClass,
                                                              ClassLoader loader)


Copyright © 2013 Devexperts. All Rights Reserved.