private static List<ParameterResolverFactory> findDelegates(ClassLoader classLoader) { Iterator<ParameterResolverFactory> iterator = load(ParameterResolverFactory.class, classLoader == null ? Thread.currentThread().getContextClassLoader() : classLoader).iterator(); //noinspection WhileLoopReplaceableByForEach final List<ParameterResolverFactory> factories = new ArrayList<>(); while (iterator.hasNext()) { try { ParameterResolverFactory factory = iterator.next(); factories.add(factory); } catch (ServiceConfigurationError e) { logger.info( "ParameterResolverFactory instance ignored, as one of the required classes is not available" + "on the classpath: {}", e.getMessage()); } catch (NoClassDefFoundError e) { logger.info("ParameterResolverFactory instance ignored. It relies on a class that cannot be found: {}", e.getMessage()); } } return factories; } }
private static MultiHandlerEnhancerDefinition findDelegates(ClassLoader classLoader) { Iterator<HandlerEnhancerDefinition> iterator = load(HandlerEnhancerDefinition.class, classLoader == null ? Thread.currentThread().getContextClassLoader() : classLoader).iterator(); //noinspection WhileLoopReplaceableByForEach final List<HandlerEnhancerDefinition> enhancers = new ArrayList<>(); while (iterator.hasNext()) { try { HandlerEnhancerDefinition factory = iterator.next(); enhancers.add(factory); } catch (ServiceConfigurationError e) { LOGGER.info( "HandlerEnhancerDefinition instance ignored, as one of the required classes is not available" + "on the classpath: {}", e.getMessage()); } catch (NoClassDefFoundError e) { LOGGER.info("HandlerEnhancerDefinition instance ignored. It relies on a class that cannot be found: {}", e.getMessage()); } } return new MultiHandlerEnhancerDefinition(enhancers); }
private static MultiHandlerDefinition findDelegates(ClassLoader classLoader) { Iterator<HandlerDefinition> iterator = load(HandlerDefinition.class, classLoader == null ? Thread.currentThread().getContextClassLoader() : classLoader).iterator(); //noinspection WhileLoopReplaceableByForEach final List<HandlerDefinition> definitions = new ArrayList<>(); while (iterator.hasNext()) { try { HandlerDefinition factory = iterator.next(); definitions.add(factory); } catch (ServiceConfigurationError e) { LOGGER.info( "HandlerDefinition instance ignored, as one of the required classes is not available" + "on the classpath: {}", e.getMessage()); } catch (NoClassDefFoundError e) { LOGGER.info("HandlerDefinition instance ignored. It relies on a class that cannot be found: {}", e.getMessage()); } } return new MultiHandlerDefinition(definitions); } }
static synchronized TaskDescriptor getTaskDescriptor() { if (_identifier != null) { return _identifier; } try { Iterator<TaskDescriptor> identifiers = _loader.iterator(); if (identifiers.hasNext()) { _identifier = identifiers.next(); LOGGER.info("Using TaskDescriptor: " + _identifier.getClass()); while (identifiers.hasNext()) { TaskDescriptor descriptor = identifiers.next(); LOGGER.debug("Discarding TaskDescriptor: {} as its not first one to be loaded: ", descriptor.getClass()); } } else { LOGGER.info("No provider found for TaskDescriptor, falling back to DefaultTaskDescriptor"); _identifier = getDefaultTaskDescriptor(); } } catch (ServiceConfigurationError e) { LOGGER.error("Unable to load provider for TaskDescriptor, falling back to DefaultTaskDescriptor", e.getMessage()); _identifier = getDefaultTaskDescriptor(); } return _identifier; }
private void loadDozerModules(BeanContainer beanContainer, DestBeanBuilderCreator destBeanBuilderCreator, BeanMappingGenerator beanMappingGenerator, PropertyDescriptorFactory propertyDescriptorFactory, DestBeanCreator destBeanCreator) { try { ServiceLoader<DozerModule> services = ServiceLoader.load(DozerModule.class); for (DozerModule module : services) { module.init(); module.init(beanContainer, destBeanCreator, propertyDescriptorFactory); destBeanBuilderCreator.addPluggedStrategies(module.getBeanBuilderCreationStrategies()); beanMappingGenerator.addPluggedFieldDetectors(module.getBeanFieldsDetectors()); propertyDescriptorFactory.addPluggedPropertyDescriptorCreationStrategies(module.getPropertyDescriptorCreationStrategies()); } } catch (ServiceConfigurationError ex) { LOG.error("{}", ex.getMessage()); } } }
private void initEngines(final ClassLoader loader) { Iterator<GremlinScriptEngineFactory> itty; try { final ServiceLoader<GremlinScriptEngineFactory> sl = AccessController.doPrivileged( (PrivilegedAction<ServiceLoader<GremlinScriptEngineFactory>>) () -> getServiceLoader(loader)); itty = sl.iterator(); } catch (ServiceConfigurationError err) { logger.error("Can't find GremlinScriptEngineFactory providers: " + err.getMessage(), err); // do not throw any exception here. user may want to manager their own factories using this manager // by explicit registration (by registerXXX) methods. return; } try { while (itty.hasNext()) { try { final GremlinScriptEngineFactory factory = itty.next(); factory.setCustomizerManager(this); engineSpis.add(factory); } catch (ServiceConfigurationError err) { logger.error("GremlinScriptEngineManager providers.next(): " + err.getMessage(), err); } } } catch (ServiceConfigurationError err) { logger.error("GremlinScriptEngineManager providers.hasNext(): " + err.getMessage(), err); // do not throw any exception here. user may want to manage their own factories using this manager // by explicit registration (by registerXXX) methods. } }
private <T extends SingularExtension> Iterable<T> loadServices(@Nonnull Class<T> extensionTarget) { try { return ServiceLoader.load(extensionTarget); } catch (ServiceConfigurationError e) { getLogger().debug(e.getMessage(), e); } return Collections.emptyList(); }
private static MultiHandlerEnhancerDefinition findDelegates(ClassLoader classLoader) { Iterator<HandlerEnhancerDefinition> iterator = load(HandlerEnhancerDefinition.class, classLoader == null ? Thread.currentThread().getContextClassLoader() : classLoader).iterator(); //noinspection WhileLoopReplaceableByForEach final List<HandlerEnhancerDefinition> enhancers = new ArrayList<>(); while (iterator.hasNext()) { try { HandlerEnhancerDefinition factory = iterator.next(); enhancers.add(factory); } catch (ServiceConfigurationError e) { LOGGER.info( "HandlerEnhancerDefinition instance ignored, as one of the required classes is not available" + "on the classpath: {}", e.getMessage()); } catch (NoClassDefFoundError e) { LOGGER.info("HandlerEnhancerDefinition instance ignored. It relies on a class that cannot be found: {}", e.getMessage()); } } return new MultiHandlerEnhancerDefinition(enhancers); }
private AdviceFactory getAdviceFactory(Class<?> type, ServiceLoader<AdviceProvider> loader) { Iterator<AdviceProvider> iter = loader.iterator(); while (iter.hasNext()) { try { AdviceFactory f = iter.next().getAdviserFactory(type); if (f != null) { factories.put(type, f); return f; } } catch (ServiceConfigurationError e) { logger.warn(e.getMessage()); } } return null; } }
private static List<ParameterResolverFactory> findDelegates(ClassLoader classLoader) { Iterator<ParameterResolverFactory> iterator = load(ParameterResolverFactory.class, classLoader == null ? Thread.currentThread().getContextClassLoader() : classLoader).iterator(); //noinspection WhileLoopReplaceableByForEach final List<ParameterResolverFactory> factories = new ArrayList<>(); while (iterator.hasNext()) { try { ParameterResolverFactory factory = iterator.next(); factories.add(factory); } catch (ServiceConfigurationError e) { logger.info( "ParameterResolverFactory instance ignored, as one of the required classes is not available" + "on the classpath: {}", e.getMessage()); } catch (NoClassDefFoundError e) { logger.info("ParameterResolverFactory instance ignored. It relies on a class that cannot be found: {}", e.getMessage()); } } return factories; } }
private static List<ParameterResolverFactory> findDelegates(ClassLoader classLoader) { Iterator<ParameterResolverFactory> iterator = load(ParameterResolverFactory.class, classLoader == null ? Thread.currentThread().getContextClassLoader() : classLoader).iterator(); //noinspection WhileLoopReplaceableByForEach final List<ParameterResolverFactory> factories = new ArrayList<>(); while (iterator.hasNext()) { try { ParameterResolverFactory factory = iterator.next(); factories.add(factory); } catch (ServiceConfigurationError e) { logger.info( "ParameterResolverFactory instance ignored, as one of the required classes is not available" + "on the classpath: {}", e.getMessage()); } catch (NoClassDefFoundError e) { logger.info("ParameterResolverFactory instance ignored. It relies on a class that cannot be found: {}", e.getMessage()); } } return factories; } }
private AdviceFactory getAdviceFactory(Class<?> type, ServiceLoader<AdviceProvider> loader) { Iterator<AdviceProvider> iter = loader.iterator(); while (iter.hasNext()) { try { AdviceFactory f = iter.next().getAdviserFactory(type); if (f != null) { factories.put(type, f); return f; } } catch (ServiceConfigurationError e) { logger.warn(e.getMessage()); } } return null; } }
private static MultiHandlerEnhancerDefinition findDelegates(ClassLoader classLoader) { Iterator<HandlerEnhancerDefinition> iterator = load(HandlerEnhancerDefinition.class, classLoader == null ? Thread.currentThread().getContextClassLoader() : classLoader).iterator(); //noinspection WhileLoopReplaceableByForEach final List<HandlerEnhancerDefinition> enhancers = new ArrayList<>(); while (iterator.hasNext()) { try { HandlerEnhancerDefinition factory = iterator.next(); enhancers.add(factory); } catch (ServiceConfigurationError e) { LOGGER.info( "HandlerEnhancerDefinition instance ignored, as one of the required classes is not available" + "on the classpath: {}", e.getMessage()); } catch (NoClassDefFoundError e) { LOGGER.info("HandlerEnhancerDefinition instance ignored. It relies on a class that cannot be found: {}", e.getMessage()); } } return new MultiHandlerEnhancerDefinition(enhancers); }
private static MultiHandlerDefinition findDelegates(ClassLoader classLoader) { Iterator<HandlerDefinition> iterator = load(HandlerDefinition.class, classLoader == null ? Thread.currentThread().getContextClassLoader() : classLoader).iterator(); //noinspection WhileLoopReplaceableByForEach final List<HandlerDefinition> definitions = new ArrayList<>(); while (iterator.hasNext()) { try { HandlerDefinition factory = iterator.next(); definitions.add(factory); } catch (ServiceConfigurationError e) { LOGGER.info( "HandlerDefinition instance ignored, as one of the required classes is not available" + "on the classpath: {}", e.getMessage()); } catch (NoClassDefFoundError e) { LOGGER.info("HandlerDefinition instance ignored. It relies on a class that cannot be found: {}", e.getMessage()); } } return new MultiHandlerDefinition(definitions); } }
private static MultiHandlerDefinition findDelegates(ClassLoader classLoader) { Iterator<HandlerDefinition> iterator = load(HandlerDefinition.class, classLoader == null ? Thread.currentThread().getContextClassLoader() : classLoader).iterator(); //noinspection WhileLoopReplaceableByForEach final List<HandlerDefinition> definitions = new ArrayList<>(); while (iterator.hasNext()) { try { HandlerDefinition factory = iterator.next(); definitions.add(factory); } catch (ServiceConfigurationError e) { LOGGER.info( "HandlerDefinition instance ignored, as one of the required classes is not available" + "on the classpath: {}", e.getMessage()); } catch (NoClassDefFoundError e) { LOGGER.info("HandlerDefinition instance ignored. It relies on a class that cannot be found: {}", e.getMessage()); } } return new MultiHandlerDefinition(definitions); } }
public Optional<ElsewhereProvider> getElsewhereProvider( String typ ) { Optional<ElsewhereProvider> elsewhereProvider = Optional.empty(); try { Iterator<ElsewhereProvider> providers = loader.iterator(); while( !elsewhereProvider.isPresent() && providers.hasNext() ) { ElsewhereProvider d = providers.next(); if( d.getType().equals( typ ) ) { elsewhereProvider = Optional.of( d ); } } } catch( ServiceConfigurationError serviceError ) { Log.warn( serviceError.getMessage() ); return Optional.empty(); } return elsewhereProvider; }
public Exporter getExporter(String formatName) throws ExportException { try { Iterator<Exporter> exporters = loader.iterator(); while (exporters.hasNext()) { Exporter e = exporters.next(); if (e.getProviderName().equals(formatName)) { return e; } } } catch (ServiceConfigurationError serviceError) { throw new ExportException("Service configuration error during export. " + serviceError.getMessage()); } catch (Exception ex) { throw new ExportException("Could not find Exporter \"" + formatName + "\", unknown exception"); } throw new ExportException("No such Exporter: " + formatName); }
public static <T> void loadServices(ServiceRegistry<T> registry) { Iterable<T> iterable = SystemUtils.loadServices(registry.getServiceType()); final Iterator<T> iterator = iterable.iterator(); //noinspection WhileLoopReplaceableByForEach while (iterator.hasNext()) { try { registry.addService(iterator.next()); } catch (ServiceConfigurationError e) { final Logger logger; if (moduleContext != null) { logger = moduleContext.getLogger(); } else { logger = BeamLogManager.getSystemLogger(); } logger.log(Level.WARNING, e.getMessage(), e.getCause()); } } }
public void exportFormat(Dataset dataset, String formatName) throws ExportException { try { Iterator<Exporter> exporters = loader.iterator(); while (exporters.hasNext()) { Exporter e = exporters.next(); if (e.getProviderName().equals(formatName)) { DatasetVersion releasedVersion = dataset.getReleasedVersion(); if (releasedVersion == null) { throw new IllegalStateException("No Released Version"); } final JsonObjectBuilder datasetAsJsonBuilder = JsonPrinter.jsonAsDatasetDto(releasedVersion); cacheExport(releasedVersion, formatName, datasetAsJsonBuilder.build(), e); } } } catch (ServiceConfigurationError serviceError) { throw new ExportException("Service configuration error during export. " + serviceError.getMessage()); } catch (IllegalStateException e) { throw new ExportException("No published version found during export. " + dataset.getGlobalId().toString()); } }
private void loadDozerModules(BeanContainer beanContainer, DestBeanBuilderCreator destBeanBuilderCreator, BeanMappingGenerator beanMappingGenerator, PropertyDescriptorFactory propertyDescriptorFactory, DestBeanCreator destBeanCreator) { try { ServiceLoader<DozerModule> services = ServiceLoader.load(DozerModule.class); for (DozerModule module : services) { module.init(); module.init(beanContainer, destBeanCreator, propertyDescriptorFactory); destBeanBuilderCreator.addPluggedStrategies(module.getBeanBuilderCreationStrategies()); beanMappingGenerator.addPluggedFieldDetectors(module.getBeanFieldsDetectors()); propertyDescriptorFactory.addPluggedPropertyDescriptorCreationStrategies(module.getPropertyDescriptorCreationStrategies()); } } catch (ServiceConfigurationError ex) { LOG.error("{}", ex.getMessage()); } } }