Search in sources :

Example 1 with DynamicConfigurationService

use of org.glassfish.hk2.api.DynamicConfigurationService in project jersey by jersey.

the class Main method main.

public static void main(String[] args) {
    ServiceLocatorFactory factory = ServiceLocatorFactory.getInstance();
    ServiceLocator locator = factory.create("myLocator");
    DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
    DynamicConfiguration dc = dcs.createDynamicConfiguration();
    AbstractBinder binder = new AbstractBinder() {

        @Override
        protected void configure() {
            bind(HelloServiceImpl.class).to(GreetingService.class);
        }
    };
    locator.inject(binder);
    binder.bind(dc);
    dc.commit();
    GreetingWrapper wrapper = new GreetingWrapper(locator);
    System.out.println("result: " + wrapper.getInjectedGreeting());
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) ServiceLocatorFactory(org.glassfish.hk2.api.ServiceLocatorFactory)

Example 2 with DynamicConfigurationService

use of org.glassfish.hk2.api.DynamicConfigurationService in project jersey by jersey.

the class MyServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    ServiceLocatorFactory factory = ServiceLocatorFactory.getInstance();
    ServiceLocator locator = factory.create("myLocator");
    DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
    DynamicConfiguration dc = dcs.createDynamicConfiguration();
    AbstractBinder binder = new AbstractBinder() {

        @Override
        protected void configure() {
            bind(HelloServiceImpl.class).to(GreetingService.class);
        }
    };
    binder.bind(dc);
    dc.commit();
    GreetingWrapper wrapper = new GreetingWrapper(locator);
    response.getWriter().write("Greeting: " + wrapper.getInjectedGreeting());
    locator.shutdown();
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) ServiceLocatorFactory(org.glassfish.hk2.api.ServiceLocatorFactory)

Example 3 with DynamicConfigurationService

use of org.glassfish.hk2.api.DynamicConfigurationService in project Payara by payara.

the class EjbInjectedWithServiceLocator method installHK2Service.

@Override
public void installHK2Service() {
    DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
    DynamicConfiguration config = dcs.createDynamicConfiguration();
    config.addActiveDescriptor(BasicService.class);
    config.commit();
}
Also used : DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration)

Example 4 with DynamicConfigurationService

use of org.glassfish.hk2.api.DynamicConfigurationService in project Payara by payara.

the class HK2IntegrationExtension method afterDeploymentValidation.

/**
 * Called by CDI after it has been completely validated.  Will add the JIT resolver to HK2
 * with the BeanManager
 *
 * @param event This is just to mark the type of the event
 * @param manager The manager that will be used to get references
 */
@SuppressWarnings("unused")
private void afterDeploymentValidation(@Observes AfterDeploymentValidation event) {
    if (locator == null)
        return;
    DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
    DynamicConfiguration config = dcs.createDynamicConfiguration();
    config.addActiveDescriptor(CDISecondChanceResolver.class);
    config.addActiveDescriptor(CDIContextBridge.class);
    config.commit();
}
Also used : DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration)

Example 5 with DynamicConfigurationService

use of org.glassfish.hk2.api.DynamicConfigurationService in project Payara by payara.

the class ConfigListenerTest method registerAndCreateHttpListenerContainer.

private HttpListenerContainer registerAndCreateHttpListenerContainer(ServiceLocator locator) {
    HttpListenerContainer retVal = locator.getService(HttpListenerContainer.class);
    if (retVal != null)
        return retVal;
    DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
    Assert.assertNotNull(dcs);
    DynamicConfiguration config = dcs.createDynamicConfiguration();
    config.addActiveDescriptor(HttpListenerContainer.class);
    config.commit();
    return locator.getService(HttpListenerContainer.class);
}
Also used : DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration)

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