public ProviderAgent findProviderAgent() { ServiceLoader<ProviderAgent> serviceLoaderFromExt = ServiceLoader.loadInstalled(ProviderAgent.class); if (serviceLoaderFromExt.iterator().hasNext()) { ProviderAgent providerAgent = serviceLoaderFromExt.iterator().next(); LOGGER.info("Using {} from Extension ClassLoader for service {}", providerAgent.getClass().getName(), ProviderAgent.class.getName()); return providerAgent; } ServiceLoader<ProviderAgent> serviceLoaderFromTccl = ServiceLoader.load(ProviderAgent.class); if (serviceLoaderFromTccl.iterator().hasNext()) { ProviderAgent providerAgent = serviceLoaderFromTccl.iterator().next(); LOGGER.info("Using {} from Thread Context ClassLoader for service {}", providerAgent.getClass().getName(), ProviderAgent.class.getName()); return providerAgent; } ServiceLoader<ProviderAgent> serviceLoaderFromSys = ServiceLoader.load(ProviderAgent.class, null); if (serviceLoaderFromSys.iterator().hasNext()) { ProviderAgent providerAgent = serviceLoaderFromSys.iterator().next(); LOGGER.info("Using {} from System ClassLoader for service {}", providerAgent.getClass().getName(), ProviderAgent.class.getName()); return providerAgent; } return createProviderAgent(); }
private ServiceLoader<GremlinScriptEngineFactory> getServiceLoader(final ClassLoader loader) { if (loader != null) { return ServiceLoader.load(GremlinScriptEngineFactory.class, loader); } else { return ServiceLoader.loadInstalled(GremlinScriptEngineFactory.class); } }
@Override public ServiceLoader<S> call() throws Exception { return ServiceLoader.loadInstalled(type); } };
@Override public ServiceLoader<S> call() throws Exception { return ServiceLoader.loadInstalled(type); } };
private ServiceLoader<GremlinScriptEngineFactory> getServiceLoader(final ClassLoader loader) { if (loader != null) { return ServiceLoader.load(GremlinScriptEngineFactory.class, loader); } else { return ServiceLoader.loadInstalled(GremlinScriptEngineFactory.class); } }
/** Replies all the installed SRE into the class path. * * @param onlyInstalledInJRE indicates if the services will be considered only into the libraries that are * installed into the JRE. If {@code true}, only the libraries into the JRE will be considered and * the application libraries will be ignored. If {@code false}, the application libraries will be * considered as well. * @return the installed SRE. */ @Pure public static ServiceLoader<SREBootstrap> getServiceLoader(boolean onlyInstalledInJRE) { synchronized (SRE.class) { ServiceLoader<SREBootstrap> sl = loader == null ? null : loader.get(); if (sl == null) { if (onlyInstalledInJRE) { sl = ServiceLoader.loadInstalled(SREBootstrap.class); } else { sl = ServiceLoader.load(SREBootstrap.class); } loader = new SoftReference<>(sl); } return sl; } }
/** * Creates a new service loader for the given service type, using the extension class loader. * <p/> * <p> This convenience method simply locates the extension class loader, call it <tt><i>extClassLoader</i></tt>, and * then returns * <p/> * <blockquote><pre> * OverloadedServiceLoader.load(<i>service</i>, <i>extClassLoader</i>)</pre></blockquote> * <p/> * <p> If the extension class loader cannot be found then the system class loader is used; if there is no system class * loader then the bootstrap class loader is used. * <p/> * <p> This method is intended for use when only installed providers are desired. The resulting service will only * find and load providers that have been installed into the current Java virtual machine; providers on the * application's class path will be ignored. * * @param service The interface or abstract class representing the service * @return A new service loader */ public static <S> OverloadedServiceLoader<S> loadInstalled( Class<S> service ) { return new OverloadedServiceLoader<>( ServiceLoader.loadInstalled( service ) ); }
ServiceLoader<Service> extensionServices = ServiceLoader.loadInstalled(klass); ceylon.language.Iterable<? extends Service,? extends Object> services = new It(moduleServices).<Service,Object>chain($reified$Service, Null.$TypeDescriptor$, new It(extensionServices));