Java Code Examples for org.jboss.modules.ModuleLoader#loadModule()
The following examples show how to use
org.jboss.modules.ModuleLoader#loadModule() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DaemonServiceActivator.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 6 votes |
@Override public void start(StartContext context) throws StartException { try { final String artifactName = System.getProperty(BootstrapProperties.APP_ARTIFACT); if (artifactName == null) { throw new StartException("Failed to find artifact name under " + BootstrapProperties.APP_ARTIFACT); } final ModuleLoader serviceLoader = this.serviceLoader.getValue(); final String moduleName = "deployment." + artifactName; final Module module = serviceLoader.loadModule(ModuleIdentifier.create(moduleName)); if (module == null) { throw new StartException("Failed to find deployment module under " + moduleName); } //TODO: allow overriding the default port? this.server = Server.create("localhost", 12345, module.getClassLoader()); this.server.start(); } catch (ModuleLoadException | ServerLifecycleException e) { throw new StartException(e); } }
Example 2
Source File: LoggingDependencyDeploymentProcessor.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void deploy(final DeploymentPhaseContext phaseContext) { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION); final ModuleLoader moduleLoader = Module.getBootModuleLoader(); // Add the logging modules for (String moduleId : DUP_INJECTED_LOGGING_MODULES) { try { LoggingLogger.ROOT_LOGGER.tracef("Adding module '%s' to deployment '%s'", moduleId, deploymentUnit.getName()); moduleLoader.loadModule(moduleId); moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, moduleId, false, false, false, false)); } catch (ModuleLoadException ex) { LoggingLogger.ROOT_LOGGER.debugf("Module not found: %s", moduleId); } } }
Example 3
Source File: Main.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private static void runBootableJar(Path jbossHome, List<String> arguments, Long unzipTime) throws Exception { final String modulePath = jbossHome.resolve(JBOSS_MODULES_DIR_NAME).toAbsolutePath().toString(); ModuleLoader moduleLoader = setupModuleLoader(modulePath); final Module bootableJarModule; try { bootableJarModule = moduleLoader.loadModule(MODULE_ID_JAR_RUNTIME); } catch (final ModuleLoadException mle) { throw new Exception(mle); } final ModuleClassLoader moduleCL = bootableJarModule.getClassLoader(); final Class<?> bjFactoryClass; try { bjFactoryClass = moduleCL.loadClass(BOOTABLE_JAR); } catch (final ClassNotFoundException cnfe) { throw new Exception(cnfe); } Method runMethod; try { runMethod = bjFactoryClass.getMethod(BOOTABLE_JAR_RUN_METHOD, Path.class, List.class, ModuleLoader.class, ModuleClassLoader.class, Long.class); } catch (final NoSuchMethodException nsme) { throw new Exception(nsme); } runMethod.invoke(null, jbossHome, arguments, moduleLoader, moduleCL, unzipTime); }
Example 4
Source File: ContextCreateHandlerRegistryIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testHandlerRegistry() throws Exception { ContextCreateHandlerRegistry handlerRegistry = ServiceLocator.getRequiredService(CamelConstants.CONTEXT_CREATE_HANDLER_REGISTRY_SERVICE_NAME, ContextCreateHandlerRegistry.class); ModuleLoader moduleLoader = Module.getCallerModuleLoader(); deployer.deploy(CAMEL_TEST_JAR); Module module = moduleLoader.loadModule(ModuleIdentifier.create("deployment.camel-test.jar")); ClassLoader classLoader = module.getClassLoader(); // Registry should have classloader key after deploy Assert.assertTrue(handlerRegistry.containsKey(classLoader)); deployer.undeploy(CAMEL_TEST_JAR); // Registry should have removed classloader key after undeploy Assert.assertFalse("Expected registry to not contain key: " + classLoader, handlerRegistry.containsKey(classLoader)); }
Example 5
Source File: ServerReloadHelper.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@SuppressWarnings("unchecked") private void executeOperation(Object deploymentOperations, String operation) throws Exception { Class defaultBootModuleLoaderHolder = this.getClass().getClassLoader().loadClass("org.jboss.modules.DefaultBootModuleLoaderHolder"); Field instance = defaultBootModuleLoaderHolder.getDeclaredField("INSTANCE"); instance.setAccessible(true); ModuleLoader loader = (ModuleLoader) instance.get(null); Module module = loader.loadModule(ModuleIdentifier.fromString("org.jboss.as.deployment-scanner")); traceln("ServerLoaderhelper", "Module " + module.toString() + " loaded."); ModuleClassLoader cl = module.getClassLoader(); Class modelNodeClass = cl.loadClassLocal("org.jboss.dmr.ModelNode"); traceln("ServerLoaderhelper", "org.jboss.dmr.ModelNode class loaded."); Object modelNode = modelNodeClass.newInstance(); Method getMethod = modelNodeClass.getDeclaredMethod("get", String.class); Method setMethod = modelNodeClass.getDeclaredMethod("set", String.class); Method setAddressMethod = modelNodeClass.getDeclaredMethod("set", modelNodeClass); Method setEmptyListMethod = modelNodeClass.getDeclaredMethod("setEmptyList"); Object operationNode = getMethod.invoke(modelNode, "operation"); setMethod.invoke(operationNode, operation); Object operationAddressNode = getMethod.invoke(modelNode, "address"); Object addressNode = modelNodeClass.newInstance(); setEmptyListMethod.invoke(addressNode); setAddressMethod.invoke(operationAddressNode, addressNode); traceln("ServerLoaderhelper", "We have computed the following operation " + modelNode.toString()); for (Method deployMethod : deploymentOperations.getClass().getDeclaredMethods()) { if ("deploy".equals(deployMethod.getName())) { deployMethod.setAccessible(true); traceln("ServerLoaderhelper", "We have found the execution method."); deployMethod.invoke(deploymentOperations, modelNode, null); traceln("ServerLoaderhelper", "We have executed the following operation: " + modelNode.toString()); } } }
Example 6
Source File: EmbeddedProcessFactory.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static void setupVfsModule(final ModuleLoader moduleLoader) { final ModuleIdentifier vfsModuleID = ModuleIdentifier.create(MODULE_ID_VFS); final Module vfsModule; try { vfsModule = moduleLoader.loadModule(vfsModuleID); } catch (final ModuleLoadException mle) { throw EmbeddedLogger.ROOT_LOGGER.moduleLoaderError(mle,MODULE_ID_VFS, moduleLoader); } Module.registerURLStreamHandlerFactoryModule(vfsModule); }
Example 7
Source File: Server.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static void setupVfsModule(final ModuleLoader moduleLoader) { final Module vfsModule; try { vfsModule = moduleLoader.loadModule(MODULE_ID_VFS); } catch (final ModuleLoadException mle) { throw BootableJarLogger.ROOT_LOGGER.moduleLoaderError(mle, MODULE_ID_VFS, moduleLoader); } Module.registerURLStreamHandlerFactoryModule(vfsModule); }
Example 8
Source File: Seam2Processor.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Lookup Seam integration resource loader. * @return the Seam integration resource loader * @throws DeploymentUnitProcessingException for any error */ protected synchronized ResourceRoot getSeamIntResourceRoot() throws DeploymentUnitProcessingException { try { if (seamIntResourceRoot == null) { final ModuleLoader moduleLoader = Module.getBootModuleLoader(); Module extModule = moduleLoader.loadModule(EXT_CONTENT_MODULE); URL url = extModule.getExportedResource(SEAM_INT_JAR); if (url == null) throw ServerLogger.ROOT_LOGGER.noSeamIntegrationJarPresent(extModule); File file = new File(url.toURI()); VirtualFile vf = VFS.getChild(file.toURI()); final Closeable mountHandle = VFS.mountZip(file, vf, TempFileProviderService.provider()); Service<Closeable> mountHandleService = new Service<Closeable>() { public void start(StartContext startContext) throws StartException { } public void stop(StopContext stopContext) { VFSUtils.safeClose(mountHandle); } public Closeable getValue() throws IllegalStateException, IllegalArgumentException { return mountHandle; } }; ServiceBuilder<Closeable> builder = serviceTarget.addService(ServiceName.JBOSS.append(SEAM_INT_JAR), mountHandleService); builder.setInitialMode(ServiceController.Mode.ACTIVE).install(); serviceTarget = null; // our cleanup service install work is done MountHandle dummy = MountHandle.create(null); // actual close is done by the MSC service above seamIntResourceRoot = new ResourceRoot(vf, dummy); } return seamIntResourceRoot; } catch (Exception e) { throw new DeploymentUnitProcessingException(e); } }
Example 9
Source File: ModuleLoadingResourceDefinition.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static List<String> findResourcePaths(String moduleName) throws ModuleLoadException, ReflectiveOperationException, IOException, URISyntaxException { ModuleLoader moduleLoader = Module.getCallerModuleLoader(); ModuleLoaderMXBean loader = ModuleInfoHandler.INSTANCE.getMxBean(moduleLoader); moduleLoader.loadModule(ModuleIdentifier.fromString(moduleName)); List<String> result = new LinkedList<>(); for (ResourceLoaderInfo rl : loader.getResourceLoaders(moduleName)){ if (rl.getLocation() != null) { URL url = new URL(rl.getLocation()); switch (url.getProtocol()){ case "jar": { JarURLConnection jarConnection = (JarURLConnection)url.openConnection(); result.add(jarConnection.getJarFile().getName()); break; } default: { result.add(new File(url.getFile() ).toString()); } } } } return result; }
Example 10
Source File: SecurityActions.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static <T> T internalLoadAndInstantiateFromModule(String moduleId, final Class<T> iface, final String name) throws Exception { ModuleLoader loader = Module.getCallerModuleLoader(); final Module module = loader.loadModule(ModuleIdentifier.fromString(moduleId)); ClassLoader cl = WildFlySecurityManager.isChecking() ? doPrivileged(new GetModuleClassLoaderAction(module)) : module.getClassLoader(); Class<?> clazz = cl.loadClass(name); return iface.cast(clazz.newInstance()); }
Example 11
Source File: EmbeddedProcessFactory.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * Create an embedded standalone server with an already established module loader. * * @param configuration the configuration for the embedded server * @return the running embedded server. Will not be {@code null} */ public static StandaloneServer createStandaloneServer(final Configuration configuration) { final ChainedContext context = new ChainedContext(); context.add(new StandaloneSystemPropertyContext(configuration.getJBossHome())); context.add(new LoggerContext(configuration.getModuleLoader())); final ModuleLoader moduleLoader = configuration.getModuleLoader(); setupVfsModule(moduleLoader); // Load the Embedded Server Module final Module embeddedModule; try { embeddedModule = moduleLoader.loadModule(MODULE_ID_EMBEDDED); } catch (final ModuleLoadException mle) { throw EmbeddedLogger.ROOT_LOGGER.moduleLoaderError(mle, MODULE_ID_EMBEDDED, moduleLoader); } // Load the Embedded Server Factory via the modular environment final ModuleClassLoader embeddedModuleCL = embeddedModule.getClassLoader(); final Class<?> embeddedServerFactoryClass; final Class<?> standaloneServerClass; try { embeddedServerFactoryClass = embeddedModuleCL.loadClass(SERVER_FACTORY); standaloneServerClass = embeddedModuleCL.loadClass(StandaloneServer.class.getName()); } catch (final ClassNotFoundException cnfe) { throw EmbeddedLogger.ROOT_LOGGER.cannotLoadEmbeddedServerFactory(cnfe, SERVER_FACTORY); } // Get a handle to the method which will create the server boolean useClMethod = true; Method createServerMethod; try { createServerMethod = embeddedServerFactoryClass.getMethod("create", File.class, ModuleLoader.class, Properties.class, Map.class, String[].class, ClassLoader.class); } catch (final NoSuchMethodException nsme) { useClMethod = false; try { // Check if we're using a version of WildFly Core before 6.0 which did not include the create method that accepts a class loader createServerMethod = embeddedServerFactoryClass.getMethod("create", File.class, ModuleLoader.class, Properties.class, Map.class, String[].class); } catch (final NoSuchMethodException e) { throw EmbeddedLogger.ROOT_LOGGER.cannotGetReflectiveMethod(e, "create", embeddedServerFactoryClass.getName()); } } // Create the server Object standaloneServerImpl = createManagedProcess(ProcessType.STANDALONE_SERVER, createServerMethod, configuration, useClMethod ? embeddedModuleCL : null); return new EmbeddedManagedProcessImpl(standaloneServerClass, standaloneServerImpl, context); }
Example 12
Source File: EmbeddedProcessFactory.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * Create an embedded host controller with an already established module loader. * * @param configuration the configuration for the embedded host controller * @return the running host controller Will not be {@code null} */ public static HostController createHostController(final Configuration configuration) { final ChainedContext context = new ChainedContext(); context.add(new HostControllerSystemPropertyContext(configuration.getJBossHome())); context.add(new LoggerContext(configuration.getModuleLoader())); final ModuleLoader moduleLoader = configuration.getModuleLoader(); setupVfsModule(moduleLoader); // Load the Embedded Server Module final Module embeddedModule; try { embeddedModule = moduleLoader.loadModule(MODULE_ID_EMBEDDED); } catch (final ModuleLoadException mle) { throw EmbeddedLogger.ROOT_LOGGER.moduleLoaderError(mle, MODULE_ID_EMBEDDED, moduleLoader); } // Load the Embedded Server Factory via the modular environment final ModuleClassLoader embeddedModuleCL = embeddedModule.getClassLoader(); final Class<?> embeddedHostControllerFactoryClass; final Class<?> hostControllerClass; try { embeddedHostControllerFactoryClass = embeddedModuleCL.loadClass(HOST_FACTORY); hostControllerClass = embeddedModuleCL.loadClass(HostController.class.getName()); } catch (final ClassNotFoundException cnfe) { throw EmbeddedLogger.ROOT_LOGGER.cannotLoadEmbeddedServerFactory(cnfe, HOST_FACTORY); } // Get a handle to the method which will create the server boolean useClMethod = true; Method createServerMethod; try { createServerMethod = embeddedHostControllerFactoryClass.getMethod("create", File.class, ModuleLoader.class, Properties.class, Map.class, String[].class, ClassLoader.class); } catch (final NoSuchMethodException nsme) { useClMethod = false; try { // Check if we're using a version of WildFly Core before 6.0 which did not include the create method that accepts a class loader createServerMethod = embeddedHostControllerFactoryClass.getMethod("create", File.class, ModuleLoader.class, Properties.class, Map.class, String[].class); } catch (final NoSuchMethodException e) { throw EmbeddedLogger.ROOT_LOGGER.cannotGetReflectiveMethod(e, "create", embeddedHostControllerFactoryClass.getName()); } } // Create the server Object hostControllerImpl = createManagedProcess(ProcessType.HOST_CONTROLLER, createServerMethod, configuration, useClMethod ? embeddedModuleCL : null); return new EmbeddedManagedProcessImpl(hostControllerClass, hostControllerImpl, context); }
Example 13
Source File: RuntimeVaultReader.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private ModuleClassLoader getModuleClassLoader(final String moduleSpec) throws ModuleLoadException { ModuleLoader loader = Module.getCallerModuleLoader(); final Module module = loader.loadModule(ModuleIdentifier.fromString(moduleSpec)); return WildFlySecurityManager.isChecking() ? doPrivileged(new GetModuleClassLoaderAction(module)) : module.getClassLoader(); }