本文整理汇总了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();
}
}
示例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;
}
示例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());
}
示例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);
}
示例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.");
}
}
示例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]);
}
示例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);
}
示例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;
}
示例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()));
}
示例10: load
import java.util.ServiceLoader; //导入方法依赖的package包/类
public static void load() {
ServiceLoader<ModuleConfigurationProvider> configurations = ServiceLoader.load(ModuleConfigurationProvider.class);
configurations.forEach(ModuleConfigurationsLoader::configure);
}
示例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));
}