use of org.glassfish.hk2.api.PopulatorPostProcessor 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;
}
use of org.glassfish.hk2.api.PopulatorPostProcessor 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);
}
}
use of org.glassfish.hk2.api.PopulatorPostProcessor in project Payara by payara.
the class ApplicationInfo method populateApplicationServiceLocator.
/**
* Populates the ApplicationServiceLocator with services using the current
* appClassLoader. Services must be described in files named
* META-INF/hk2-locator/application. {@link PopulationPostProcessor} may be defined
* in the META-INF/services standard way
*
* @throws IOException On failure to read the service files
*/
private void populateApplicationServiceLocator() throws IOException {
createServiceLocator();
ServiceLoader<PopulatorPostProcessor> postProcessors = ServiceLoader.load(PopulatorPostProcessor.class, appClassLoader);
LinkedList<PopulatorPostProcessor> allProcessors = new LinkedList<PopulatorPostProcessor>();
for (PopulatorPostProcessor postProcessor : postProcessors) {
allProcessors.add(postProcessor);
}
// Add this one AFTER all the other processors
allProcessors.addLast(new ApplicationClassLoadingPostProcessor(appClassLoader));
HK2Populator.populate(appServiceLocator, new ApplicationDescriptorFileFinder(appClassLoader, APPLICATION_LOADER_FILES), allProcessors);
HashSet<ClassLoader> treatedLoaders = new HashSet<ClassLoader>();
treatedLoaders.add(appClassLoader);
for (ModuleInfo module : modules) {
ClassLoader moduleClassLoader = module.getModuleClassLoader();
if ((moduleClassLoader == null) || treatedLoaders.contains(moduleClassLoader)) {
continue;
}
treatedLoaders.add(moduleClassLoader);
allProcessors.removeLast();
allProcessors.addLast(new ApplicationClassLoadingPostProcessor(moduleClassLoader));
HK2Populator.populate(appServiceLocator, new ApplicationDescriptorFileFinder(moduleClassLoader, WEB_LOADER_FILES), allProcessors);
}
}
Aggregations