Search in sources :

Example 1 with AbstractActiveDescriptor

use of org.glassfish.hk2.utilities.AbstractActiveDescriptor 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();
    }
}
Also used : DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) StartupContext(com.sun.enterprise.module.bootstrap.StartupContext) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry) Logger(java.util.logging.Logger) ProcessEnvironment(org.glassfish.api.admin.ProcessEnvironment) ClientNamingConfigurator(org.glassfish.api.naming.ClientNamingConfigurator) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ClientNamingConfiguratorImpl(com.sun.enterprise.naming.impl.ClientNamingConfiguratorImpl) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) ModulesRegistry(com.sun.enterprise.module.ModulesRegistry) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry)

Example 2 with AbstractActiveDescriptor

use of org.glassfish.hk2.utilities.AbstractActiveDescriptor 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 3 with AbstractActiveDescriptor

use of org.glassfish.hk2.utilities.AbstractActiveDescriptor in project Payara by payara.

the class AbstractRestResourceProvider method getResourceConfig.

@Override
public ResourceConfig getResourceConfig(Set<Class<?>> classes, final ServerContext sc, final ServiceLocator habitat, final Set<? extends Binder> additionalBinders) throws EndpointRegistrationException {
    final Reloader r = new Reloader();
    ResourceConfig rc = new ResourceConfig(classes);
    rc.property(ServerProperties.MEDIA_TYPE_MAPPINGS, getMimeMappings());
    rc.register(CsrfProtectionFilter.class);
    // TODO - JERSEY2
    // RestConfig restConf = ResourceUtil.getRestConfig(habitat);
    // if (restConf != null) {
    // if (restConf.getLogOutput().equalsIgnoreCase("true")) { //enable output logging
    // rc.getContainerResponseFilters().add(LoggingFilter.class);
    // }
    // if (restConf.getLogInput().equalsIgnoreCase("true")) { //enable input logging
    // rc.getContainerRequestFilters().add(LoggingFilter.class);
    // }
    // if (restConf.getWadlGeneration().equalsIgnoreCase("false")) { //disable WADL
    // rc.getFeatures().put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE);
    // }
    // }
    // else {
    // rc.getFeatures().put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE);
    // }
    // 
    rc.register(r);
    rc.register(ReloadResource.class);
    rc.register(new MultiPartFeature());
    // rc.register(getJsonFeature());
    rc.register(new AbstractBinder() {

        @Override
        protected void configure() {
            AbstractActiveDescriptor<Reloader> descriptor = BuilderHelper.createConstantDescriptor(r);
            descriptor.addContractType(Reloader.class);
            bind(descriptor);
            AbstractActiveDescriptor<ServerContext> scDescriptor = BuilderHelper.createConstantDescriptor(sc);
            scDescriptor.addContractType(ServerContext.class);
            bind(scDescriptor);
            LocatorBridge locatorBridge = new LocatorBridge(habitat);
            AbstractActiveDescriptor<LocatorBridge> hDescriptor = BuilderHelper.createConstantDescriptor(locatorBridge);
            bind(hDescriptor);
            RestSessionManager rsm = habitat.getService(RestSessionManager.class);
            AbstractActiveDescriptor<RestSessionManager> rmDescriptor = BuilderHelper.createConstantDescriptor(rsm);
            bind(rmDescriptor);
        }
    });
    for (Binder b : additionalBinders) {
        rc.register(b);
    }
    rc.property(MessageProperties.LEGACY_WORKERS_ORDERING, true);
    return rc;
}
Also used : Binder(org.glassfish.hk2.utilities.Binder) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) ServerContext(org.glassfish.internal.api.ServerContext) MultiPartFeature(org.glassfish.jersey.media.multipart.MultiPartFeature) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) RestSessionManager(org.glassfish.common.util.admin.RestSessionManager) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) AbstractActiveDescriptor(org.glassfish.hk2.utilities.AbstractActiveDescriptor)

Aggregations

StartupContext (com.sun.enterprise.module.bootstrap.StartupContext)2 DynamicConfiguration (org.glassfish.hk2.api.DynamicConfiguration)2 DynamicConfigurationService (org.glassfish.hk2.api.DynamicConfigurationService)2 Version (com.sun.appserv.server.util.Version)1 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)1 StaticModulesRegistry (com.sun.enterprise.module.single.StaticModulesRegistry)1 ClientNamingConfiguratorImpl (com.sun.enterprise.naming.impl.ClientNamingConfiguratorImpl)1 Logger (java.util.logging.Logger)1 ProcessEnvironment (org.glassfish.api.admin.ProcessEnvironment)1 ClientNamingConfigurator (org.glassfish.api.naming.ClientNamingConfigurator)1 RestSessionManager (org.glassfish.common.util.admin.RestSessionManager)1 Context (org.glassfish.hk2.api.Context)1 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)1 RunLevelContext (org.glassfish.hk2.runlevel.RunLevelContext)1 AsyncRunLevelContext (org.glassfish.hk2.runlevel.internal.AsyncRunLevelContext)1 RunLevelControllerImpl (org.glassfish.hk2.runlevel.internal.RunLevelControllerImpl)1 AbstractActiveDescriptor (org.glassfish.hk2.utilities.AbstractActiveDescriptor)1 Binder (org.glassfish.hk2.utilities.Binder)1 AbstractBinder (org.glassfish.hk2.utilities.binding.AbstractBinder)1 ServerContext (org.glassfish.internal.api.ServerContext)1