Search in sources :

Example 1 with StartupContext

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

the class ACCModulesManager method initialize.

public static synchronized void initialize(final ClassLoader loader) throws URISyntaxException {
    /*
         * The habitat might have been initialized earlier.  Currently
         * we use a single habitat for the JVM.  
         */
    if (habitat == null) {
        habitat = prepareHabitat(loader);
        /*
             * Set up the default habitat in Globals as soon as we know
             * which habitat we'll use.
             */
        Globals.setDefaultHabitat(habitat);
        ServiceLocator locator = habitat;
        DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
        DynamicConfiguration config = dcs.createDynamicConfiguration();
        /*
             * Remove any already-loaded startup context so we can replace it
             * with the ACC one.
             */
        config.addUnbindFilter(BuilderHelper.createContractFilter(StartupContext.class.getName()));
        /*
             * Following the example from AppServerStartup, remove any
             * pre-loaded lazy inhabitant for ProcessEnvironment that exists
             * from HK2's scan for services.  Then add in
             * an ACC ProcessEnvironment.
             */
        config.addUnbindFilter(BuilderHelper.createContractFilter(ProcessEnvironment.class.getName()));
        config.commit();
        config = dcs.createDynamicConfiguration();
        StartupContext startupContext = new ACCStartupContext();
        AbstractActiveDescriptor<?> startupContextDescriptor = BuilderHelper.createConstantDescriptor(startupContext);
        startupContextDescriptor.addContractType(StartupContext.class);
        config.addActiveDescriptor(startupContextDescriptor);
        ModulesRegistry modulesRegistry = new StaticModulesRegistry(ACCModulesManager.class.getClassLoader());
        config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(modulesRegistry));
        config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(new ProcessEnvironment(ProcessEnvironment.ProcessType.ACC)));
        /*
             * Create the ClientNamingConfigurator used by naming.
             */
        ClientNamingConfigurator cnc = new ClientNamingConfiguratorImpl();
        config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(cnc));
        Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
        AbstractActiveDescriptor<Logger> di = BuilderHelper.createConstantDescriptor(logger);
        di.addContractType(Logger.class);
        config.addActiveDescriptor(di);
        config.commit();
    }
}
Also used : DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) StartupContext(com.sun.enterprise.module.bootstrap.StartupContext) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry) Logger(java.util.logging.Logger) ProcessEnvironment(org.glassfish.api.admin.ProcessEnvironment) ClientNamingConfigurator(org.glassfish.api.naming.ClientNamingConfigurator) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ClientNamingConfiguratorImpl(com.sun.enterprise.naming.impl.ClientNamingConfiguratorImpl) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) ModulesRegistry(com.sun.enterprise.module.ModulesRegistry) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry)

Example 2 with StartupContext

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

the class ConnectorNamingUtils method getHabitat.

private static ServiceLocator getHabitat() {
    ServiceLocator habitat = Globals.getStaticHabitat();
    StartupContext startupContext = new StartupContext();
    ServiceLocatorUtilities.addOneConstant(habitat, startupContext);
    ServiceLocatorUtilities.addOneConstant(habitat, new ProcessEnvironment(ProcessEnvironment.ProcessType.Other));
    return habitat;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) StartupContext(com.sun.enterprise.module.bootstrap.StartupContext)

Example 3 with StartupContext

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

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

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

the class Utils method getNewHabitat.

public static ServiceLocator getNewHabitat(String root) {
    Properties p = new Properties();
    p.put(com.sun.enterprise.glassfish.bootstrap.Constants.INSTALL_ROOT_PROP_NAME, root);
    p.put(com.sun.enterprise.glassfish.bootstrap.Constants.INSTANCE_ROOT_PROP_NAME, root);
    ModulesRegistry registry = new StaticModulesRegistry(Utils.class.getClassLoader(), new StartupContext(p));
    ServiceLocator defaultSL = registry.createServiceLocator("default");
    return defaultSL;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) StartupContext(com.sun.enterprise.module.bootstrap.StartupContext) ModulesRegistry(com.sun.enterprise.module.ModulesRegistry) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry) Properties(java.util.Properties)

Aggregations

StartupContext (com.sun.enterprise.module.bootstrap.StartupContext)13 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)6 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)6 ModuleStartup (com.sun.enterprise.module.bootstrap.ModuleStartup)3 StaticModulesRegistry (com.sun.enterprise.module.single.StaticModulesRegistry)3 File (java.io.File)3 Properties (java.util.Properties)3 DynamicConfiguration (org.glassfish.hk2.api.DynamicConfiguration)3 DynamicConfigurationService (org.glassfish.hk2.api.DynamicConfigurationService)3 SingleModulesRegistry (com.sun.enterprise.module.single.SingleModulesRegistry)2 FilenameFilter (java.io.FilenameFilter)2 JarFile (java.util.jar.JarFile)2 Logger (java.util.logging.Logger)2 ProcessEnvironment (org.glassfish.api.admin.ProcessEnvironment)2 GlassFishException (org.glassfish.embeddable.GlassFishException)2 Version (com.sun.appserv.server.util.Version)1 RankedConfigBeanProxy (com.sun.enterprise.config.modularity.RankedConfigBeanProxy)1 ConfigBeanDefaultValue (com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue)1 Domain (com.sun.enterprise.config.serverbeans.Domain)1 EmbeddedInhabitantsParser (com.sun.enterprise.glassfish.bootstrap.EmbeddedInhabitantsParser)1