/** * Gets a service finder for a given service path.<br> * If the finder does not exist yet, it will be created. * The classloader used is {@code Thread.currentThread().getContextClassLoader()}. * * @param servicePath the service path prefix * @return the finder, never null */ public static ServiceFinder getServiceFinder(String servicePath) { return INSTANCE.getServiceFinderImpl(servicePath); }
/** * Gets a service finder.<br> * If the finder does not exist yet, it will be created. * The classloader used is {@code Thread.currentThread().getContextClassLoader()} * and the service path is {@code "META_INF/services/"}. * * @return the finder */ protected ServiceFinder getServiceFinderImpl() { return getServiceFinderImpl(Constants.DEFAULT_SERVICE_PATH); }
/** * Gets a service finder for a given classloader and service path.<br> * If the finder does not exist yet, it will be created. * * @param loader the classloader * @param servicePath the service path prefix * @return the finder */ public static ServiceFinder getServiceFinder(ClassLoader loader, String servicePath) { return INSTANCE.getServiceFinderImpl(loader, servicePath); }
/** * Gets a service finder.<br> * If the finder does not exist yet, it will be created. * The classloader used is {@code Thread.currentThread().getContextClassLoader()} * and the service path is {@code "META_INF/services/"}. * * @return the finder */ public static ServiceFinder getServiceFinder() { return INSTANCE.getServiceFinderImpl(); }
/** * Gets a service finder for a given service path.<br> * If the finder does not exist yet, it will be created. * The classloader to use is determined as follows: * <ol> * <li> use the fixed classloader set by {@link #setFixedClassLoader(java.lang.ClassLoader)}, if not null</li> * <li>else try {@code Thread.currentThread().getContextClassLoader()}</li> * <li>if the context classloader is null, use the classloader that loaded the service factory</li> * </ol> * * @param servicePath the service path prefix * @return the finder, never null */ protected ServiceFinder getServiceFinderImpl(String servicePath) { return getServiceFinderImpl(getClassLoader(), servicePath); }
/** * Utility method to create a service instance.<br> * This is the standard way to instantiate singletons. * Finds the first service implementation along the classpath. * * @param <T> the service type * @param serviceClass the service class * @return an instance of the service */ public static <T> Class<T> createServiceClass(Class<T> serviceClass) { try { return INSTANCE.getServiceFinderImpl().findFirstServiceProvider(serviceClass); } catch (ClassNotFoundException ex) { throw new TentackleRuntimeException("cannot create service class for " + serviceClass, ex); } }