Example usage for java.util ServiceLoader load

List of usage examples for java.util ServiceLoader load

Introduction

In this page you can find the example usage for java.util ServiceLoader load.

Prototype

@CallerSensitive
public static <S> ServiceLoader<S> load(Class<S> service) 

Source Link

Document

Creates a new service loader for the given service type, using the current thread's java.lang.Thread#getContextClassLoader context class loader .

Usage

From source file:uk.ac.tgac.metaopt.OptimiserFactory.java

public OptimiserFactory() {
    this.loader = ServiceLoader.load(Optimiser.class);
}

From source file:org.sensorhub.test.osgi.TestOsgi.java

protected Framework getFramework() {
    Iterator<FrameworkFactory> it = ServiceLoader.load(org.osgi.framework.launch.FrameworkFactory.class)
            .iterator();/*from  www .  j  a va 2s  . com*/
    assertTrue("No OSGI implementation found in classpath", it.hasNext());

    Map<String, String> osgiConfig = new HashMap<String, String>();
    //osgiConfig.put(AutoProcessor.AUTO_DEPLOY_DIR_PROPERY, "");
    osgiConfig.put("org.osgi.framework.storage", CACHE_FOLDER);
    osgiConfig.put("org.osgi.framework.storage.clean", "onFirstInit");
    Framework fw = it.next().newFramework(osgiConfig);

    return fw;
}

From source file:com.bennavetta.appsite.processing.ProcessingConfiguration.java

@Bean
public ProcessingController processingController() {
    ProcessingController pc = new ProcessingController();

    ServiceLoader<Processor> loader = ServiceLoader.load(Processor.class);
    for (Processor proc : loader) {
        log.info("Found processor {}", proc);
        pc.register(proc);// ww  w  . j  a va2s.c o  m
    }

    ServiceLoader<OutputProcessor> postProcLoader = ServiceLoader.load(OutputProcessor.class);
    for (OutputProcessor postProc : postProcLoader) {
        log.info("Found post-processor {}", postProc);
        pc.register(postProc);
    }

    pc.setResourceService(resourceService);
    return pc;
}

From source file:org.overlord.sramp.atom.archive.expand.registry.ZipToSrampArchiveRegistry.java

/**
 * Uses the Java {@link ServiceLoader} mechanism to find contributed providers.
 *//*from   w w  w. java2s.  com*/
private static void discoverProviders() {
    for (ZipToSrampArchiveProvider provider : ServiceLoader.load(ZipToSrampArchiveProvider.class)) {
        providers.add(provider);
    }
}

From source file:uk.ac.tgac.rampart.util.SpiFactory.java

@SuppressWarnings("unchecked")
public SpiFactory(Class<T> clazz) {
    this.clazz = clazz;
    this.loader = ServiceLoader.load(clazz);
}

From source file:org.marketcetera.core.instruments.StaticInstrumentFunctionSelector.java

/**
 * Creates an instance.//www  .ja  v a 2s  .  c  o m
 *
 * @param inClass the instrument function handler class. Cannot be null.
 */
public StaticInstrumentFunctionSelector(Class<T> inClass) {
    Validate.notNull(inClass, "class"); //$NON-NLS-1$
    mClass = inClass;
    Map<Class<?>, T> handlers = new HashMap<Class<?>, T>();
    ServiceLoader<T> loader = ServiceLoader.load(inClass);
    for (T t : loader) {
        handlers.put(t.getInstrumentType(), t);
    }
    SLF4JLoggerProxy.debug(this, "Available handlers {}", handlers); //$NON-NLS-1$
    mHandlers = ImmutableMap.copyOf(handlers);
}

From source file:org.marketcetera.core.instruments.DynamicInstrumentFunctionSelector.java

/**
 * Creates an instance./*from w  ww.ja  v  a2 s .co m*/
 *
 * @param inClass the class of dynamic functions that are selected
 * by this instance. Cannot be null.
 */
public DynamicInstrumentFunctionSelector(Class<S> inClass) {
    Validate.notNull(inClass, "class"); //$NON-NLS-1$
    List<S> list = new LinkedList<S>();
    ServiceLoader<S> loader = ServiceLoader.load(inClass);
    for (S s : loader) {
        list.add(s);
    }
    SLF4JLoggerProxy.debug(this, "Available handlers {}", list); //$NON-NLS-1$
    mClass = inClass;
    mHandlers = ImmutableList.copyOf(list);
}

From source file:org.apache.hadoop.hive.ql.io.StorageFormatFactory.java

public StorageFormatFactory() {
    Map<String, StorageFormatDescriptor> localStorageFormats = new HashMap<String, StorageFormatDescriptor>();
    for (StorageFormatDescriptor descriptor : ServiceLoader.load(StorageFormatDescriptor.class)) {
        for (String name : descriptor.getNames()) {
            name = name.trim().toUpperCase();
            StorageFormatDescriptor oldDescriptor = localStorageFormats.put(name, descriptor);
            if (oldDescriptor != null) {
                String msg = "Storage Format Descriptor conflict at name '" + name + "', " + "the descriptor "
                        + descriptor + " is overriding " + oldDescriptor;
                LOG.warn(msg);/*from  w  w  w  . j  a va  2 s  . c o  m*/
            }
        }
    }
    this.storageFormats = ImmutableMap.copyOf(localStorageFormats);
}

From source file:org.mrgeo.cmd.MrGeo.java

/**
 * Discover, load, and store all mrgeo commands (using {@link CommandSpi}).
 * Using Java's ServiceLoader, discover all service providers for commands, load them for
 * future use.//w  ww.j  a v  a 2s .c  o  m
 */
private static void loadCommands() {
    commands = new TreeMap<>();

    ServiceLoader<CommandSpi> loader = ServiceLoader.load(CommandSpi.class);

    for (CommandSpi cmd : loader) {
        commands.put(cmd.getCommandName(), cmd);
    }

}

From source file:com.thoughtworks.go.security.AESEncrypter.java

private IVProvider getIvProviderInstance() {
    if (ivProvider == null) {
        synchronized (AESEncrypter.class) {
            if (ivProvider == null) {
                ivProvider = ServiceLoader.load(IVProvider.class).iterator().next();
            }/*from w ww.ja  va 2  s  .co m*/
        }
    }
    return ivProvider;
}