当前位置: 首页>>代码示例>>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;未经允许,请勿转载。