Search in sources :

Example 1 with ModuleStartup

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

the class MicroGlassFishRuntime method newGlassFish.

@Override
public GlassFish newGlassFish(GlassFishProperties glassfishProperties) throws GlassFishException {
    System.setProperty("com.sun.aas.installRoot", System.getProperty("com.sun.aas.instanceRoot"));
    System.setProperty("com.sun.aas.installRootURI", System.getProperty("com.sun.aas.instanceRootURI"));
    glassfishProperties.setProperty("com.sun.aas.installRoot", System.getProperty("com.sun.aas.instanceRoot"));
    glassfishProperties.setProperty("com.sun.aas.installRootURI", System.getProperty("com.sun.aas.instanceRootURI"));
    StartupContext context = new StartupContext(glassfishProperties.getProperties());
    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    SingleHK2Factory.initialize(tccl);
    registry = new SingleModulesRegistry(tccl);
    registry.setParentClassLoader(tccl);
    habitat = registry.newServiceLocator();
    DynamicConfigurationService dcs = habitat.getService(DynamicConfigurationService.class);
    DynamicConfiguration config = dcs.createDynamicConfiguration();
    config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(context));
    config.commit();
    registry.populateServiceLocator("default", habitat, Arrays.asList(new PayaraMicroInhabitantsParser(), new EmbeddedInhabitantsParser(), new DuplicatePostProcessor()));
    registry.populateConfig(habitat);
    ModuleStartup kernel = habitat.getService(ModuleStartup.class);
    gf = new MicroGlassFish(kernel, habitat, glassfishProperties.getProperties());
    return gf;
}
Also used : StartupContext(com.sun.enterprise.module.bootstrap.StartupContext) DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) SingleModulesRegistry(com.sun.enterprise.module.single.SingleModulesRegistry) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) DuplicatePostProcessor(org.glassfish.hk2.utilities.DuplicatePostProcessor) EmbeddedInhabitantsParser(com.sun.enterprise.glassfish.bootstrap.EmbeddedInhabitantsParser) ModuleStartup(com.sun.enterprise.module.bootstrap.ModuleStartup)

Example 2 with ModuleStartup

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

the class StaticGlassFishRuntime method newGlassFish.

/**
 * Creates a new GlassFish instance and add it to a Map of instances
 * created by this runtime.
 *
 * @param glassFishProperties
 * @return
 * @throws Exception
 */
@Override
public synchronized GlassFish newGlassFish(GlassFishProperties glassFishProperties) throws GlassFishException {
    // some code to be executed which may be depending on the environment variable values.
    try {
        // Don't set temporarily created instanceroot in the user supplied
        // GlassFishProperties, hence clone it.
        Properties cloned = new Properties();
        cloned.putAll(glassFishProperties.getProperties());
        final GlassFishProperties gfProps = new GlassFishProperties(cloned);
        setEnv(gfProps);
        final StartupContext startupContext = new StartupContext(gfProps.getProperties());
        ModulesRegistry modulesRegistry = SingleHK2Factory.getInstance().createModulesRegistry();
        ServiceLocator serviceLocator = main.createServiceLocator(modulesRegistry, startupContext, Arrays.asList((PopulatorPostProcessor) new EmbeddedInhabitantsParser(), new ContextDuplicatePostProcessor()), null);
        final ModuleStartup gfKernel = main.findStartupService(modulesRegistry, serviceLocator, null, startupContext);
        // create a new GlassFish instance
        GlassFishImpl gfImpl = new GlassFishImpl(gfKernel, serviceLocator, gfProps.getProperties()) {

            @Override
            public void dispose() throws GlassFishException {
                try {
                    super.dispose();
                } finally {
                    gfMap.remove(gfProps.getInstanceRoot());
                    if ("true".equalsIgnoreCase(gfProps.getProperties().getProperty(autoDelete)) && gfProps.getInstanceRoot() != null) {
                        File instanceRoot = new File(gfProps.getInstanceRoot());
                        if (instanceRoot.exists()) {
                            // might have been deleted already.
                            Util.deleteRecursive(instanceRoot);
                        }
                    }
                }
            }
        };
        // Add this newly created instance to a Map
        gfMap.put(gfProps.getInstanceRoot(), gfImpl);
        return gfImpl;
    } catch (GlassFishException e) {
        throw e;
    } catch (Exception e) {
        throw new GlassFishException(e);
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) StartupContext(com.sun.enterprise.module.bootstrap.StartupContext) ContextDuplicatePostProcessor(com.sun.enterprise.module.bootstrap.ContextDuplicatePostProcessor) PopulatorPostProcessor(org.glassfish.hk2.api.PopulatorPostProcessor) Hk2LoaderPopulatorPostProcessor(org.glassfish.hk2.bootstrap.impl.Hk2LoaderPopulatorPostProcessor) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) GlassFishException(org.glassfish.embeddable.GlassFishException) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ModulesRegistry(com.sun.enterprise.module.ModulesRegistry) File(java.io.File) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) ModuleStartup(com.sun.enterprise.module.bootstrap.ModuleStartup)

Example 3 with ModuleStartup

use of com.sun.enterprise.module.bootstrap.ModuleStartup 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

ModuleStartup (com.sun.enterprise.module.bootstrap.ModuleStartup)3 StartupContext (com.sun.enterprise.module.bootstrap.StartupContext)3 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)2 GlassFishException (org.glassfish.embeddable.GlassFishException)2 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)2 EmbeddedInhabitantsParser (com.sun.enterprise.glassfish.bootstrap.EmbeddedInhabitantsParser)1 BootException (com.sun.enterprise.module.bootstrap.BootException)1 ContextDuplicatePostProcessor (com.sun.enterprise.module.bootstrap.ContextDuplicatePostProcessor)1 Main (com.sun.enterprise.module.bootstrap.Main)1 SingleModulesRegistry (com.sun.enterprise.module.single.SingleModulesRegistry)1 File (java.io.File)1 GlassFish (org.glassfish.embeddable.GlassFish)1 GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)1 DynamicConfiguration (org.glassfish.hk2.api.DynamicConfiguration)1 DynamicConfigurationService (org.glassfish.hk2.api.DynamicConfigurationService)1 PopulatorPostProcessor (org.glassfish.hk2.api.PopulatorPostProcessor)1 Hk2LoaderPopulatorPostProcessor (org.glassfish.hk2.bootstrap.impl.Hk2LoaderPopulatorPostProcessor)1 DuplicatePostProcessor (org.glassfish.hk2.utilities.DuplicatePostProcessor)1 ServiceTracker (org.osgi.util.tracker.ServiceTracker)1