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