use of org.glassfish.hk2.api.DynamicConfigurationService in project Payara by payara.
the class MultimodeCommand method atomicReplace.
private static void atomicReplace(ServiceLocator locator, ProgramOptions options) {
DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
DynamicConfiguration config = dcs.createDynamicConfiguration();
config.addUnbindFilter(BuilderHelper.createContractFilter(ProgramOptions.class.getName()));
ActiveDescriptor<ProgramOptions> desc = BuilderHelper.createConstantDescriptor(options, null, ProgramOptions.class);
config.addActiveDescriptor(desc);
config.commit();
}
use of org.glassfish.hk2.api.DynamicConfigurationService in project Payara by payara.
the class JarManifestModuleRegistry method parseInhabitants.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected List<ActiveDescriptor> parseInhabitants(HK2Module module, String name, ServiceLocator serviceLocator, List<PopulatorPostProcessor> postProcessors) throws IOException {
ArrayList<PopulatorPostProcessor> allPostProcessors = new ArrayList<PopulatorPostProcessor>();
allPostProcessors.add(new Hk2LoaderPopulatorPostProcessor(singleClassLoader));
if (postProcessors != null) {
allPostProcessors.addAll(postProcessors);
}
DynamicConfigurationService dcs = serviceLocator.getService(DynamicConfigurationService.class);
Populator populator = dcs.getPopulator();
List<ActiveDescriptor<?>> retVal = populator.populate(new ClasspathDescriptorFileFinder(singleClassLoader, name), allPostProcessors.toArray(new PopulatorPostProcessor[allPostProcessors.size()]));
return (List<ActiveDescriptor>) ((List) retVal);
}
use of org.glassfish.hk2.api.DynamicConfigurationService in project Payara by payara.
the class AppServerStartupTest method initialize.
// ----- test initialization ---------------------------------------------
private void initialize(ServiceLocator testLocator) {
DynamicConfigurationService dcs = testLocator.getService(DynamicConfigurationService.class);
DynamicConfiguration config = dcs.createDynamicConfiguration();
config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(new TestSystemTasks()));
// These are services that would normally be started by hk2 core
config.addActiveDescriptor(AppServerStartup.AppInstanceListener.class);
AbstractActiveDescriptor<?> descriptor = BuilderHelper.createConstantDescriptor(new TestModulesRegistry());
descriptor.addContractType(ModulesRegistry.class);
config.addActiveDescriptor(descriptor);
descriptor = BuilderHelper.createConstantDescriptor(new ExecutorServiceFactory().provide());
descriptor.addContractType(ExecutorService.class);
config.addActiveDescriptor(descriptor);
config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(new ServerEnvironmentImpl()));
config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(new EventsImpl()));
config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(new Version()));
config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(new StartupContext()));
config.bind(BuilderHelper.link(RunLevelControllerImpl.class).to(RunLevelController.class).build());
config.addUnbindFilter(BuilderHelper.createContractFilter(RunLevelContext.class.getName()));
config.bind(BuilderHelper.link(RunLevelContext.class).to(Context.class).in(Singleton.class).build());
config.addUnbindFilter(BuilderHelper.createContractFilter(AsyncRunLevelContext.class.getName()));
config.bind(BuilderHelper.link(AsyncRunLevelContext.class).in(Singleton.class).build());
config.bind(BuilderHelper.link(AppServerStartup.class).build());
descriptor = BuilderHelper.createConstantDescriptor(testLocator);
descriptor.addContractType(ServiceLocator.class);
config.addActiveDescriptor(descriptor);
bindService(config, TestInitRunLevelService.class);
bindService(config, TestStartupService.class);
bindService(config, TestStartupRunLevelService.class);
bindService(config, TestPostStartupRunLevelService.class);
bindService(config, CommonClassLoaderServiceImpl.class);
bindService(config, APIClassLoaderServiceImpl.class);
bindService(config, APIExporterImpl.class);
config.commit();
}
use of org.glassfish.hk2.api.DynamicConfigurationService in project Payara by payara.
the class HK2DomConfigUtilities method enableHK2DomConfiguration.
/**
* This method enables HK2 Dom based XML configuration parsing for
* systems that do not use HK2 metadata files or use a non-default
* name for HK2 metadata files. This method is idempotent, so that
* if the services already are available in the locator they will
* not get added again
*
* @param locator The non-null locator to add the hk2 dom based
* configuration services to
*/
public static void enableHK2DomConfiguration(ServiceLocator locator, HK2Loader loader) {
DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
DynamicConfiguration config = dcs.createDynamicConfiguration();
boolean dirty = false;
boolean operationDirty;
operationDirty = addIfNotThere(locator, config, getConfigSupport(), loader);
dirty = dirty || operationDirty;
operationDirty = addIfNotThere(locator, config, getConfigurationPopulator(), loader);
dirty = dirty || operationDirty;
operationDirty = addIfNotThere(locator, config, getTransactions(), loader);
dirty = dirty || operationDirty;
operationDirty = addIfNotThere(locator, config, getConfigInstanceListener(), loader);
dirty = dirty || operationDirty;
if (dirty) {
config.commit();
}
}
use of org.glassfish.hk2.api.DynamicConfigurationService 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);
}
Aggregations