Search in sources :

Example 6 with HK2Module

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

the class ContainerStarter method startContainer.

public Collection<EngineInfo> startContainer(Sniffer sniffer) {
    assert sniffer != null;
    String containerName = sniffer.getModuleType();
    assert containerName != null;
    // repositories which would allow access to the container module.
    try {
        HK2Module[] modules = sniffer.setup(null, logger);
        logger.logp(Level.FINE, "ContainerStarter", "startContainer", "Sniffer {0} set up following modules: {1}", new Object[] { sniffer, modules != null ? Arrays.toString(modules) : "" });
    } catch (FileNotFoundException fnf) {
        logger.log(Level.SEVERE, fnf.getMessage());
        return null;
    } catch (IOException ioe) {
        logger.log(Level.SEVERE, ioe.getMessage(), ioe);
        return null;
    }
    // first the right container from that module.
    Map<String, EngineInfo> containers = new HashMap<String, EngineInfo>();
    for (String name : sniffer.getContainersNames()) {
        ServiceHandle<Container> provider = serviceLocator.getServiceHandle(Container.class, name);
        if (provider == null) {
            logger.severe("Cannot find Container named " + name + ", so unable to start " + sniffer.getModuleType() + " container");
            return null;
        }
        EngineInfo info = new EngineInfo(provider, sniffer, null);
        containers.put(name, info);
    }
    // Now that we have successfully created all containers, let's register them as well.
    for (Map.Entry<String, EngineInfo> entry : containers.entrySet()) {
        registry.addContainer(entry.getKey(), entry.getValue());
    }
    return containers.values();
}
Also used : EngineInfo(org.glassfish.internal.data.EngineInfo) Container(org.glassfish.api.container.Container) HK2Module(com.sun.enterprise.module.HK2Module) HashMap(java.util.HashMap) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with HK2Module

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

the class AppServerStartup method printModuleStatus.

public static void printModuleStatus(ModulesRegistry registry, Level level) {
    if (!logger.isLoggable(level) || registry == null) {
        return;
    }
    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");
    logger.log(level, sb.toString());
}
Also used : HK2Module(com.sun.enterprise.module.HK2Module)

Example 8 with HK2Module

use of com.sun.enterprise.module.HK2Module in project glassfish-hk2 by eclipse-ee4j.

the class OSGiModulesRegistryImpl method bundleChanged.

@Override
public void bundleChanged(BundleEvent event) {
    // Extender implementation.
    try {
        final Bundle bundle = event.getBundle();
        switch(event.getType()) {
            case BundleEvent.INSTALLED:
                {
                    if (logger.isLoggable(Level.FINE)) {
                        logger.log(Level.FINE, "[{0}] {1} installed", new Object[] { bundle.getBundleId(), bundle.getSymbolicName() });
                    }
                    break;
                }
            case BundleEvent.RESOLVED:
                {
                    // call add as it processes provider names
                    OSGiModuleImpl m = makeModule(bundle);
                    add(m);
                    break;
                }
            case BundleEvent.UNINSTALLED:
                {
                    final HK2Module m = getModule(bundle);
                    if (m != null) {
                        // getModule can return null if some bundle got uninstalled
                        // before we have finished initialization. This can
                        // happen if framework APIs are called in parallel
                        // by some third party bundles.
                        // We need to call remove as it processes provider names
                        // and updates the cache.
                        remove(m);
                    }
                    break;
                }
            case BundleEvent.UPDATED:
                final HK2Module m = getModule(bundle);
                if (m != null) {
                    // getModule can return null if some bundle got uninstalled
                    // before we have finished initialization. This can
                    // happen if framework APIs are called in parallel
                    // by some third party bundles.
                    // We need to call remove as it processes provider names
                    // and updates the cache.
                    remove(m);
                }
                // make a new module from the updated bundle data and add it
                add(makeModule(bundle));
                break;
        }
    } catch (Exception e) {
        logger.logp(Level.WARNING, "OSGiModulesRegistryImpl", "bundleChanged", e.getMessage(), e);
    }
}
Also used : HK2Module(com.sun.enterprise.module.HK2Module) Bundle(org.osgi.framework.Bundle) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException)

Example 9 with HK2Module

use of com.sun.enterprise.module.HK2Module in project glassfish-hk2 by eclipse-ee4j.

the class OSGiModuleImpl method getImports.

@Override
public List<HK2Module> getImports() {
    List<HK2Module> result = new ArrayList<>();
    RequiredBundle[] requiredBundles = registry.getPackageAdmin().getRequiredBundles(bundle.getSymbolicName());
    if (requiredBundles != null) {
        for (RequiredBundle rb : requiredBundles) {
            HK2Module m = registry.getModule(rb.getBundle());
            if (m != null) {
                // module is known to the module system
                result.add(m);
            } else {
            // module is not known to us - may be the OSgi bundle depends on a native
            // OSGi bundle
            }
        }
    }
    return result;
}
Also used : HK2Module(com.sun.enterprise.module.HK2Module) RequiredBundle(org.osgi.service.packageadmin.RequiredBundle)

Example 10 with HK2Module

use of com.sun.enterprise.module.HK2Module in project glassfish-hk2 by eclipse-ee4j.

the class AbstractModulesRegistryImpl method populateServiceLocator.

/**
 * Creates a {@link ServiceLocator} from all the modules in this registry
 *
 * @param name
 *      Determines which descriptors are loaded.
 * @param postProcessors
 */
public void populateServiceLocator(String name, ServiceLocator serviceLocator, List<PopulatorPostProcessor> postProcessors) throws MultiException {
    try {
        for (final HK2Module module : getModules()) {
            // TODO: should get the inhabitantsParser out of Main instead since
            // this could have been overridden
            List<ActiveDescriptor> allDescriptors = parseInhabitants(module, name, serviceLocator, postProcessors);
            if (allDescriptors == null)
                continue;
            if (allDescriptors.isEmpty())
                continue;
            Map<ServiceLocator, List<ActiveDescriptor>> descriptorByServiceLocator = moduleDescriptors.get(module);
            if (descriptorByServiceLocator == null) {
                descriptorByServiceLocator = new HashMap<ServiceLocator, List<ActiveDescriptor>>();
                moduleDescriptors.put(module, descriptorByServiceLocator);
            }
            List<ActiveDescriptor> foundDs = descriptorByServiceLocator.get(serviceLocator);
            if (foundDs == null) {
                foundDs = new LinkedList<ActiveDescriptor>();
                descriptorByServiceLocator.put(serviceLocator, foundDs);
            }
            foundDs.addAll(allDescriptors);
        }
    } catch (Exception e) {
        throw new MultiException(e);
    }
    // From now on, we will keep this service registry up-to-date with module system state
    habitats.put(serviceLocator, name);
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) HK2Module(com.sun.enterprise.module.HK2Module) ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MultiException(org.glassfish.hk2.api.MultiException) BootException(com.sun.enterprise.module.bootstrap.BootException) IOException(java.io.IOException) MultiException(org.glassfish.hk2.api.MultiException)

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