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


Java ServiceLoader.forEach方法代码示例

本文整理汇总了Java中java.util.ServiceLoader.forEach方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceLoader.forEach方法的具体用法?Java ServiceLoader.forEach怎么用?Java ServiceLoader.forEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.ServiceLoader的用法示例。


在下文中一共展示了ServiceLoader.forEach方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: reLoadService

import java.util.ServiceLoader; //导入方法依赖的package包/类
/**
 * 重新加载服务.
 *
 * @param cl 类加载器
 */
public void reLoadService(ClassLoader cl) {
    try {
        lock.lock();
        ServiceLoader<DataProvider> providers;
        if (cl == null) {
            providers = ServiceLoader.load(DataProvider.class);
        } else {
            providers = ServiceLoader.load(DataProvider.class, cl);
        }
        providerCache.clear();
        providers.forEach(provider -> {
            String id = provider.getId();
            DataProvider oldProvider = providerCache.get(id);
            if (oldProvider != null) {
                throw new GeneratorException("provider出现重复id:" + id + " 旧类名:" + oldProvider.getClass().getName()
                                             + " 新类名:" + provider.getClass().getName());
            } else {
                providerCache.put(provider.getId(), provider);
            }
        });
    } finally {
        lock.unlock();
    }
}
 
开发者ID:sgota,项目名称:tkcg,代码行数:30,代码来源:DispatcherController.java

示例2: 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

示例3: 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

示例4: loadAnalyzers

import java.util.ServiceLoader; //导入方法依赖的package包/类
private static void loadAnalyzers() {
    logger.debug("Loading NiFiProvenanceEventAnalyzer ...");
    final ServiceLoader<NiFiProvenanceEventAnalyzer> serviceLoader
            = ServiceLoader.load(NiFiProvenanceEventAnalyzer.class);
    serviceLoader.forEach(analyzer -> {
        addAnalyzer(analyzer.targetComponentTypePattern(), analyzersForComponentType, analyzer);
        addAnalyzer(analyzer.targetTransitUriPattern(), analyzersForTransitUri, analyzer);
        final ProvenanceEventType eventType = analyzer.targetProvenanceEventType();
        if (eventType != null) {
            if (analyzersForProvenanceEventType.containsKey(eventType)) {
                logger.warn("Fo ProvenanceEventType {}, an Analyzer {} is already assigned." +
                        " Only one analyzer for a type can be registered. Ignoring {}",
                        eventType, analyzersForProvenanceEventType.get(eventType), analyzer);
            }
            analyzersForProvenanceEventType.put(eventType, analyzer);
        }
    });
    logger.info("Loaded NiFiProvenanceEventAnalyzers: componentTypes={}, transitUris={}", analyzersForComponentType, analyzersForTransitUri);
}
 
开发者ID:bcgov,项目名称:nifi-atlas,代码行数:20,代码来源:NiFiProvenanceEventAnalyzerFactory.java

示例5: DockerUnitRunner

import java.util.ServiceLoader; //导入方法依赖的package包/类
public DockerUnitRunner(Class<?> klass) throws InitializationError {
    super(klass);
    ServiceLoader<DiscoveryProviderFactory> loader = ServiceLoader.load(DiscoveryProviderFactory.class);
    List<DiscoveryProviderFactory> implementations = new ArrayList<>();
    loader.forEach(impl -> {
    	logger.info("Found discovery provider factory of type " + impl.getClass().getSimpleName());
    	implementations.add(impl);
    });
    if(implementations.size() > 0) {
    	logger.info("Using discovery provider factory " + implementations.get(0).getClass().getSimpleName());
    	discoveryProvider = implementations.get(0).getProvider();
    } else {
    	throw new InitializationError("No discovery provider factory found. Aborting test.");
    }
}
 
开发者ID:qzagarese,项目名称:dockerunit,代码行数:16,代码来源:DockerUnitRunner.java

示例6: getDefaultBleaches

import java.util.ServiceLoader; //导入方法依赖的package包/类
/**
 * Finds all statically loadable bleaches
 *
 * @return ordered list of statically loadable bleaches
 */
private static Bleach[] getDefaultBleaches() {
    ServiceLoader<Bleach> services = ServiceLoader.load(Bleach.class);

    Collection<Bleach> list = new ArrayList<>();
    services.forEach(list::add);

    return list.toArray(new Bleach[0]);
}
 
开发者ID:docbleach,项目名称:DocBleach,代码行数:14,代码来源:DefaultBleach.java

示例7: configureHttpServer

import java.util.ServiceLoader; //导入方法依赖的package包/类
private void configureHttpServer(VertxContext vertxContext, Future<HttpServerOptions> future) {
    HttpServerOptions httpServerOptions = new HttpServerOptions();
    httpServerOptions.setPort(vertxContext.config().getInteger(HTTP_PORT_KEY, DEFAULT_PORT));
    ServiceLoader<HttpServerConfigurator> configurators = ServiceLoader.load(HttpServerConfigurator.class);
    configurators.forEach(c -> c.configureHttpServer(vertxContext, httpServerOptions));
    httpServerOptions.setCompressionSupported(true);

    future.complete(httpServerOptions);
}
 
开发者ID:GwtDomino,项目名称:domino,代码行数:10,代码来源:DominoLoader.java

示例8: discoverConverters

import java.util.ServiceLoader; //导入方法依赖的package包/类
private List<Converter> discoverConverters() {
    List<Converter> converters = new ArrayList<>();
    ServiceLoader<Converter> converterLoader = ServiceLoader.load(Converter.class, classLoader);
    converterLoader.forEach(converter -> {
        converters.add(converter);
    });
    return converters;
}
 
开发者ID:wildfly-extras,项目名称:wildfly-microprofile-config,代码行数:9,代码来源:WildFlyConfigBuilder.java

示例9: initialize

import java.util.ServiceLoader; //导入方法依赖的package包/类
@Override
public void initialize(URL url, ResourceBundle rb) {
    itemCount.setText(SunagoUtil.getSunagoPreferences().getPreference(SunagoPrefsKeys.ITEM_COUNT.getKey(), "50"));
    final ServiceLoader<SocialMediaPreferencesController> smPrefsLoader
            = ServiceLoader.load(SocialMediaPreferencesController.class);
    smPrefsLoader.forEach(smp -> smPrefs.add(smp));

    smPrefs.forEach(smp -> tabPane.getTabs().add(smp.getTab()));
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:10,代码来源:PreferencesController.java

示例10: load

import java.util.ServiceLoader; //导入方法依赖的package包/类
public static void load() {
    ServiceLoader<ModuleConfigurationProvider> configurations = ServiceLoader.load(ModuleConfigurationProvider.class);
    configurations.forEach(ModuleConfigurationsLoader::configure);
}
 
开发者ID:GwtDomino,项目名称:domino-todolist,代码行数:5,代码来源:ModuleConfigurationsLoader.java

示例11: onModulesLoaded

import java.util.ServiceLoader; //导入方法依赖的package包/类
@Override
public void onModulesLoaded(ServerContext serverContext) {
        VertxContext vertxContext = (VertxContext) serverContext;
        ServiceLoader<VertxEntryPoint> vertxEntryPoints = ServiceLoader.load(VertxEntryPoint.class);
        vertxEntryPoints.forEach(e -> e.onVertxStartup(vertxContext));
}
 
开发者ID:GwtDomino,项目名称:domino-event-bus,代码行数:7,代码来源:VertxBusEntryPoint.java


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