Search in sources :

Example 1 with Main

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

the class StaticGlassFishRuntimeBuilder method build.

public GlassFishRuntime build(BootstrapProperties bsProps) throws GlassFishException {
    /* Step 1. Build the classloader. */
    // The classloader should contain installRoot/modules/**/*.jar files.
    String installRoot = getInstallRoot(bsProps);
    if (installRoot != null) {
        System.setProperty("org.glassfish.embeddable.installRoot", installRoot);
    }
    // Required to add moduleJarURLs to support 'java -jar modules/glassfish.jar case'
    List<URL> moduleJarURLs = getModuleJarURLs(installRoot);
    ClassLoader cl = getClass().getClassLoader();
    if (!moduleJarURLs.isEmpty()) {
        cl = new StaticClassLoader(getClass().getClassLoader(), moduleJarURLs);
    }
    // Step 2. Setup the module subsystem.
    Main main = new EmbeddedMain(cl);
    SingleHK2Factory.initialize(cl);
    ModulesRegistry modulesRegistry = AbstractFactory.getInstance().createModulesRegistry();
    modulesRegistry.setParentClassLoader(cl);
    // Step 3. Create NonOSGIGlassFishRuntime
    GlassFishRuntime glassFishRuntime = new StaticGlassFishRuntime(main);
    logger.logp(Level.FINER, getClass().getName(), "build", "Created GlassFishRuntime {0} with InstallRoot {1}, Bootstrap Options {2}", new Object[] { glassFishRuntime, installRoot, bsProps });
    return glassFishRuntime;
}
Also used : ModulesRegistry(com.sun.enterprise.module.ModulesRegistry) GlassFishRuntime(org.glassfish.embeddable.GlassFishRuntime) URLClassLoader(java.net.URLClassLoader) Main(com.sun.enterprise.module.bootstrap.Main) URL(java.net.URL)

Example 2 with Main

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

the class EmbeddedOSGiGlassFishRuntime method newGlassFish.

@Override
public synchronized GlassFish newGlassFish(GlassFishProperties gfProps) throws GlassFishException {
    try {
        // set env props before updating config, because configuration update may actually trigger
        // some code to be executed which may be depending on the environment variable values.
        setEnv(gfProps.getProperties());
        final StartupContext startupContext = new StartupContext(gfProps.getProperties());
        final ServiceTracker hk2Tracker = new ServiceTracker(getBundleContext(), Main.class.getName(), null);
        hk2Tracker.open();
        final Main main = (Main) hk2Tracker.waitForService(0);
        hk2Tracker.close();
        final ModulesRegistry mr = ModulesRegistry.class.cast(getBundleContext().getService(getBundleContext().getServiceReference(ModulesRegistry.class.getName())));
        ServiceLocator serviceLocator = main.createServiceLocator(mr, startupContext, null, null);
        final ModuleStartup gfKernel = main.findStartupService(mr, serviceLocator, null, startupContext);
        GlassFish glassFish = createGlassFish(gfKernel, serviceLocator, gfProps.getProperties());
        gfs.add(glassFish);
        return glassFish;
    } catch (BootException ex) {
        throw new GlassFishException(ex);
    } catch (InterruptedException ex) {
        throw new GlassFishException(ex);
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) GlassFishException(org.glassfish.embeddable.GlassFishException) StartupContext(com.sun.enterprise.module.bootstrap.StartupContext) ServiceTracker(org.osgi.util.tracker.ServiceTracker) ModulesRegistry(com.sun.enterprise.module.ModulesRegistry) BootException(com.sun.enterprise.module.bootstrap.BootException) Main(com.sun.enterprise.module.bootstrap.Main) GlassFish(org.glassfish.embeddable.GlassFish) ModuleStartup(com.sun.enterprise.module.bootstrap.ModuleStartup)

Aggregations

ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)2 Main (com.sun.enterprise.module.bootstrap.Main)2 BootException (com.sun.enterprise.module.bootstrap.BootException)1 ModuleStartup (com.sun.enterprise.module.bootstrap.ModuleStartup)1 StartupContext (com.sun.enterprise.module.bootstrap.StartupContext)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 GlassFish (org.glassfish.embeddable.GlassFish)1 GlassFishException (org.glassfish.embeddable.GlassFishException)1 GlassFishRuntime (org.glassfish.embeddable.GlassFishRuntime)1 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)1 ServiceTracker (org.osgi.util.tracker.ServiceTracker)1