use of com.sun.enterprise.module.ModulesRegistry 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();
}
}
use of com.sun.enterprise.module.ModulesRegistry in project Payara by payara.
the class CLIContainer method getServiceLocator.
public ServiceLocator getServiceLocator() {
if (serviceLocator == null) {
Metrix.event("Init hk2 - start");
ModulesRegistry registry = new StaticModulesRegistry(this.classLoader);
serviceLocator = registry.createServiceLocator("default");
if (programOptions != null) {
ServiceLocatorUtilities.addOneConstant(serviceLocator, programOptions);
}
if (environment != null) {
ServiceLocatorUtilities.addOneConstant(serviceLocator, environment);
}
ServiceLocatorUtilities.addOneConstant(serviceLocator, this);
Metrix.event("Init hk2 - done");
}
return serviceLocator;
}
use of com.sun.enterprise.module.ModulesRegistry in project Payara by payara.
the class CustomizationTokensProvider method initializeLocator.
protected void initializeLocator() {
final ClassLoader ecl = CustomizationTokensProvider.class.getClassLoader();
File inst = new File(System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY));
final File ext = new File(inst, "modules");
LOG.log(Level.FINE, "asadmin modules directory: {0}", ext);
if (ext.isDirectory()) {
AccessController.doPrivileged(new PrivilegedAction() {
@Override
public Object run() {
try {
URLClassLoader pl = new URLClassLoader(getJars(ext));
ModulesRegistry registry = new StaticModulesRegistry(pl);
locator = registry.createServiceLocator("default");
return pl;
} catch (IOException ex) {
// any failure here is fatal
LOG.log(Level.SEVERE, ConfigApiLoggerInfo.MODULES_CL_FAILED, ex);
}
return ecl;
}
});
} else {
LOG.log(Level.FINER, "Modules directory does not exist");
}
}
use of com.sun.enterprise.module.ModulesRegistry in project Payara by payara.
the class RuntimeRootImpl method restartDomain.
public void restartDomain() {
final ModulesRegistry registry = InjectedValues.getInstance().getModulesRegistry();
final AdminCommandContext ctx = new AdminCommandContextImpl(AMXLoggerInfo.getLogger(), new PlainTextActionReporter());
final AdminCommand cmd = new RestartDomainCommand(registry);
cmd.execute(ctx);
}
use of com.sun.enterprise.module.ModulesRegistry 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);
}
}
Aggregations