Search in sources :

Example 46 with ServiceLoader

use of java.util.ServiceLoader in project knox by apache.

the class ServiceDefinitionDeploymentContributorTest method testServiceLoader.

@Test
public void testServiceLoader() throws Exception {
    ServiceLoader loader = ServiceLoader.load(ProviderDeploymentContributor.class);
    Iterator iterator = loader.iterator();
    assertThat("Service iterator empty.", iterator.hasNext());
    while (iterator.hasNext()) {
        Object object = iterator.next();
        if (object instanceof ServiceDefinitionDeploymentContributor) {
            fail("The ServiceDefinition deployment contributor is not meant to be loaded using the service loader mechanism");
        }
    }
}
Also used : ServiceLoader(java.util.ServiceLoader) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 47 with ServiceLoader

use of java.util.ServiceLoader in project knox by apache.

the class HtmlPrefixProcessorTest method testServiceLoader.

@SuppressWarnings("rawtypes")
@Test
public void testServiceLoader() throws Exception {
    ServiceLoader loader = ServiceLoader.load(UrlRewriteFunctionProcessor.class);
    Iterator iterator = loader.iterator();
    assertThat("Service iterator empty.", iterator.hasNext());
    while (iterator.hasNext()) {
        Object object = iterator.next();
        if (object instanceof HtmlPrefixProcessor) {
            return;
        }
    }
    fail("Failed to find " + HtmlPrefixProcessor.class.getName() + " via service loader.");
}
Also used : ServiceLoader(java.util.ServiceLoader) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 48 with ServiceLoader

use of java.util.ServiceLoader in project knox by apache.

the class FrontendFunctionDescriptorTest method testServiceLoader.

@SuppressWarnings("rawtypes")
@Test
public void testServiceLoader() throws Exception {
    ServiceLoader loader = ServiceLoader.load(UrlRewriteFunctionDescriptor.class);
    Iterator iterator = loader.iterator();
    assertThat("Service iterator empty.", iterator.hasNext());
    while (iterator.hasNext()) {
        Object object = iterator.next();
        if (object instanceof FrontendFunctionDescriptor) {
            return;
        }
    }
    fail("Failed to find " + FrontendFunctionDescriptor.class.getName() + " via service loader.");
}
Also used : ServiceLoader(java.util.ServiceLoader) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 49 with ServiceLoader

use of java.util.ServiceLoader in project knox by apache.

the class AnonymousAuthDeploymentContributorTest method testServiceLoader.

@Test
public void testServiceLoader() throws Exception {
    ServiceLoader loader = ServiceLoader.load(ProviderDeploymentContributor.class);
    Iterator iterator = loader.iterator();
    assertThat("Service iterator empty.", iterator.hasNext());
    while (iterator.hasNext()) {
        Object object = iterator.next();
        if (object instanceof AnonymousAuthDeploymentContributor) {
            return;
        }
    }
    fail("Failed to find " + AnonymousAuthDeploymentContributor.class.getName() + " via service loader.");
}
Also used : ServiceLoader(java.util.ServiceLoader) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 50 with ServiceLoader

use of java.util.ServiceLoader in project wildfly-swarm by wildfly-swarm.

the class StandaloneXMLParserProducer method setupFactory.

private void setupFactory(Fraction fraction) throws Exception {
    try (AutoCloseable handle = Performance.time("Setting up XML parser: " + fraction.getClass().getSimpleName())) {
        WildFlyExtension anno = fraction.getClass().getAnnotation(WildFlyExtension.class);
        if (anno == null) {
            return;
        }
        String extensionModuleName = anno.module();
        String extensionClassName = anno.classname();
        boolean noClass = anno.noClass();
        if (extensionClassName != null && extensionClassName.trim().isEmpty()) {
            extensionClassName = null;
        }
        Module extensionModule = Module.getBootModuleLoader().loadModule(extensionModuleName);
        if (noClass) {
        // ignore it all
        } else if (extensionClassName != null) {
            Class<?> extCls = extensionModule.getClassLoader().loadClass(extensionClassName);
            try {
                Extension ext = (Extension) extCls.newInstance();
                add(ext);
            } catch (InstantiationException | IllegalAccessException e) {
                SwarmConfigMessages.MESSAGES.errorCreatingExtension(extensionClassName, extensionModuleName, e);
            }
        } else {
            ServiceLoader<Extension> extensionLoader = extensionModule.loadService(Extension.class);
            Iterator<Extension> extensionIter = extensionLoader.iterator();
            List<Extension> extensions = new ArrayList<>();
            if (extensionIter.hasNext()) {
                Extension ext = extensionIter.next();
                extensions.add(ext);
            }
            if (extensions.size() > 1) {
                throw SwarmMessages.MESSAGES.fractionHasMultipleExtensions(fraction.getClass().getName(), extensions.stream().map(Objects::toString).collect(Collectors.toList()));
            }
            if (!extensions.isEmpty()) {
                add(extensions.get(0));
            }
        }
    }
}
Also used : Extension(org.jboss.as.controller.Extension) WildFlyExtension(org.wildfly.swarm.spi.api.annotations.WildFlyExtension) ServiceLoader(java.util.ServiceLoader) WildFlyExtension(org.wildfly.swarm.spi.api.annotations.WildFlyExtension) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Module(org.jboss.modules.Module)

Aggregations

ServiceLoader (java.util.ServiceLoader)59 Iterator (java.util.Iterator)42 Test (org.junit.Test)40 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 NoSuchElementException (java.util.NoSuchElementException)3 ServiceConfigurationError (java.util.ServiceConfigurationError)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 CharsetProvider (java.nio.charset.spi.CharsetProvider)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Optional (java.util.Optional)2 ResourceBundle (java.util.ResourceBundle)2 BundleReference (org.osgi.framework.BundleReference)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Person (com.dockerx.traffic.providespro.entity.Person)1 Analysis (com.dockerx.traffic.providespro.service.Analysis)1 Joiner.on (com.google.common.base.Joiner.on)1 ImmutableMap (com.google.common.collect.ImmutableMap)1