List of usage examples for java.util ServiceLoader iterator
public Iterator<S> iterator()
From source file:org.pentaho.hadoop.shim.HadoopConfigurationLocator.java
/** * Locates an implementation of {@code service} using the {@link ServiceLoader}. * * @param cl Class loader to look for implementations in * @return The first implementation found. *///from w ww . j a v a2 s. c o m protected <T> T locateServiceImpl(ClassLoader cl, Class<T> service) { ServiceLoader<T> loader = ServiceLoader.load(service, cl); Iterator<T> iter = loader.iterator(); if (iter.hasNext()) { return iter.next(); } return null; }
From source file:org.pentaho.pms.mql.dialect.SQLDialectFactory.java
/** * Load and register dialects defined as service providers implementing {@link SQLDialectInterface} (via Java's * ServiceLoader mechanism).// w w w.j a v a 2s.c om */ private void loadDialectPlugins() { ServiceLoader<SQLDialectInterface> dialects = ServiceLoader.load(SQLDialectInterface.class); Iterator<SQLDialectInterface> dialectIter = dialects.iterator(); while (dialectIter.hasNext()) { SQLDialectInterface dialect = null; try { dialect = dialectIter.next(); // Try to instantiate the next dialect } catch (ServiceConfigurationError err) { // Log an error if dialect instantiation/registration fails for any other reason. We don't know the dialect // we attempted to load here so log it as a generic error with stack trace. logger.warn(Messages.getErrorString("SQLDialectFactory.WARN_0001_DIALECT_COULD_NOT_BE_LOADED", //$NON-NLS-1$ err.getMessage())); if (logger.isDebugEnabled()) { logger.debug(Messages.getErrorString("SQLDialectFactory.WARN_0001_DIALECT_COULD_NOT_BE_LOADED", //$NON-NLS-1$ err.getMessage()), err); } } if (dialect != null) { addDialect(dialect); } } }
From source file:org.seedstack.seed.security.internal.SeedSecurityCorePlugin.java
/** * Plugin constructor/*from ww w .j a va 2 s .com*/ */ public SeedSecurityCorePlugin() { ServiceLoader<SeedSecurityPlugin> loader = ServiceLoader.load(SeedSecurityPlugin.class, SeedReflectionUtils.findMostCompleteClassLoader(SeedSecurityCorePlugin.class)); Iterator<SeedSecurityPlugin> it = loader.iterator(); if (!it.hasNext()) { securityPlugins.add(new DefaultSecurityPlugin()); } else { while (it.hasNext()) { securityPlugins.add(it.next()); } } }
From source file:org.sikuli.scriptrunner.ScriptRunner.java
public static void initScriptingSupport() { if (isReady) { return;//from ww w .ja va 2 s .c o m } log(lvl, "initScriptingSupport: enter"); if (scriptRunner.isEmpty()) { EndingTypes.put("py", CPYTHON); EndingTypes.put("rb", CRUBY); EndingTypes.put("txt", CPLAIN); for (String k : EndingTypes.keySet()) { typeEndings.put(EndingTypes.get(k), k); } ServiceLoader<IScriptRunner> rloader = ServiceLoader.load(IScriptRunner.class); Iterator<IScriptRunner> rIterator = rloader.iterator(); while (rIterator.hasNext()) { IScriptRunner current = null; try { current = rIterator.next(); } catch (ServiceConfigurationError e) { log(lvl, "initScriptingSupport: warning: %s", e.getMessage()); continue; } String name = current.getName(); if (name != null && !name.startsWith("Not")) { scriptRunner.put(name, current); current.init(null); log(lvl, "initScriptingSupport: added: %s", name); } } } if (scriptRunner.isEmpty()) { Debug.error("Settings: No scripting support available. Rerun Setup!"); String em = "Terminating: No scripting support available. Rerun Setup!"; log(-1, em); if (Settings.isRunningIDE) { Sikulix.popError(em, "IDE has problems ..."); } System.exit(1); } else { RDEFAULT = (String) scriptRunner.keySet().toArray()[0]; EDEFAULT = scriptRunner.get(RDEFAULT).getFileEndings()[0]; for (IScriptRunner r : scriptRunner.values()) { for (String e : r.getFileEndings()) { if (!supportedRunner.containsKey(EndingTypes.get(e))) { supportedRunner.put(EndingTypes.get(e), r); } } } } log(lvl, "initScriptingSupport: exit with defaultrunner: %s (%s)", RDEFAULT, EDEFAULT); isReady = true; }
From source file:org.wildfly.security.tool.Command.java
protected Supplier<Provider[]> getProvidersSupplier(final String providersList) { return () -> { if (providersList != null && !providersList.isEmpty()) { final String[] providerNames = providersList.split(","); List<Provider> providers = new ArrayList<>(providerNames.length); for (String p : providerNames) { Provider provider = Security.getProvider(p.trim()); if (provider != null) { providers.add(provider); }/* w ww .j a v a 2s. c o m*/ } ServiceLoader<Provider> providerLoader = ServiceLoader.load(Provider.class); for (Provider provider : providerLoader) { for (String p : providerNames) { if (provider.getName().equals(p)) { providers.add(provider); break; } } } if (providers.isEmpty()) { throw ElytronToolMessages.msg.unknownProvider(providersList); } return providers.toArray(new Provider[providers.size()]); } else { // when no provider list is specified, load all Providers from service loader except WildFlyElytron Provider ServiceLoader<Provider> providerLoader = ServiceLoader.load(Provider.class); Iterator<Provider> providerIterator = providerLoader.iterator(); List<Provider> providers = new ArrayList<>(); while (providerIterator.hasNext()) { Provider provider = providerIterator.next(); if (provider.getName().equals("WildFlyElytron")) continue; providers.add(provider); } return providers.toArray(new Provider[providers.size()]); } }; }
From source file:org.wso2.carbon.apimgt.tracing.TracingServiceImpl.java
private TracingServiceImpl() { try {//from w ww .j a v a 2 s . co m String openTracerName = configuration.getFirstProperty(TracingConstants.OPEN_TRACER_NAME) != null ? configuration.getFirstProperty(TracingConstants.OPEN_TRACER_NAME) : TracingConstants.DEFAULT_OPEN_TRACER_NAME; Boolean remoteTracerEnabled = Boolean .valueOf(configuration.getFirstProperty(TracingConstants.OPEN_TRACER_ENABLED) != null ? configuration.getFirstProperty(TracingConstants.OPEN_TRACER_ENABLED) : TracingConstants.DEFAULT_OPEN_TRACER_ENABLED); String tracerName = (openTracerName != null && remoteTracerEnabled) ? openTracerName : TracingConstants.LOG; ServiceLoader<OpenTracer> openTracers = ServiceLoader.load(OpenTracer.class, OpenTracer.class.getClassLoader()); Iterator iterator = openTracers.iterator(); while (iterator.hasNext()) { OpenTracer openTracer = (OpenTracer) iterator.next(); if (tracerName.equalsIgnoreCase(openTracer.getName())) { this.tracer = openTracer; } } } catch (Exception e) { log.error("Error in reading openTracerName", e); } }