Search in sources :

Example 1 with ContextDuplicatePostProcessor

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

the class ACCModulesManager method prepareHabitat.

/**
 * Sets up the HK2 habitat.
 * <p>
 * Must be invoked at least once before an AppClientContainerBuilder
 * returns a new AppClientContainer to the caller.
 * @param classLoader
 * @param logger
 * @throws com.sun.enterprise.module.bootstrap.BootException
 * @throws java.net.URISyntaxException
 */
private static ServiceLocator prepareHabitat(final ClassLoader loader) {
    ServiceLocator serviceLocator = ServiceLocatorFactory.getInstance().create("default");
    habitat = serviceLocator;
    ContextDuplicatePostProcessor duplicateProcessor = new ContextDuplicatePostProcessor();
    List<PopulatorPostProcessor> postProcessors = new LinkedList<PopulatorPostProcessor>();
    postProcessors.add(duplicateProcessor);
    try {
        HK2Populator.populate(serviceLocator, new ClasspathDescriptorFileFinder(loader), postProcessors);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return habitat;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ClasspathDescriptorFileFinder(org.glassfish.hk2.bootstrap.impl.ClasspathDescriptorFileFinder) ContextDuplicatePostProcessor(com.sun.enterprise.module.bootstrap.ContextDuplicatePostProcessor) PopulatorPostProcessor(org.glassfish.hk2.bootstrap.PopulatorPostProcessor) IOException(java.io.IOException) LinkedList(java.util.LinkedList)

Example 2 with ContextDuplicatePostProcessor

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

Aggregations

ContextDuplicatePostProcessor (com.sun.enterprise.module.bootstrap.ContextDuplicatePostProcessor)2 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)2 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)1 ModuleStartup (com.sun.enterprise.module.bootstrap.ModuleStartup)1 StartupContext (com.sun.enterprise.module.bootstrap.StartupContext)1 File (java.io.File)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 GlassFishException (org.glassfish.embeddable.GlassFishException)1 GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)1 PopulatorPostProcessor (org.glassfish.hk2.api.PopulatorPostProcessor)1 PopulatorPostProcessor (org.glassfish.hk2.bootstrap.PopulatorPostProcessor)1 ClasspathDescriptorFileFinder (org.glassfish.hk2.bootstrap.impl.ClasspathDescriptorFileFinder)1 Hk2LoaderPopulatorPostProcessor (org.glassfish.hk2.bootstrap.impl.Hk2LoaderPopulatorPostProcessor)1