当前位置: 首页>>代码示例>>Java>>正文


Java ServiceLoader.load方法代码示例

本文整理汇总了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;
}
 
开发者ID:eclipse,项目名称:microprofile-open-api,代码行数:22,代码来源:OASFactoryResolver.java

示例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
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Main.java

示例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;
}
 
开发者ID:wildfly-extras,项目名称:wildfly-microprofile-config,代码行数:18,代码来源:WildFlyConfigBuilder.java

示例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());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:20,代码来源:SPIServiceUtils.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ServiceLoaderUtil.java

示例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;
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ModulesTest.java

示例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;
}
 
开发者ID:sormuras,项目名称:bach,代码行数:8,代码来源:Plugin.java

示例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);
}
 
开发者ID:forax,项目名称:moduletools,代码行数:6,代码来源:ModuleOutput.java

示例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;
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:10,代码来源:ClientServerMonitor.java

示例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);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:13,代码来源:ServerLauncher.java

示例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);
}
 
开发者ID:tapack,项目名称:satisfy,代码行数:10,代码来源:WebStepsFactory.java

示例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;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:24,代码来源:CacheXml.java

示例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);
}
 
开发者ID:tapack,项目名称:satisfy,代码行数:10,代码来源:WebStepsFactory.java

示例15: loadAll

import java.util.ServiceLoader; //导入方法依赖的package包/类
public static <S> ServiceLoader<S> loadAll(Class<S> clazz) {
    return ServiceLoader.load(clazz);
}
 
开发者ID:yu199195,项目名称:myth,代码行数:4,代码来源:ServiceBootstrap.java


注:本文中的java.util.ServiceLoader.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。