private void loadAnalyzers() { ServiceLoader.load(AnnotationAnalyzer.class) .forEach(analyzers::add); }
private static void loadMapperServices(List<ConfigMapperProvider> providers) { ServiceLoader.load(ConfigMapperProvider.class) .forEach(providers::add); }
/** * 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; }
private void addAllFromCurrentClassLoader() { ServiceLoader .load(serviceClass, Thread.currentThread().getContextClassLoader()) .forEach(impl -> tryAdd(impl, "classpath")); }
Collection<BQModuleProvider> autoLoadedProviders() { Collection<BQModuleProvider> modules = new ArrayList<>(); ServiceLoader.load(BQModuleProvider.class).forEach(p -> modules.add(p)); return modules; } }
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); }
@Override public ConfigBuilder addDiscoveredConverters() { ServiceLoader.load(Converter.class, getClassLoader()) .forEach(this::addConverter); return this; }
private AssignmentServiceRegistry() { foundStrategies .forEach(strategy -> assignmentStrategies.put(strategy.getIdentifier(), strategy)); }
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); }
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); }
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); }
@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; }
/** * 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; }
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); } } }
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; } }
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());
ServiceLoader.load(CRaSHPlugin.class, this.loader).forEach(plugins::add);
@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)); }
clusterResolverLoader.forEach(resolver -> results.addAll(resolver.validate(context)));
ServiceLoader.load(DockerClientProviderStrategy.class).forEach( cs -> configurationStrategies.add( cs ) );