Search in sources :

Example 1 with ClasspathDescriptorFileFinder

use of org.glassfish.hk2.bootstrap.impl.ClasspathDescriptorFileFinder 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 ClasspathDescriptorFileFinder

use of org.glassfish.hk2.bootstrap.impl.ClasspathDescriptorFileFinder in project Payara by payara.

the class Utils method getNewServiceLocator.

public static ServiceLocator getNewServiceLocator(String name) {
    ServiceLocator habitat = null;
    if (ServiceLocatorFactory.getInstance().find(name) == null) {
        ServiceLocator serviceLocator = ServiceLocatorFactory.getInstance().create(name);
        DynamicConfigurationService dcs = serviceLocator.getService(DynamicConfigurationService.class);
        DynamicConfiguration config = dcs.createDynamicConfiguration();
        config.commit();
        habitat = ServiceLocatorFactory.getInstance().create(name);
        try {
            HK2Populator.populate(serviceLocator, new ClasspathDescriptorFileFinder(Utils.class.getClassLoader()), null);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return (habitat != null) ? habitat : ServiceLocatorFactory.getInstance().create(name);
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) ClasspathDescriptorFileFinder(org.glassfish.hk2.bootstrap.impl.ClasspathDescriptorFileFinder) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)2 ClasspathDescriptorFileFinder (org.glassfish.hk2.bootstrap.impl.ClasspathDescriptorFileFinder)2 ContextDuplicatePostProcessor (com.sun.enterprise.module.bootstrap.ContextDuplicatePostProcessor)1 LinkedList (java.util.LinkedList)1 DynamicConfiguration (org.glassfish.hk2.api.DynamicConfiguration)1 DynamicConfigurationService (org.glassfish.hk2.api.DynamicConfigurationService)1 PopulatorPostProcessor (org.glassfish.hk2.bootstrap.PopulatorPostProcessor)1