Search in sources :

Example 1 with HK2Module

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

the class GenericSniffer method setup.

/**
 * Sets up the container libraries so that any imported bundle from the
 * connector jar file will now be known to the module subsystem
 *
 * This method returns a {@link ModuleDefinition} for the module containing
 * the core implementation of the container. That means that this module
 * will be locked as long as there is at least one module loaded in the
 * associated container.
 *
 * @param containerHome is where the container implementation resides (Not used anymore)
 * @param logger the logger to use
 * @return the module definition of the core container implementation.
 *
 * @throws java.io.IOException exception if something goes sour
 */
@Override
public synchronized HK2Module[] setup(String containerHome, Logger logger) throws IOException {
    // TODO(Sahoo): Change signature to not accept containerHome or logger
    if (modules != null) {
        if (logger.isLoggable(Level.FINE)) {
            logger.logp(Level.FINE, "GenericSniffer", "setup", "{0} has already setup {1} container, so just returning.", new Object[] { this, containerName });
        }
        return modules;
    }
    List<HK2Module> tmp = new ArrayList<HK2Module>();
    for (String moduleName : getContainerModuleNames()) {
        HK2Module m = modulesRegistry.makeModuleFor(moduleName, null);
        if (m != null) {
            tmp.add(m);
        } else {
            throw new RuntimeException("Unable to set up module " + moduleName);
        }
    }
    modules = tmp.toArray(new HK2Module[tmp.size()]);
    return modules;
}
Also used : HK2Module(com.sun.enterprise.module.HK2Module)

Example 2 with HK2Module

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

the class ListContainersCommand method execute.

public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    report.setActionDescription(localStrings.getLocalString("list.containers.command", "List of Containers"));
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    ActionReport.MessagePart top = report.getTopMessagePart();
    top.setMessage(localStrings.getLocalString("list.containers.command", "List of Containers"));
    top.setChildrenType(localStrings.getLocalString("container", "Container"));
    Iterable<? extends Sniffer> sniffers = habitat.getAllServices(Sniffer.class);
    if (sniffers == null) {
        top.setMessage(localStrings.getLocalString("list.containers.nocontainer", "No container currently configured"));
    } else {
        for (Sniffer sniffer : sniffers) {
            ActionReport.MessagePart container = top.addChild();
            container.setMessage(sniffer.getModuleType());
            container.addProperty(localStrings.getLocalString("contractprovider", "ContractProvider"), sniffer.getModuleType());
            EngineInfo engineInfo = containerRegistry.getContainer(sniffer.getModuleType());
            if (engineInfo != null) {
                container.addProperty(localStrings.getLocalString("status", "Status"), localStrings.getLocalString("started", "Started"));
                HK2Module connectorModule = modulesRegistry.find(engineInfo.getSniffer().getClass());
                container.addProperty(localStrings.getLocalString("connector", "Connector"), connectorModule.getModuleDefinition().getName() + ":" + connectorModule.getModuleDefinition().getVersion());
                container.addProperty(localStrings.getLocalString("implementation", "Implementation"), engineInfo.getContainer().getClass().toString());
                boolean atLeastOne = false;
                for (Application app : applications.getApplications()) {
                    for (com.sun.enterprise.config.serverbeans.Module module : app.getModule()) {
                        Engine engine = module.getEngine(engineInfo.getSniffer().getModuleType());
                        if (engine != null) {
                            if (!atLeastOne) {
                                atLeastOne = true;
                                container.setChildrenType(localStrings.getLocalString("list.containers.listapps", "Applications deployed"));
                            }
                            container.addChild().setMessage(app.getName());
                        }
                    }
                }
                if (!atLeastOne) {
                    container.addProperty("Status", "Not Started");
                }
            }
        }
    }
}
Also used : HK2Module(com.sun.enterprise.module.HK2Module) Sniffer(org.glassfish.api.container.Sniffer) ActionReport(org.glassfish.api.ActionReport) EngineInfo(org.glassfish.internal.data.EngineInfo) Application(com.sun.enterprise.config.serverbeans.Application) Engine(com.sun.enterprise.config.serverbeans.Engine)

Example 3 with HK2Module

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

the class GlassFishTldProvider method postConstruct.

public void postConstruct() {
    /*
         * Check whether JSP caching has been enabled
         */
    Config cfg = serverContext.getDefaultServices().getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
    WebContainer webContainer = cfg.getExtensionByType(WebContainer.class);
    if (webContainer == null) {
        return;
    }
    if (!Boolean.valueOf(webContainer.getJspCachingEnabled())) {
        return;
    }
    /*
         * JSP caching has been enabled
         */
    Class jspCachingImplClass = CacheTag.class;
    URI[] uris = null;
    HK2Module m = null;
    if (jspCachingImplClass != null) {
        m = registry.find(jspCachingImplClass);
    }
    if (m != null) {
        uris = m.getModuleDefinition().getLocations();
    } else {
        ClassLoader classLoader = getClass().getClassLoader();
        if (classLoader instanceof URLClassLoader) {
            URL[] urls = ((URLClassLoader) classLoader).getURLs();
            if (urls != null && urls.length > 0) {
                uris = new URI[urls.length];
                for (int i = 0; i < urls.length; i++) {
                    try {
                        uris[i] = urls[i].toURI();
                    } catch (URISyntaxException e) {
                        String msg = rb.getString(LogFacade.TLD_PROVIDER_IGNORE_URL);
                        msg = MessageFormat.format(msg, urls[i]);
                        logger.log(Level.WARNING, msg, e);
                    }
                }
            }
        } else {
            logger.log(Level.WARNING, LogFacade.UNABLE_TO_DETERMINE_TLD_RESOURCES, new Object[] { "JSP Caching", classLoader, GlassFishTldProvider.class.getName() });
        }
    }
    if (uris != null && uris.length > 0) {
        Pattern pattern = Pattern.compile("META-INF/.*\\.tld");
        for (URI uri : uris) {
            List<String> entries = JarURIPattern.getJarEntries(uri, pattern);
            if (entries != null && entries.size() > 0) {
                tldMap.put(uri, entries);
            }
        }
    }
}
Also used : JarURIPattern(com.sun.enterprise.util.net.JarURIPattern) Pattern(java.util.regex.Pattern) HK2Module(com.sun.enterprise.module.HK2Module) Config(com.sun.enterprise.config.serverbeans.Config) WebContainer(org.glassfish.web.config.serverbeans.WebContainer) CacheTag(com.sun.appserv.web.taglibs.cache.CacheTag)

Example 4 with HK2Module

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

the class JerseyMvcTldProvider method postConstruct.

public void postConstruct() {
    final Class jerseyIncludeClass = org.glassfish.jersey.server.mvc.jsp.Include.class;
    URI[] uris = null;
    HK2Module m = null;
    if (jerseyIncludeClass != null) {
        m = registry.find(jerseyIncludeClass);
    }
    if (m != null) {
        uris = m.getModuleDefinition().getLocations();
    } else {
        ClassLoader classLoader = getClass().getClassLoader();
        if (classLoader instanceof URLClassLoader) {
            URL[] urls = ((URLClassLoader) classLoader).getURLs();
            if (urls != null && urls.length > 0) {
                uris = new URI[urls.length];
                for (int i = 0; i < urls.length; i++) {
                    try {
                        uris[i] = urls[i].toURI();
                    } catch (URISyntaxException e) {
                        String msg = rb.getString(LogFacade.TLD_PROVIDER_IGNORE_URL);
                        msg = MessageFormat.format(msg, urls[i]);
                        logger.log(Level.WARNING, msg, e);
                    }
                }
            }
        } else {
            logger.log(Level.WARNING, LogFacade.UNABLE_TO_DETERMINE_TLD_RESOURCES, new Object[] { JerseyMvcTldProvider.class.getSimpleName(), classLoader, JerseyMvcTldProvider.class.getName() });
        }
    }
    if (uris != null && uris.length > 0) {
        Pattern pattern = Pattern.compile("META-INF/.*\\.tld");
        for (URI uri : uris) {
            List<String> entries = JarURIPattern.getJarEntries(uri, pattern);
            if (entries != null && entries.size() > 0) {
                tldMap.put(uri, entries);
            }
        }
    }
}
Also used : JarURIPattern(com.sun.enterprise.util.net.JarURIPattern) Pattern(java.util.regex.Pattern) HK2Module(com.sun.enterprise.module.HK2Module) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader)

Example 5 with HK2Module

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

the class MonitoringBootstrap method loadXMLProviders.

private void loadXMLProviders(File xmlProvidersDir) {
    // Creates a filter which will return only xml files
    FilenameFilter filter = new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".xml");
        }
    };
    // Retrieves all the provider XML's
    File[] files = xmlProvidersDir.listFiles(filter);
    if (files == null)
        return;
    Map<String, File> providerMap = new HashMap();
    for (File file : files) {
        if (LOGGER.isLoggable(Level.FINE))
            LOGGER.log(Level.FINE, "Found the provider xml - {0}", file.getAbsolutePath());
        int index = file.getName().indexOf("-:");
        if (index != -1) {
            String moduleName = file.getName().substring(0, index);
            providerMap.put(moduleName, file);
            if (LOGGER.isLoggable(Level.FINE))
                LOGGER.log(Level.FINE, " The provider xml belongs to - \"{0}\"", moduleName);
            if (!map.containsKey(moduleName)) {
                continue;
            }
            if (LOGGER.isLoggable(Level.FINE))
                LOGGER.fine(" Module found (containsKey)");
            HK2Module module = map.get(moduleName);
            if (module == null) {
                LOGGER.log(Level.SEVERE, monitoringMissingModuleFromXmlProbeProviders, new Object[] { moduleName });
            } else {
                ClassLoader mcl = module.getClassLoader();
                if (LOGGER.isLoggable(Level.FINE)) {
                    LOGGER.log(Level.FINE, "ModuleClassLoader = {0}", mcl);
                    LOGGER.log(Level.FINE, "XML File path = {0}", file.getAbsolutePath());
                }
                processProbeProviderXML(mcl, file.getAbsolutePath(), false);
            }
        }
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) HK2Module(com.sun.enterprise.module.HK2Module) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) File(java.io.File)

Aggregations

HK2Module (com.sun.enterprise.module.HK2Module)16 JarURIPattern (com.sun.enterprise.util.net.JarURIPattern)4 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 Pattern (java.util.regex.Pattern)4 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)3 URL (java.net.URL)3 URLClassLoader (java.net.URLClassLoader)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)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 Config (com.sun.enterprise.config.serverbeans.Config)1 Engine (com.sun.enterprise.config.serverbeans.Engine)1 Tokenizer (com.sun.enterprise.module.common_impl.Tokenizer)1 File (java.io.File)1