Search in sources :

Example 11 with DynamicConfigurationService

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();
}
Also used : DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration)

Example 12 with DynamicConfigurationService

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);
}
Also used : DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) ClasspathDescriptorFileFinder(org.glassfish.hk2.utilities.ClasspathDescriptorFileFinder) ArrayList(java.util.ArrayList) PopulatorPostProcessor(org.glassfish.hk2.api.PopulatorPostProcessor) Hk2LoaderPopulatorPostProcessor(org.glassfish.hk2.bootstrap.impl.Hk2LoaderPopulatorPostProcessor) Hk2LoaderPopulatorPostProcessor(org.glassfish.hk2.bootstrap.impl.Hk2LoaderPopulatorPostProcessor) ArrayList(java.util.ArrayList) List(java.util.List) Populator(org.glassfish.hk2.api.Populator)

Example 13 with DynamicConfigurationService

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();
}
Also used : RunLevelContext(org.glassfish.hk2.runlevel.RunLevelContext) StartupContext(com.sun.enterprise.module.bootstrap.StartupContext) AsyncRunLevelContext(org.glassfish.hk2.runlevel.internal.AsyncRunLevelContext) Context(org.glassfish.hk2.api.Context) DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) StartupContext(com.sun.enterprise.module.bootstrap.StartupContext) ServerEnvironmentImpl(org.glassfish.server.ServerEnvironmentImpl) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) Version(com.sun.appserv.server.util.Version) AsyncRunLevelContext(org.glassfish.hk2.runlevel.internal.AsyncRunLevelContext) RunLevelControllerImpl(org.glassfish.hk2.runlevel.internal.RunLevelControllerImpl) EventsImpl(org.glassfish.kernel.event.EventsImpl)

Example 14 with DynamicConfigurationService

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();
    }
}
Also used : DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration)

Example 15 with DynamicConfigurationService

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);
}
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

DynamicConfigurationService (org.glassfish.hk2.api.DynamicConfigurationService)18 DynamicConfiguration (org.glassfish.hk2.api.DynamicConfiguration)17 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)6 StartupContext (com.sun.enterprise.module.bootstrap.StartupContext)3 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)2 ProcessEnvironment (org.glassfish.api.admin.ProcessEnvironment)2 ServiceLocatorFactory (org.glassfish.hk2.api.ServiceLocatorFactory)2 AbstractBinder (org.glassfish.hk2.utilities.binding.AbstractBinder)2 Before (org.junit.Before)2 Version (com.sun.appserv.server.util.Version)1 ProgramOptions (com.sun.enterprise.admin.cli.ProgramOptions)1 EmbeddedInhabitantsParser (com.sun.enterprise.glassfish.bootstrap.EmbeddedInhabitantsParser)1 ModuleStartup (com.sun.enterprise.module.bootstrap.ModuleStartup)1 StaticModulesRegistry (com.sun.enterprise.module.single.StaticModulesRegistry)1 ClientNamingConfiguratorImpl (com.sun.enterprise.naming.impl.ClientNamingConfiguratorImpl)1 OpenURLClassLoader (fish.payara.micro.boot.loader.OpenURLClassLoader)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Logger (java.util.logging.Logger)1