private boolean getNextServiceLoader() { while (nextServiceLoader == null) { try { if (!serviceLoaderIterator.hasNext()) { return false; } nextServiceLoader = serviceLoaderIterator.next(); } catch (final ServiceConfigurationError e) { if (e.getCause() instanceof SecurityException) { // Ignore security exceptions // TODO Log? continue; } throw e; } } return true; }
Throwable cause = ee.getCause();
private boolean getNextServiceLoader() { while (nextServiceLoader == null) { try { if (!serviceLoaderIterator.hasNext()) { return false; } nextServiceLoader = serviceLoaderIterator.next(); } catch (final ServiceConfigurationError e) { if (e.getCause() instanceof SecurityException) { // Ignore security exceptions // TODO Log? continue; } throw e; } } return true; }
private boolean getNextServiceLoader() { while (nextServiceLoader == null) { try { if (!serviceLoaderIterator.hasNext()) { return false; } nextServiceLoader = serviceLoaderIterator.next(); } catch (final ServiceConfigurationError e) { if (e.getCause() instanceof SecurityException) { // Ignore security exceptions // TODO Log? continue; } throw e; } } return true; }
private static boolean loadProviderAsService() { final ServiceLoader<HttpServerProvider> loader = ServiceLoader.load(HttpServerProvider.class, null); final Iterator<HttpServerProvider> i = loader.iterator(); while (i.hasNext()) { try { provider = i.next(); return true; } catch (ServiceConfigurationError sce) { if (sce.getCause() instanceof SecurityException) { // Ignore the security exception, try the next provider continue; } throw sce; } } return false; }
@Override protected void initializeProviders() { ServiceLoader<ZoneRulesProvider> loader = ServiceLoader.load(ZoneRulesProvider.class, ZoneRulesProvider.class.getClassLoader()); for (ZoneRulesProvider provider : loader) { try { ZoneRulesProvider.registerProvider(provider); } catch (ServiceConfigurationError ex) { if (!(ex.getCause() instanceof SecurityException)) { throw ex; } } } } }
@Override protected void initializeProviders() { ServiceLoader<ZoneRulesProvider> loader = ServiceLoader.load(ZoneRulesProvider.class, ZoneRulesProvider.class.getClassLoader()); for (ZoneRulesProvider provider : loader) { try { ZoneRulesProvider.registerProvider(provider); } catch (ServiceConfigurationError ex) { if (!(ex.getCause() instanceof SecurityException)) { throw ex; } } } } }
/** check service definitions from jars, if there is one and it isn't gumshoe * * adapted from SelectorProvider.loadProviderAsService jdk6 */ private static SelectorProvider getProviderAsService() { ServiceLoader<SelectorProvider> sl = ServiceLoader.load(SelectorProvider.class, ClassLoader.getSystemClassLoader()); Iterator<SelectorProvider> i = sl.iterator(); for (;;) { try { if( ! i.hasNext()) return null; SelectorProvider candidate = i.next(); if( ! (candidate instanceof IoTraceSelectorProvider)) { return candidate; } } catch (ServiceConfigurationError sce) { if (sce.getCause() instanceof SecurityException) { // Ignore the security exception, try the next provider continue; } throw sce; } } }
private static void loadManagers() { Iterator<MonitorManager> managers = ServiceLoader.load(MonitorManager.class).iterator(); MonitorManager manager = null; //noinspection WhileLoopReplaceableByForEach while (managers.hasNext()) { try { MonitorManager curManager = managers.next(); manager = curManager; break; } catch (ServiceConfigurationError e) { if (!(e.getCause() instanceof UnsupportedOperatingSystemException)) { throw e; } } } if (manager == null) { // TODO Throw appropriate error if we found no manager // For now, we just stop with an error throw new Error("no manager found"); } else { INSTANCE = manager; } }
/** * Loads the next service from the {@link Iterator}. * * @param serviceFactories * {@link Iterator} over the {@link ServiceFactory} instances. * @param serviceContext * {@link ServiceContext}. * @return Next service. */ private static <S, F extends ServiceFactory<S>> S nextService(Iterator<F> serviceFactories, Class<F> serviceFactoryType, ServiceContext serviceContext) { // Obtain the next service factory F serviceFactory; try { serviceFactory = serviceFactories.next(); } catch (ServiceConfigurationError error) { Throwable cause = error.getCause(); throw new LoadServiceError(serviceFactoryType.getName(), cause != null ? cause : error); } // Create the service return createService(serviceFactory, serviceContext); }
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()); } } }