java.util.ServiceLoader.forEach()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中java.util.ServiceLoader.forEach()方法的一些代码示例,展示了ServiceLoader.forEach()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ServiceLoader.forEach()方法的具体详情如下:
包路径:java.util.ServiceLoader
类名称:ServiceLoader
方法名:forEach

ServiceLoader.forEach介绍

暂无

代码示例

代码示例来源:origin: oracle/helidon

private void loadAnalyzers() {
  ServiceLoader.load(AnnotationAnalyzer.class)
      .forEach(analyzers::add);
}

代码示例来源:origin: oracle/helidon

private static void loadMapperServices(List<ConfigMapperProvider> providers) {
  ServiceLoader.load(ConfigMapperProvider.class)
      .forEach(providers::add);
}

代码示例来源:origin: jdbi/jdbi

/**
 * Use the {@link ServiceLoader} API to detect and install plugins automagically.
 * Some people consider this feature dangerous; some consider it essential --
 * use at your own risk.
 * @return this
 */
public Jdbi installPlugins() {
  ServiceLoader.load(JdbiPlugin.class).forEach(this::installPlugin);
  LOG.debug("Automatically installed plugins {}", plugins);
  return this;
}

代码示例来源:origin: apache/incubator-druid

private void addAllFromCurrentClassLoader()
{
 ServiceLoader
   .load(serviceClass, Thread.currentThread().getContextClassLoader())
   .forEach(impl -> tryAdd(impl, "classpath"));
}

代码示例来源:origin: bootique/bootique

Collection<BQModuleProvider> autoLoadedProviders() {
    Collection<BQModuleProvider> modules = new ArrayList<>();
    ServiceLoader.load(BQModuleProvider.class).forEach(p -> modules.add(p));
    return modules;
  }
}

代码示例来源:origin: javax.enterprise/cdi-api

private static void findAllProviders() {
  ServiceLoader<CDIProvider> providerLoader;
  Set<CDIProvider> providers = new TreeSet<>(Comparator.comparingInt(CDIProvider::getPriority).reversed());
  providerLoader = ServiceLoader.load(CDIProvider.class, CDI.class.getClassLoader());
  if(! providerLoader.iterator().hasNext()) {
    throw new IllegalStateException("Unable to locate CDIProvider");
  }
  try {
    providerLoader.forEach(providers::add);
  } catch (ServiceConfigurationError e) {
    throw new IllegalStateException(e);
  }
  CDI.discoveredProviders = Collections.unmodifiableSet(providers);
}

代码示例来源:origin: oracle/helidon

@Override
public ConfigBuilder addDiscoveredConverters() {
  ServiceLoader.load(Converter.class, getClassLoader())
      .forEach(this::addConverter);
  return this;
}

代码示例来源:origin: kiegroup/jbpm

private AssignmentServiceRegistry() {
  foundStrategies
    .forEach(strategy -> assignmentStrategies.put(strategy.getIdentifier(), strategy));
}

代码示例来源:origin: kiegroup/jbpm

public ExecutionErrorManagerImpl(ExecutionErrorStorage storage) {
  ServiceLoader<ExecutionErrorFilter> discoveredFilters = ServiceLoader.load(ExecutionErrorFilter.class);
  
  discoveredFilters.forEach(filter -> filters.add(filter));        
  filters.sort((ExecutionErrorFilter f1, ExecutionErrorFilter f2) -> { 
    return f1.getPriority().compareTo(f2.getPriority());
  }); 
  logger.debug("Error handling filters {}", this.filters);
  
  this.storage = storage;
  logger.debug("Execution error storage {}", this.storage);
}

代码示例来源:origin: apache/nifi

private void initClusterResolvers(ConfigurationContext context) {
  final Set<ClusterResolver> loadedClusterResolvers = new LinkedHashSet<>();
  clusterResolverLoader.forEach(resolver -> {
    resolver.configure(context);
    loadedClusterResolvers.add(resolver);
  });
  clusterResolvers = new ClusterResolvers(Collections.unmodifiableSet(loadedClusterResolvers), defaultClusterName);
}

代码示例来源:origin: oracle/helidon

private String loadProviderServices(Map<String, SecurityProviderService> configKeyToService,
                  Map<String, SecurityProviderService> classNameToService) {
  Set<String> configKeys = new HashSet<>();
  ServiceLoader<SecurityProviderService> loader = ServiceLoader.load(SecurityProviderService.class);
  loader.forEach(service -> {
    String configKey = service.providerConfigKey();
    if (null != configKey) {
      configKeyToService.put(configKey, service);
      configKeys.add(configKey);
    }
    Class<? extends SecurityProvider> theClass = service.providerClass();
    classNameToService.put(theClass.getName(), service);
  });
  return String.join(", ", configKeys);
}

代码示例来源:origin: oracle/helidon

@Override
public ConfigBuilder addDiscoveredSources() {
  ServiceLoader.load(ConfigSource.class, getClassLoader())
      .forEach(this::addConfigSource);
  ServiceLoader.load(ConfigSourceProvider.class, getClassLoader())
      .forEach(csp -> csp.getConfigSources(getClassLoader())
          .forEach(this::addConfigSource));
  return this;
}

代码示例来源:origin: AxonFramework/AxonFramework

/**
 * Returns a Configurer instance with default components configured, such as a {@link SimpleCommandBus} and
 * {@link SimpleEventBus}, indicating whether to {@code autoLocateConfigurerModules}.
 *
 * When {@code autoLocateConfigurerModules} is {@code true}, a ServiceLoader will be used to locate all declared
 * instances of type {@link ConfigurerModule}. Each of the discovered instances will be invoked, allowing it to
 * set default values for the configuration.
 *
 * @param autoLocateConfigurerModules flag indicating whether ConfigurerModules on the classpath should be
 *                                    automatically retrieved. Should be set to {@code false} when using an
 *                                    application container, such as Spring or CDI.
 * @return Configurer instance for further configuration.
 */
public static Configurer defaultConfiguration(boolean autoLocateConfigurerModules) {
  DefaultConfigurer configurer = new DefaultConfigurer();
  if(autoLocateConfigurerModules) {
    ServiceLoader<ConfigurerModule> configurerModuleLoader = ServiceLoader.load(ConfigurerModule.class, configurer.getClass().getClassLoader());
    List<ConfigurerModule> configurerModules = new ArrayList<>();
    configurerModuleLoader.forEach(configurerModules::add);
    configurerModules.sort(Comparator.comparingInt(ConfigurerModule::order));
    configurerModules.forEach(cm -> cm.configureModule(configurer));
  }
  return configurer;
}

代码示例来源:origin: apache/incubator-druid

private void addAllFromFileSystem()
{
 for (File extension : getExtensionFilesToLoad(extensionsConfig)) {
  log.info("Loading extension [%s] for class [%s]", extension.getName(), serviceClass);
  try {
   final URLClassLoader loader = getClassLoaderForExtension(
     extension,
     extensionsConfig.isUseExtensionClassloaderFirst()
   );
   ServiceLoader.load(serviceClass, loader).forEach(impl -> tryAdd(impl, "local file system"));
  }
  catch (Exception e) {
   throw Throwables.propagate(e);
  }
 }
}

代码示例来源:origin: stagemonitor/stagemonitor

private List<Class<? extends SpanEventListenerFactory>> getFactoryClasses() {
    List<Class<? extends SpanEventListenerFactory>> spanEventListenerFactories = new ArrayList<>();
    final ServiceLoader<SpanEventListenerFactory> serviceLoader = ServiceLoader.load(SpanEventListenerFactory.class);
    serviceLoader.forEach(e -> spanEventListenerFactories.add(e.getClass()));
    return spanEventListenerFactories;
  }
}

代码示例来源:origin: AxonFramework/AxonFramework

ServiceLoader.load(ChildEntityDefinition.class, inspectedType.getClassLoader());
for (Field field : ReflectionUtils.fieldsOf(inspectedType)) {
  childEntityDefinitions.forEach(def -> def.createChildDefinition(field, this).ifPresent(child -> {
    children.add(child);
    commandHandlers.addAll(child.commandHandlers());

代码示例来源:origin: jooby-project/jooby

ServiceLoader.load(CRaSHPlugin.class, this.loader).forEach(plugins::add);

代码示例来源:origin: stagemonitor/stagemonitor

@Test
public void testLoadedViaServiceLoader() throws Exception {
  List<Class<? extends SpanReporter>> spanReporters = new ArrayList<>();
  ServiceLoader.load(SpanReporter.class).forEach(reporter -> spanReporters.add(reporter.getClass()));
  assertTrue(spanReporters.contains(LoggingSpanReporter.class));
}

代码示例来源:origin: apache/nifi

clusterResolverLoader.forEach(resolver -> results.addAll(resolver.validate(context)));

代码示例来源:origin: testcontainers/testcontainers-java

ServiceLoader.load(DockerClientProviderStrategy.class).forEach( cs -> configurationStrategies.add( cs ) );

相关文章