本文整理汇总了Java中java.util.ServiceLoader.load方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceLoader.load方法的具体用法?Java ServiceLoader.load怎么用?Java ServiceLoader.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.ServiceLoader
的用法示例。
在下文中一共展示了ServiceLoader.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadSpi
import java.util.ServiceLoader; //导入方法依赖的package包/类
private static OASFactoryResolver loadSpi(ClassLoader cl) {
if (cl == null) {
return null;
}
OASFactoryResolver instance = loadSpi(cl.getParent());
if (instance == null) {
ServiceLoader<OASFactoryResolver> sl = ServiceLoader.load(OASFactoryResolver.class, cl);
for (OASFactoryResolver spi : sl) {
if (instance != null) {
throw new IllegalStateException("Multiple OASFactoryResolver implementations found: " + spi.getClass().getName() + " and "
+ instance.getClass().getName());
}
else {
instance = spi;
}
}
}
return instance;
}
示例2: testAddUses
import java.util.ServiceLoader; //导入方法依赖的package包/类
/**
* Test Module::addUses
*/
public void testAddUses() {
Module thisModule = Main.class.getModule();
assertFalse(thisModule.canUse(Service.class));
try {
ServiceLoader.load(Service.class);
assertTrue(false);
} catch (ServiceConfigurationError expected) { }
Module result = thisModule.addUses(Service.class);
assertTrue(result== thisModule);
assertTrue(thisModule.canUse(Service.class));
ServiceLoader.load(Service.class); // no exception
}
示例3: discoverSources
import java.util.ServiceLoader; //导入方法依赖的package包/类
private List<ConfigSource> discoverSources() {
List<ConfigSource> discoveredSources = new ArrayList<>();
ServiceLoader<ConfigSource> configSourceLoader = ServiceLoader.load(ConfigSource.class, classLoader);
configSourceLoader.forEach(configSource -> {
discoveredSources.add(configSource);
});
// load all ConfigSources from ConfigSourceProviders
ServiceLoader<ConfigSourceProvider> configSourceProviderLoader = ServiceLoader.load(ConfigSourceProvider.class, classLoader);
configSourceProviderLoader.forEach(configSourceProvider -> {
configSourceProvider.getConfigSources(classLoader)
.forEach(configSource -> {
discoveredSources.add(configSource);
});
});
return discoveredSources;
}
示例4: getSortedService
import java.util.ServiceLoader; //导入方法依赖的package包/类
public static <T> List<T> getSortedService(Class<T> serviceType) {
List<Entry<Integer, T>> serviceEntries = new ArrayList<>();
ServiceLoader<T> serviceLoader = ServiceLoader.load(serviceType);
serviceLoader.forEach(service -> {
int serviceOrder = 0;
Method getOrder = ReflectionUtils.findMethod(service.getClass(), "getOrder");
if (getOrder != null) {
serviceOrder = (int) ReflectionUtils.invokeMethod(getOrder, service);
}
Entry<Integer, T> entry = new SimpleEntry<>(serviceOrder, service);
serviceEntries.add(entry);
});
return serviceEntries.stream()
.sorted(Comparator.comparingInt(Entry::getKey))
.map(Entry::getValue)
.collect(Collectors.toList());
}
示例5: firstByServiceLoader
import java.util.ServiceLoader; //导入方法依赖的package包/类
static <P, T extends Exception> P firstByServiceLoader(Class<P> spiClass,
Logger logger,
ExceptionHandler<T> handler) throws T {
logger.log(Level.FINE, "Using java.util.ServiceLoader to find {0}", spiClass.getName());
// service discovery
try {
ServiceLoader<P> serviceLoader = ServiceLoader.load(spiClass);
for (P impl : serviceLoader) {
logger.log(Level.FINE, "ServiceProvider loading Facility used; returning object [{0}]", impl.getClass().getName());
return impl;
}
} catch (Throwable t) {
throw handler.createException(t, "Error while searching for service [" + spiClass.getName() + "]");
}
return null;
}
示例6: testIteratorOrder
import java.util.ServiceLoader; //导入方法依赖的package包/类
/**
* Basic test of iterator() to test iteration order. Providers deployed
* as named modules should be found before providers deployed on the class
* path.
*/
@Test
public void testIteratorOrder() {
ServiceLoader<ScriptEngineFactory> loader
= ServiceLoader.load(ScriptEngineFactory.class);
boolean foundUnnamed = false;
for (ScriptEngineFactory factory : collectAll(loader)) {
if (factory.getClass().getModule().isNamed()) {
if (foundUnnamed) {
assertTrue(false, "Named module element after unnamed");
}
} else {
foundUnnamed = true;
}
}
}
示例7: loadSpi
import java.util.ServiceLoader; //导入方法依赖的package包/类
private static FaultToleranceProviderResolver loadSpi(ClassLoader cl) {
if (cl == null) {
return null;
}
// start from the root CL and go back down to the TCCL
FaultToleranceProviderResolver instance = loadSpi(cl.getParent());
if (instance == null) {
ServiceLoader<FaultToleranceProviderResolver> sl = ServiceLoader.load(FaultToleranceProviderResolver.class, cl);
for (FaultToleranceProviderResolver spi : sl) {
if (instance != null) {
throw new IllegalStateException("Multiple FaultToleranceResolverProvider implementations found: " + spi.getClass().getName()
+ " and " + instance.getClass().getName());
} else {
instance = spi;
}
}
}
return instance;
}
开发者ID:Emily-Jiang,项目名称:microprofile-faultTolerance-incubation,代码行数:22,代码来源:FaultToleranceProviderResolver.java
示例8: load
import java.util.ServiceLoader; //导入方法依赖的package包/类
static List<Plugin> load() {
List<Plugin> plugins = new ArrayList<>();
for (Plugin plugin : ServiceLoader.load(Plugin.class)) {
plugins.add(plugin);
}
return plugins;
}
示例9: availableOutputs
import java.util.ServiceLoader; //导入方法依赖的package包/类
static ModuleOutput availableOutputs() {
ServiceLoader<ModuleOutput> loader = ServiceLoader.load(ModuleOutput.class, ModuleOutput.class.getClassLoader());
return StreamSupport.stream(loader.spliterator(), false)
.reduce((_1, _2) -> Optional.empty(), ModuleOutput::or);
}
示例10: loadMonitor
import java.util.ServiceLoader; //导入方法依赖的package包/类
private List<MonitorService> loadMonitor() {
Iterable<MonitorService> candidates =
ServiceLoader.load(MonitorService.class, ClassHelper.getClassLoader());
List<MonitorService> list = Lists.newArrayList();
for (MonitorService current : candidates) {
list.add(current);
}
return list;
}
示例11: createCache
import java.util.ServiceLoader; //导入方法依赖的package包/类
private MCache createCache(Properties gemfireProperties) {
ServiceLoader<ServerLauncherCacheProvider> loader =
ServiceLoader.load(ServerLauncherCacheProvider.class);
for (ServerLauncherCacheProvider provider : loader) {
MCache cache = provider.createCache(gemfireProperties, this);
if (cache != null) {
return cache;
}
}
return DEFAULT_CACHE_PROVIDER.createCache(gemfireProperties, this);
}
示例12: getDownloadSteps
import java.util.ServiceLoader; //导入方法依赖的package包/类
public static DownloadSteps getDownloadSteps(By identity) {
ServiceLoader<DownloadSteps> loader = ServiceLoader.load
(DownloadSteps.class);
for (DownloadSteps downloadSteps : loader) {
if (downloadSteps.accept(identity))
return downloadSteps;
}
return new BaseFileDownloadSteps(identity);
}
示例13: resolveEntityByEntityResolvers
import java.util.ServiceLoader; //导入方法依赖的package包/类
/**
* Resolve entity using discovered {@link EntityResolver2}s.
*
* @param publicId
* @param systemId
* @return {@link InputSource} for resolved entity if found, otherwise null.
* @throws IOException
* @throws SAXException
* @since GemFire 8.1
*/
private InputSource resolveEntityByEntityResolvers(String name, String publicId, String baseURI,
String systemId) throws SAXException, IOException {
final ServiceLoader<EntityResolver2> entityResolvers =
ServiceLoader.load(EntityResolver2.class, ClassPathLoader.getLatest().asClassLoader());
for (final EntityResolver2 entityResolver : entityResolvers) {
final InputSource inputSource =
entityResolver.resolveEntity(name, publicId, baseURI, systemId);
if (null != inputSource) {
return inputSource;
}
}
return null;
}
示例14: getTableSteps
import java.util.ServiceLoader; //导入方法依赖的package包/类
public static TableSteps getTableSteps(By identity) {
ServiceLoader<TableSteps> loader = ServiceLoader.load(TableSteps.class);
for (TableSteps steps : loader) {
if (steps.accept(identity)) {
return steps;
}
}
return new BaseTableSteps(identity);
}
示例15: loadAll
import java.util.ServiceLoader; //导入方法依赖的package包/类
public static <S> ServiceLoader<S> loadAll(Class<S> clazz) {
return ServiceLoader.load(clazz);
}