當前位置: 首頁>>代碼示例>>Java>>正文


Java ServiceLoader.iterator方法代碼示例

本文整理匯總了Java中java.util.ServiceLoader.iterator方法的典型用法代碼示例。如果您正苦於以下問題:Java ServiceLoader.iterator方法的具體用法?Java ServiceLoader.iterator怎麽用?Java ServiceLoader.iterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.ServiceLoader的用法示例。


在下文中一共展示了ServiceLoader.iterator方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loadProviderAsService

import java.util.ServiceLoader; //導入方法依賴的package包/類
private static AsynchronousChannelProvider loadProviderAsService() {
    ServiceLoader<AsynchronousChannelProvider> sl =
        ServiceLoader.load(AsynchronousChannelProvider.class,
                           ClassLoader.getSystemClassLoader());
    Iterator<AsynchronousChannelProvider> i = sl.iterator();
    for (;;) {
        try {
            return (i.hasNext()) ? i.next() : null;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:AsynchronousChannelProvider.java

示例2: loadProviderAsService

import java.util.ServiceLoader; //導入方法依賴的package包/類
private static boolean loadProviderAsService() {

        ServiceLoader<SelectorProvider> sl =
            ServiceLoader.load(SelectorProvider.class,
                               ClassLoader.getSystemClassLoader());
        Iterator<SelectorProvider> i = sl.iterator();
        for (;;) {
            try {
                if (!i.hasNext())
                    return false;
                provider = i.next();
                return true;
            } catch (ServiceConfigurationError sce) {
                if (sce.getCause() instanceof SecurityException) {
                    // Ignore the security exception, try the next provider
                    continue;
                }
                throw sce;
            }
        }
    }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:22,代碼來源:SelectorProvider.java

示例3: initialize

import java.util.ServiceLoader; //導入方法依賴的package包/類
/**
 * Initialize a specific type
 * 
 * @param type
 *            the initializer specific type, see
 *            {@link Initializer#initialize(Object)}
 * @param classloader
 *            a specific class loader to use
 */
public static void initialize ( final Object type, final ClassLoader classloader )
{
    logger.debug ( "Initializing: {}", type );

    final ServiceLoader<Initializer> loader = ServiceLoader.load ( Initializer.class, classloader );
    final Iterator<Initializer> i = loader.iterator ();
    while ( i.hasNext () )
    {
        final Initializer initializer = i.next ();
        logger.debug ( "Processing: {}", initializer );

        try
        {
            initializer.initialize ( type );
        }
        catch ( final Exception e )
        {
            logger.info ( "Failed to initialize", e );
        }
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:31,代碼來源:ServiceLoaderProcessor.java

示例4: test

import java.util.ServiceLoader; //導入方法依賴的package包/類
@Test
public void test() {
	ServiceLoader<ClientModuleFactory> loader = ServiceLoader.load(ClientModuleFactory.class);
	Iterator<ClientModuleFactory> iterator = loader.iterator();

	Set<Class> moduleClasses = new HashSet<>();
	while (iterator.hasNext()) {
		ClientModuleFactory moduleFactory = iterator.next();
		Module module = moduleFactory.create();
		moduleClasses.add(module.getClass());
	}

	Assert.assertEquals(2, moduleClasses.size());
	Assert.assertTrue(moduleClasses.contains(ValidationModule.class));
	Assert.assertTrue(moduleClasses.contains(MetaModule.class));
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:17,代碼來源:ValidationClientModuleFactoryTest.java

示例5: testIteratorNext

import java.util.ServiceLoader; //導入方法依賴的package包/類
@Test(expectedExceptions = { ConcurrentModificationException.class })
public void testIteratorNext() {
    ServiceLoader<ScriptEngineFactory> sl = load(ScriptEngineFactory.class);
    Iterator<ScriptEngineFactory> iterator = sl.iterator();
    assertTrue(iterator.hasNext());
    sl.reload();
    iterator.next();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:ReloadTest.java

示例6: getInstance

import java.util.ServiceLoader; //導入方法依賴的package包/類
public static BookService getInstance(){
	ServiceLoader<BookServiceProvider> sl
           = ServiceLoader.load(BookServiceProvider.class);
       Iterator<BookServiceProvider> iter = sl.iterator();
       if (!iter.hasNext())
           throw new RuntimeException("No service providers found!");
       BookServiceProvider provider = null;
       while(iter.hasNext()){
       	provider = iter.next();
       	System.out.println(provider.getClass());
       }
       return provider.getBookService();
}
 
開發者ID:PacktPublishing,項目名稱:Java-9-Cookbook,代碼行數:14,代碼來源:BookService.java

示例7: testSequentialUse1

import java.util.ServiceLoader; //導入方法依賴的package包/類
@Test
public void testSequentialUse1() {
    ServiceLoader<S> sl = ServiceLoader.load(S.class, testClassLoader);

    Iterator<S> iterator1 = sl.iterator();
    iterator1.next();
    iterator1.next();
    assertFalse(iterator1.hasNext());

    Iterator<S> iterator2 = sl.iterator();
    iterator2.next();
    iterator2.next();
    assertFalse(iterator2.hasNext());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:TwoIterators.java

示例8: validateServiceIsLocatableViaServiceLoader

import java.util.ServiceLoader; //導入方法依賴的package包/類
@Test
public void validateServiceIsLocatableViaServiceLoader() {
    ServiceLoader<ControllerService> loader = ServiceLoader.<ControllerService> load(ControllerService.class);
    Iterator<ControllerService> iter = loader.iterator();
    boolean present = false;
    while (iter.hasNext()) {
        ControllerService cs = iter.next();
        assertTrue(cs instanceof JMSConnectionFactoryProviderDefinition);
        present = true;
    }
    assertTrue(present);
}
 
開發者ID:lsac,項目名稱:nifi-jms-jndi,代碼行數:13,代碼來源:JMSConnectionFactoryProviderTest.java

示例9: loadFirst

import java.util.ServiceLoader; //導入方法依賴的package包/類
public static <S> S loadFirst(Class<S> clazz) {
    final ServiceLoader<S> loader = loadAll(clazz);
    final Iterator<S> iterator = loader.iterator();
    if (!iterator.hasNext()) {
        throw new IllegalStateException(String.format(
                "No implementation defined in /META-INF/services/%s, please check whether the file exists and has the right implementation class!",
                clazz.getName()));
    }
    return iterator.next();
}
 
開發者ID:yu199195,項目名稱:myth,代碼行數:11,代碼來源:ServiceBootstrap.java

示例10: getInstance

import java.util.ServiceLoader; //導入方法依賴的package包/類
@Override
public ServiceDiscovery getInstance() {
	ServiceLoader<ServiceDiscovery> loader = ServiceLoader.load(ServiceDiscovery.class);
	Iterator<ServiceDiscovery> iterator = loader.iterator();
	if (iterator.hasNext()) {
		ServiceDiscovery discovery = iterator.next();
		PreconditionUtil.assertFalse("expected unique ServiceDiscovery implementation, got: " + loader, iterator.hasNext());
		return discovery;
	}
	return null;
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:12,代碼來源:DefaultServiceDiscoveryFactory.java

示例11: test

import java.util.ServiceLoader; //導入方法依賴的package包/類
@Test
public void test() {
	ServiceLoader<ClientModuleFactory> loader = ServiceLoader.load(ClientModuleFactory.class);
	Iterator<ClientModuleFactory> iterator = loader.iterator();
	Assert.assertTrue(iterator.hasNext());
	ClientModuleFactory moduleFactory = iterator.next();
	Assert.assertFalse(iterator.hasNext());
	Module module = moduleFactory.create();
	Assert.assertTrue(module instanceof MetaModule);
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:11,代碼來源:MetaClientModuleFactoryTest.java

示例12: getInstance

import java.util.ServiceLoader; //導入方法依賴的package包/類
public static ReportWriter getInstance() {
    ServiceLoader<ReportWriter> loader = ServiceLoader.load(ReportWriter.class);
    final Iterator<ReportWriter> it = loader.iterator();
    final ReportWriter server;
    if (!it.hasNext()) {
        throw new RuntimeException("No ReportWriter in classpath");
    } else {
        server = it.next();
    }
    if (it.hasNext()) {
        LoggerFactory.getLogger(ReportWriter.class).warn("Multiple bindings for ReportWriter found: {}", loader.iterator());
    }
    return server;
}
 
開發者ID:RBMHTechnology,項目名稱:vind,代碼行數:15,代碼來源:ReportWriter.java

示例13: loadAdditionalSuits

import java.util.ServiceLoader; //導入方法依賴的package包/類
public static void loadAdditionalSuits(List<PluginProvider> providers) {

        ServiceLoader<PluginProvider> serviceLoader = ServiceLoader
                .load(PluginProvider.class);

        Iterator<PluginProvider> iterator = serviceLoader.iterator();

        while (iterator.hasNext()) {
            PluginProvider provider = iterator.next();
            providers.add(provider);
        }
    }
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:13,代碼來源:AdditionalPluginLoader.java

示例14: create

import java.util.ServiceLoader; //導入方法依賴的package包/類
public static HttpServer create(int port) {
    ServiceLoader<HttpServerProvider> sl
        = ServiceLoader.load(HttpServerProvider.class);
    Iterator<HttpServerProvider> iterator = sl.iterator();
    if (iterator.hasNext()) {
        HttpServerProvider provider = iterator.next();
        return provider.createHttpServer(port);
    } else {
        return new HttpServer(port) { };
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:HttpServer.java

示例15: determineCompilerOrThrow

import java.util.ServiceLoader; //導入方法依賴的package包/類
private void determineCompilerOrThrow()
{
	final String preferedCompiler = getProperty("preferedCompiler");
	LinkedList<JavaCompiler> allCompilers = null;
	
	JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
	if (compiler != null)
	{
		if ((preferedCompiler == null) || compiler.getClass().getName().equals(preferedCompiler))
		{
			_compiler = compiler;
			return;
		}
		
		allCompilers = new LinkedList<>();
		allCompilers.add(compiler);
	}
	
	final ServiceLoader<JavaCompiler> thirdPartyCompilers = ServiceLoader.load(JavaCompiler.class);
	Iterator<JavaCompiler> compilersIterator = thirdPartyCompilers.iterator();
	while (compilersIterator.hasNext())
	{
		compiler = compilersIterator.next();
		if ((preferedCompiler == null) || compiler.getClass().getName().equals(preferedCompiler))
		{
			_compiler = compiler;
			return;
		}
		
		if (allCompilers == null)
		{
			allCompilers = new LinkedList<>();
		}
		allCompilers.add(compilersIterator.next());
	}
	
	if (allCompilers != null)
	{
		compilersIterator = allCompilers.iterator();
		while (compilersIterator.hasNext())
		{
			compiler = compilersIterator.next();
			if ((preferedCompiler == null) || compiler.getClass().getName().equals(preferedCompiler))
			{
				break;
			}
		}
	}
	
	if (compiler == null)
	{
		throw new IllegalStateException("No javax.tools.JavaCompiler service installed!");
	}
	
	_compiler = compiler;
}
 
開發者ID:rubenswagner,項目名稱:L2J-Global,代碼行數:57,代碼來源:JavaScriptingEngine.java


注:本文中的java.util.ServiceLoader.iterator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。