Search in sources :

Example 16 with HK2Module

use of com.sun.enterprise.module.HK2Module in project Payara by payara.

the class RuntimeRootImpl method stopDomain.

public void stopDomain() {
    final ModulesRegistry registry = InjectedValues.getInstance().getModulesRegistry();
    final Collection<HK2Module> modules = registry.getModules("com.sun.enterprise.osgi-adapter");
    if (modules.size() == 1) {
        final HK2Module mgmtAgentModule = modules.iterator().next();
        mgmtAgentModule.stop();
    } else {
        AMXLoggerInfo.getLogger().warning(AMXLoggerInfo.cantFindOSGIAdapter);
    }
    AMXLoggerInfo.getLogger().warning(AMXLoggerInfo.stoppingServerForcibly);
    System.exit(0);
}
Also used : HK2Module(com.sun.enterprise.module.HK2Module) ModulesRegistry(com.sun.enterprise.module.ModulesRegistry)

Example 17 with HK2Module

use of com.sun.enterprise.module.HK2Module in project Payara by payara.

the class DeploymentTracing method printModuleStatus.

public static void printModuleStatus(ModulesRegistry registry, Level level, Logger logger) {
    if (!logger.isLoggable(level)) {
        return;
    }
    int counter = 0;
    StringBuilder sb = new StringBuilder("Module Status Report Begins\n");
    for (HK2Module m : registry.getModules()) {
        if (m.getState() == ModuleState.READY) {
            sb.append(m).append("\n");
            counter++;
        }
    }
    sb.append("there were ").append(counter).append(" modules in ACTIVE state");
    sb.append("\n");
    counter = 0;
    // then resolved
    for (HK2Module m : registry.getModules()) {
        if (m.getState() == ModuleState.RESOLVED) {
            sb.append(m).append("\n");
            counter++;
        }
    }
    sb.append("there were ").append(counter).append(" modules in RESOLVED state");
    sb.append("\n");
    counter = 0;
    // finally installed
    for (HK2Module m : registry.getModules()) {
        if (m.getState() != ModuleState.READY && m.getState() != ModuleState.RESOLVED) {
            sb.append(m).append("\n");
            counter++;
        }
    }
    sb.append("there were ").append(counter).append(" modules in INSTALLED state");
    sb.append("Module Status Report Ends");
    logger.log(level, sb.toString());
}
Also used : HK2Module(com.sun.enterprise.module.HK2Module)

Example 18 with HK2Module

use of com.sun.enterprise.module.HK2Module in project Payara by payara.

the class ListModulesCommand method execute.

public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    report.setActionDescription("List of modules");
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    ActionReport.MessagePart top = report.getTopMessagePart();
    top.setMessage("List Of Modules");
    top.setChildrenType("Module");
    StringBuilder sb = new StringBuilder("Module Status Report Begins\n");
    for (HK2Module m : registry.getModules()) {
        if (m.getState() == ModuleState.READY) {
            sb.append(m).append("\n");
        }
    }
    sb.append("\n");
    // then resolved
    for (HK2Module m : registry.getModules()) {
        if (m.getState() == ModuleState.RESOLVED) {
            sb.append(m).append("\n");
        }
    }
    sb.append("\n");
    // finally installed
    for (HK2Module m : registry.getModules()) {
        if (m.getState() != ModuleState.READY && m.getState() != ModuleState.RESOLVED) {
            sb.append(m).append("\n");
        }
    }
    sb.append("Module Status Report Ends");
    ActionReport.MessagePart childPart = top.addChild();
    childPart.setMessage(sb.toString());
}
Also used : HK2Module(com.sun.enterprise.module.HK2Module) ActionReport(org.glassfish.api.ActionReport)

Example 19 with HK2Module

use of com.sun.enterprise.module.HK2Module in project Payara by payara.

the class ClassLoaderHierarchyImpl method createApplicationParentCL.

/**
 * Sets up the parent class loader for the application class loader.
 * Application class loader are under the control of the ArchiveHandler since
 * a special archive file format will require a specific class loader.
 *
 * However GlassFish needs to be able to add capabilities to the application
 * like adding APIs accessibility, this is done through its parent class loader
 * which we create and maintain.
 *
 * @param parent the parent class loader
 * @param context deployment context
 * @return class loader capable of loading public APIs identified by the deployers
 * @throws ResolveError if one of the deployer's public API module is not found.
 */
@Override
public ClassLoader createApplicationParentCL(ClassLoader parent, DeploymentContext context) throws ResolveError {
    final ReadableArchive source = context.getSource();
    List<ModuleDefinition> defs = new ArrayList<ModuleDefinition>();
    // now let's see if the application is requesting any module imports
    Manifest m = null;
    try {
        m = source.getManifest();
    } catch (IOException e) {
        logger.log(Level.SEVERE, "Cannot load application's manifest file :", e.getMessage());
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, e.getMessage(), e);
        }
    }
    if (m != null) {
        String importedBundles = m.getMainAttributes().getValue(ManifestConstants.BUNDLE_IMPORT_NAME);
        if (importedBundles != null) {
            for (String token : new Tokenizer(importedBundles, ",")) {
                Collection<HK2Module> modules = modulesRegistry.getModules(token);
                if (modules.size() == 1) {
                    defs.add(modules.iterator().next().getModuleDefinition());
                } else {
                    throw new ResolveError("Not able to locate a unique module by name " + token);
                }
            }
        }
        // Applications can add an additional osgi repos...
        String additionalRepo = m.getMainAttributes().getValue(org.glassfish.api.ManifestConstants.GLASSFISH_REQUIRE_REPOSITORY);
        if (additionalRepo != null) {
            for (String token : new Tokenizer(additionalRepo, ",")) {
                // Each entry should be name=path
                int equals = token.indexOf('=');
                if (equals == -1) {
                    // Missing '='...
                    throw new IllegalArgumentException("\"" + org.glassfish.api.ManifestConstants.GLASSFISH_REQUIRE_REPOSITORY + ": " + additionalRepo + "\" is missing an '='.  " + "It must be in the format: name=path[,name=path]...");
                }
                String name = token.substring(0, equals);
                String path = token.substring(++equals);
                addRepository(name, resolver.translate(path));
            }
        }
        // Applications can also request to be wired to implementors of certain services.
        // That means that any module implementing the requested service will be accessible
        // by the parent class loader of the application.
        String requestedWiring = m.getMainAttributes().getValue(org.glassfish.api.ManifestConstants.GLASSFISH_REQUIRE_SERVICES);
        if (requestedWiring != null) {
            for (String token : new Tokenizer(requestedWiring, ",")) {
                for (Object impl : habitat.getAllServices(BuilderHelper.createContractFilter(token))) {
                    HK2Module wiredBundle = modulesRegistry.find(impl.getClass());
                    if (wiredBundle != null) {
                        defs.add(wiredBundle.getModuleDefinition());
                    }
                }
            }
        }
    }
    if (defs.isEmpty()) {
        return parent;
    } else {
        return modulesRegistry.getModulesClassLoader(parent, defs);
    }
}
Also used : HK2Module(com.sun.enterprise.module.HK2Module) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Tokenizer(com.sun.enterprise.module.common_impl.Tokenizer)

Example 20 with HK2Module

use of com.sun.enterprise.module.HK2Module in project Payara by payara.

the class H2Lifecycle method start.

/**
 * Callback when the module enters the {@link ModuleState#READY READY} state.
 * This is a good time to do any type of one time initialization
 * or set up access to resources
 * @param module the module instance
 */
public void start(HK2Module module) {
    try {
        final HK2Module myModule = module;
        Thread thread = new Thread() {

            public void run() {
                try {
                    try {
                        Class driverClass = myModule.getClassLoader().loadClass("org.h2.Driver");
                        myModule.setSticky(true);
                        driverClass.newInstance();
                    } catch (ClassNotFoundException e) {
                        LogHelper.getDefaultLogger().log(Level.SEVERE, "Cannot load H2 Driver ", e);
                    } catch (java.lang.InstantiationException e) {
                        LogHelper.getDefaultLogger().log(Level.SEVERE, "Cannot instantiate H2 Driver", e);
                    } catch (IllegalAccessException e) {
                        LogHelper.getDefaultLogger().log(Level.SEVERE, "Cannot instantiate H2 Driver", e);
                    }
                } catch (RuntimeException e) {
                    e.printStackTrace();
                }
            }
        };
        thread.start();
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : HK2Module(com.sun.enterprise.module.HK2Module)

Aggregations

HK2Module (com.sun.enterprise.module.HK2Module)30 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)6 IOException (java.io.IOException)5 URISyntaxException (java.net.URISyntaxException)5 URL (java.net.URL)5 JarURIPattern (com.sun.enterprise.util.net.JarURIPattern)4 URI (java.net.URI)4 Pattern (java.util.regex.Pattern)4 URLClassLoader (java.net.URLClassLoader)3 ArrayList (java.util.ArrayList)3 ModuleDefinition (com.sun.enterprise.module.ModuleDefinition)2 Repository (com.sun.enterprise.module.Repository)2 ResolveError (com.sun.enterprise.module.ResolveError)2 HashMap (java.util.HashMap)2 Vector (java.util.Vector)2 ActionReport (org.glassfish.api.ActionReport)2 EngineInfo (org.glassfish.internal.data.EngineInfo)2 CacheTag (com.sun.appserv.web.taglibs.cache.CacheTag)1 InitialGroupInfoService (com.sun.corba.ee.impl.folb.InitialGroupInfoService)1 Application (com.sun.enterprise.config.serverbeans.Application)1