List of usage examples for java.util ServiceLoader load
@CallerSensitive public static <S> ServiceLoader<S> load(Class<S> service)
From source file:org.apache.hadoop.gateway.filter.rewrite.impl.FrontendFunctionProcessorTest.java
@SuppressWarnings("rawtypes") @Test/* ww w . ja v a 2 s . c om*/ 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 FrontendFunctionProcessor) { return; } } fail("Failed to find " + FrontendFunctionProcessor.class.getName() + " via service loader."); }
From source file:org.apache.mnemonic.Utils.java
/** * retrieve a non-volatile memory allocator service * /*w w w. j a v a 2 s .c om*/ * @param id * specify a name of allocator to retrieve * * @return the non-volatile memory allocator service instance */ public static NonVolatileMemoryAllocatorService getNonVolatileMemoryAllocatorService(String id) { NonVolatileMemoryAllocatorService ret = null; if (null == m_nvmasvcloader) { m_nvmasvcloader = ServiceLoader.load(NonVolatileMemoryAllocatorService.class); } Iterator<NonVolatileMemoryAllocatorService> svcit = m_nvmasvcloader.iterator(); NonVolatileMemoryAllocatorService svc = null; while (null == ret && svcit.hasNext()) { svc = svcit.next(); if (svc.getServiceId().equals(id)) { ret = svc; } } assert null != ret : "NonVolatileMemoryAllocatorService \'" + id + "\' not found!"; return ret; }
From source file:org.powertac.customer.CustomerModelService.java
@Override public String initialize(Competition competition, List<String> completedInits) { if (!completedInits.contains("DefaultBroker") || !completedInits.contains("TariffMarket")) return null; super.init(); tariffMarketService.registerNewTariffListener(this); //modelTypes = new ArrayList<Class<AbstractCustomerDeprecated>>(); models = new ArrayList<AbstractCustomer>(); // extract the model types ServiceLoader<AbstractCustomer> loader = ServiceLoader.load(AbstractCustomer.class); // Populate and initialize the models. // Note that the instances loaded by the service loader are discarded -- // the real instances are created by serverConfig. Iterator<AbstractCustomer> modelIterator = loader.iterator(); while (modelIterator.hasNext()) { AbstractCustomer modelEx = modelIterator.next(); for (Object modelObj : serverConfig.configureInstances(modelEx.getClass())) { AbstractCustomer model = (AbstractCustomer) modelObj; models.add(model);//from w w w .ja v a 2s.com model.setServiceAccessor(this); model.initialize(); // set default tariff here to make models testable outside Spring. for (CustomerInfo cust : model.getCustomerInfos()) { tariffMarketService.subscribeToTariff(tariffMarketService.getDefaultTariff(cust.getPowerType()), cust, cust.getPopulation()); customerRepo.add(cust); } } } return "Customer"; }
From source file:com.googlecode.fascinator.api.PluginManager.java
/** * Get a list of access control plugins/*from w w w .j a va 2 s.co m*/ * * @return map of access control plugin, or empty map if not found */ public static Map<String, AccessControl> getAccessControlPlugins() { Map<String, AccessControl> access_plugins = new HashMap<String, AccessControl>(); ServiceLoader<AccessControl> plugins = ServiceLoader.load(AccessControl.class); for (AccessControl plugin : plugins) { access_plugins.put(plugin.getId(), plugin); } return access_plugins; }
From source file:io.knotx.knot.templating.impl.HandlebarsKnotProxyImpl.java
private Handlebars createHandlebars() { Handlebars newHandlebars = new Handlebars(); DefaultHandlebarsHelpers.registerFor(newHandlebars); ServiceLoader.load(CustomHandlebarsHelper.class).iterator().forEachRemaining(helper -> { newHandlebars.registerHelper(helper.getName(), helper); LOGGER.info("Registered custom Handlebars helper: {}", helper.getName()); });/*w w w . ja va 2s . co m*/ return newHandlebars; }
From source file:org.ops4j.pax.web.itest.util.TestConfiguration.java
public static boolean isEquinox() { FrameworkFactory factory = ServiceLoader.load(FrameworkFactory.class).iterator().next(); return factory.getClass().getSimpleName().contains("Equinox"); }
From source file:org.messic.service.MessicMain.java
/** * Create an osgi framework/*from www . j a v a2s .c o m*/ * * @return {@link Framework} osgi framework created * @throws BundleException */ private static Framework createFramework() throws BundleException { FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next(); Framework framework = frameworkFactory.newFramework(getFelixConfig()); framework.start(); return framework; }
From source file:kenh.expl.Environment.java
/** * Load function package through <code>Extension</code>. * @see Extension//from w w w . ja v a 2s .c om */ private void loadFunctionPackages_Extension() { ServiceLoader<Extension> es = ServiceLoader.load(Extension.class); for (Extension e : es) { if (e != null) { Map<String, String> p = e.getFunctionPackages(); if (p != null && p.size() > 0) { Set<String> keys = p.keySet(); for (String key : keys) { String funcPackage = p.get(key); setFunctionPackage(key, funcPackage); } } } } }
From source file:org.apache.mnemonic.Utils.java
/** * retrieve a durable general computing service * * @param id//from w w w .j a v a 2 s . c om * specify a name of general computing to retrieve * * @return the durable general computing service instance */ public static GeneralComputingService getGeneralComputingService(String id) { GeneralComputingService ret = null; if (null == m_gcompsvcloader) { m_gcompsvcloader = ServiceLoader.load(GeneralComputingService.class); } Iterator<GeneralComputingService> svcit = m_gcompsvcloader.iterator(); GeneralComputingService svc = null; while (null == ret && svcit.hasNext()) { svc = svcit.next(); if (svc.getServiceId().equals(id)) { ret = svc; } } assert null != ret : "GeneralComputingService \'" + id + "\' not found!"; return ret; }
From source file:org.cloudfoundry.reconfiguration.tomee.DelegatingPropertiesProvider.java
private PropertiesProvider getPropertiesProvider(ServiceInfo serviceInfo) { final ServiceLoader<PropertiesProvider> serviceLoader = ServiceLoader.load(PropertiesProvider.class); for (PropertiesProvider propertiesProvider : serviceLoader) { if (propertiesProvider.canProvide(serviceInfo)) { if (logger.isLoggable(Level.FINE)) { logger.fine("Found suitable PropertiesProvider for serviceId " + serviceId + ": " + propertiesProvider.getClass()); }/* w w w. ja va 2 s . c o m*/ return propertiesProvider; } } throw new ConfigurationException( "Cannot find suitable PropertiesProvider for serviceId " + serviceId + ": " + serviceInfo); }