private static Class<?> loadDriver(String driverName, String moduleName) throws IllegalArgumentException { try { Module module = Module.getCallerModuleLoader().loadModule(moduleName); AgroalLogger.DRIVER_LOGGER.debugf("loaded module '%s' for driver: %s", moduleName, driverName); ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class); if (serviceLoader.iterator().hasNext()) { // Consider just the first definition. User can use different implementation only with explicit declaration of class attribute Class<?> driverClass = serviceLoader.iterator().next().getClass(); AgroalLogger.DRIVER_LOGGER.driverLoaded(driverClass.getName(), driverName); return driverClass; } return null; } catch (ModuleLoadException e) { throw AgroalLogger.DRIVER_LOGGER.loadModuleException(e, moduleName); } }
ServiceLoader<ServletContainerInitializer> serviceLoader = depModule.loadService(ServletContainerInitializer.class); for (ServletContainerInitializer service : serviceLoader) { if(sciClasses.add(service.getClass())) {
final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class); if (serviceLoader != null) for (Driver driver : serviceLoader) {
final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class); boolean driverLoaded = false; if (serviceLoader != null) {
serialization.addAdvancedExternalizer(new AdvancedExternalizerAdapter<>(id++, externalizer)); for (Externalizer<?> externalizer : module.loadService(Externalizer.class)) { InfinispanLogger.ROOT_LOGGER.debugf("Cache container %s will use an externalizer for %s", this.name, externalizer.getTargetClass().getName()); serialization.addAdvancedExternalizer(new AdvancedExternalizerAdapter<>(id++, externalizer));
CacheConfigurationServiceConfigurator(PathAddress address) { super(CONFIGURATION, address); this.memory = new ServiceSupplierDependency<>(CacheComponent.MEMORY.getServiceName(address)); this.expiration = new ServiceSupplierDependency<>(CacheComponent.EXPIRATION.getServiceName(address)); this.locking = new ServiceSupplierDependency<>(CacheComponent.LOCKING.getServiceName(address)); this.persistence = new ServiceSupplierDependency<>(CacheComponent.PERSISTENCE.getServiceName(address)); this.transaction = new ServiceSupplierDependency<>(CacheComponent.TRANSACTION.getServiceName(address)); this.module = new ServiceSupplierDependency<>(CacheComponent.MODULE.getServiceName(address)); String containerName = address.getParent().getLastElement().getValue(); String cacheName = address.getLastElement().getValue(); this.configurator = new ConfigurationServiceConfigurator(this.getServiceName(), containerName, cacheName, this.andThen(builder -> { GroupsConfigurationBuilder groupsBuilder = builder.clustering().hash().groups().enabled(); for (Grouper<?> grouper : this.module.get().loadService(Grouper.class)) { groupsBuilder.addGrouper(grouper); } })).require(this); }
public ContentHandler createContentHandler(final String mimeType) { for (Module module : modules) { ServiceLoader<ContentHandlerFactory> loader = module.loadService(ContentHandlerFactory.class); for (ContentHandlerFactory factory : loader) try { final ContentHandler handler = factory.createContentHandler(mimeType); if (handler != null) { return handler; } } catch (RuntimeException e) { // ignored } } return null; } }
public ContentHandler createContentHandler(final String mimeType) { for (Module module : modules) { ServiceLoader<ContentHandlerFactory> loader = module.loadService(ContentHandlerFactory.class); for (ContentHandlerFactory factory : loader) try { final ContentHandler handler = factory.createContentHandler(mimeType); if (handler != null) { return handler; } } catch (RuntimeException e) { // ignored } } return null; } }
private URLStreamHandler locateHandler(final String protocol) { for (Module module : modules) { ServiceLoader<URLStreamHandlerFactory> loader = module.loadService(URLStreamHandlerFactory.class); for (URLStreamHandlerFactory factory : loader) { try { final URLStreamHandler handler = factory.createURLStreamHandler(protocol); if (handler != null) { return handler; } } catch (RuntimeException e) { // ignored } } } return null; }
@Override public String decorateWithServiceLoader(String s) { log.info("-----> In decorateWithServiceLoader() - " + s); Module module = Module.forClass(TestService.class); ServiceLoader<TestService> loader = module.loadService(TestService.class); for (TestService service : loader) { log.info("-----> Found service " + service); s = service.decorate(s); log.info("-----> " + s); } return s; } }
private Extension getExtension(ObjectNode config) throws Exception { String moduleId = config.get("module-id").asText(); ModuleIdentifier moduleIdentifier = ModuleIdentifier.create(moduleId); ModuleLoader loader = ModuleLoader.forClass(this.getClass()); Module module = loader.loadModule(moduleIdentifier); ServiceLoader<Extension> extensions = module.loadService(Extension.class); for (Extension extension : extensions) { return extension; } throw new Exception("No extension found in module: " + moduleId); }
private <T extends Class> T lookupService(Module module, T serviceInterface, String serviceClassName) { T serviceClass = null; for (Object service : module.loadService(serviceInterface)) { if (service.getClass().getName().equals(serviceClassName)) { serviceClass = (T)service.getClass(); break; } } if (serviceClass == null) { throw new ConfigurationException(String.format("The module '%1$s' does not contain the service '%2$s'.", module.getIdentifier().getName(), serviceClassName)); } return serviceClass; }
/** * Load a service loader from a module in the caller's module loader. The caller's * module loader refers to the loader of the module of the class that calls this method. * Note that {@link #loadService(Class)} is more efficient since it does not need to crawl * the stack. * * @param <S> the the service type * @param identifier the module identifier containing the service loader * @param serviceType the service type class * @return the loaded service from the caller's module * @throws ModuleLoadException if the named module failed to load */ public static <S> ServiceLoader<S> loadServiceFromCallerModuleLoader(ModuleIdentifier identifier, Class<S> serviceType) throws ModuleLoadException { return getCallerModuleLoader().loadModule(identifier).loadService(serviceType); }
/** * Load a service loader from a module in the caller's module loader. The caller's * module loader refers to the loader of the module of the class that calls this method. * Note that {@link #loadService(Class)} is more efficient since it does not need to crawl * the stack. * * @param <S> the the service type * @param name the module name containing the service loader * @param serviceType the service type class * @return the loaded service from the caller's module * @throws ModuleLoadException if the named module failed to load */ public static <S> ServiceLoader<S> loadServiceFromCallerModuleLoader(String name, Class<S> serviceType) throws ModuleLoadException { return getCallerModuleLoader().loadModule(name).loadService(serviceType); }
/** * Main entry-point. * * @param args Ignored. * @throws Exception if an error occurs. */ public static void main(String... args) throws Exception { if (System.getProperty("boot.module.loader") == null) { System.setProperty("boot.module.loader", "org.wildfly.swarm.bootstrap.modules.BootModuleLoader"); } Module bootstrap = Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("swarm.application")); ServiceLoader<ContainerFactory> factory = bootstrap.loadService(ContainerFactory.class); Iterator<ContainerFactory> factoryIter = factory.iterator(); if (!factoryIter.hasNext()) { simpleMain(args); } else { factoryMain(factoryIter.next(), args); } }
/** Main entry-point. * * @param args Ignored. * @throws Exception if an error occurs. */ public static void main(String... args) throws Exception { if ( System.getProperty( "boot.module.loader" ) == null ) { System.setProperty("boot.module.loader", "org.wildfly.swarm.bootstrap.modules.BootModuleLoader" ); } Module bootstrap = Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("swarm.application")); ServiceLoader<ContainerFactory> factory = bootstrap.loadService(ContainerFactory.class); Iterator<ContainerFactory> factoryIter = factory.iterator(); if ( ! factoryIter.hasNext() ) { simpleMain( args ); } else { factoryMain( factoryIter.next(), args ); } }
@SuppressWarnings("rawtypes") private ServiceLoader<ShapeExtension> loadShapeExtensions( final String moduleName) throws ModuleLoadException { ModuleLoader moduleLoader = ModuleLoader.forClass(Main.class); Module loadModule = moduleLoader.loadModule(ModuleIdentifier .create(moduleName)); return loadModule.loadService(ShapeExtension.class); }
/** * If the deployment has a module attached it will ask the module to load the ServiceActivator services. * * @param context the deployment unit context */ public void processDeployment(DeploymentUnitContext context) throws DeploymentUnitProcessingException { if(context.getAttachment(ServiceActivatorMarker.ATTACHMENT_KEY) == null) return; // Skip it if it has not been marked final Module module = context.getAttachment(ModuleDeploymentProcessor.MODULE_ATTACHMENT_KEY); if (module == null) return; // Skip deployments with no module final ServiceActivatorContext serviceActivatorContext = new ServiceActivatorContextImpl(context.getBatchBuilder()); for(ServiceActivator serviceActivator : module.loadService(ServiceActivator.class)) { serviceActivator.activate(serviceActivatorContext); } } }
private void configureExtensions(final DeploymentUnit deployment) throws DeploymentUnitProcessingException { addExtension(deployment, new PicketLinkCoreSubsystemExtension(getPartitionManagerJNDIUrl(deployment))); try { Module module = Module.getBootModuleLoader().loadModule(ORG_PICKETLINK_CORE_MODULE); for (Extension e : module.loadService(Extension.class)) { addExtension(deployment, e); } } catch (ModuleLoadException e) { throw new DeploymentUnitProcessingException("Failed to configure CDI extensions for deployment [" + deployment.getName() + "].", e); } }
CacheConfigurationServiceConfigurator(PathAddress address) { super(CONFIGURATION, address); this.memory = new ServiceSupplierDependency<>(CacheComponent.MEMORY.getServiceName(address)); this.expiration = new ServiceSupplierDependency<>(CacheComponent.EXPIRATION.getServiceName(address)); this.locking = new ServiceSupplierDependency<>(CacheComponent.LOCKING.getServiceName(address)); this.persistence = new ServiceSupplierDependency<>(CacheComponent.PERSISTENCE.getServiceName(address)); this.transaction = new ServiceSupplierDependency<>(CacheComponent.TRANSACTION.getServiceName(address)); this.module = new ServiceSupplierDependency<>(CacheComponent.MODULE.getServiceName(address)); String containerName = address.getParent().getLastElement().getValue(); String cacheName = address.getLastElement().getValue(); this.configurator = new ConfigurationServiceConfigurator(this.getServiceName(), containerName, cacheName, this.andThen(builder -> { GroupsConfigurationBuilder groupsBuilder = builder.clustering().hash().groups().enabled(); for (Grouper<?> grouper : this.module.get().loadService(Grouper.class)) { groupsBuilder.addGrouper(grouper); } })).require(this); }