Search in sources :

Example 11 with WeldConfiguration

use of org.jboss.weld.config.WeldConfiguration in project core by weld.

the class UnsafeEnabledTest method testRelaxedConstruction.

@Test
public void testRelaxedConstruction() {
    WeldConfiguration configuration = beanManager.getServices().get(WeldConfiguration.class);
    assertEquals(true, configuration.getBooleanProperty(ConfigurationKey.RELAXED_CONSTRUCTION));
    UnproxyableBean unproxyable = instance.get();
    // Interception will not work until after the constructor has finished
    assertFalse(SimpleInterceptor.INTERCEPTED.get());
    unproxyable.ping();
    assertTrue(SimpleInterceptor.INTERCEPTED.get());
}
Also used : WeldConfiguration(org.jboss.weld.config.WeldConfiguration) Test(org.junit.Test)

Example 12 with WeldConfiguration

use of org.jboss.weld.config.WeldConfiguration in project core by weld.

the class AccessibleManagerResolutionTest method beforeMethod.

@BeforeMethod
public void beforeMethod() {
    BeanIdentifierIndex beanIdentifierIndex = new BeanIdentifierIndex();
    beanIdentifierIndex.build(Collections.<Bean<?>>emptySet());
    this.typeStore = new TypeStore();
    this.classTransformer = new ClassTransformer(typeStore, new SharedObjectCache(), ReflectionCacheFactory.newInstance(typeStore), RegistrySingletonProvider.STATIC_INSTANCE);
    this.services = new SimpleServiceRegistry();
    this.services.add(MetaAnnotationStore.class, new MetaAnnotationStore(classTransformer));
    this.services.add(ContextualStore.class, new ContextualStoreImpl(STATIC_INSTANCE, beanIdentifierIndex));
    this.services.add(ClassTransformer.class, classTransformer);
    this.services.add(SharedObjectCache.class, new SharedObjectCache());
    this.services.add(WeldConfiguration.class, new WeldConfiguration(this.services, new MockDeployment(services)));
    this.services.add(SecurityServices.class, NoopSecurityServices.INSTANCE);
    this.services.add(ObserverNotifierFactory.class, DefaultObserverNotifierFactory.INSTANCE);
    this.services.add(GlobalObserverNotifierService.class, new GlobalObserverNotifierService(services, RegistrySingletonProvider.STATIC_INSTANCE));
    this.services.add(ExpressionLanguageSupport.class, WeldWebModule.EL_SUPPORT);
    this.services.add(SpecializationAndEnablementRegistry.class, new SpecializationAndEnablementRegistry());
    this.services.add(InterceptorsApiAbstraction.class, new InterceptorsApiAbstraction(DefaultResourceLoader.INSTANCE));
    this.services.add(ProxyInstantiator.class, DefaultProxyInstantiator.INSTANCE);
    this.services.add(ResourceInjectionFactory.class, new ResourceInjectionFactory());
    this.services.add(EjbSupport.class, EjbSupport.NOOP_IMPLEMENTATION);
    // create BeanManagerImpl and initialize container
    root = BeanManagerImpl.newRootManager(STATIC_INSTANCE, "root", services);
    Container.initialize(root, services);
    // add injection target service; has to be done once container was initialized
    this.services.add(InjectionTargetService.class, new InjectionTargetService(root));
}
Also used : SpecializationAndEnablementRegistry(org.jboss.weld.bootstrap.SpecializationAndEnablementRegistry) ResourceInjectionFactory(org.jboss.weld.injection.ResourceInjectionFactory) MetaAnnotationStore(org.jboss.weld.metadata.cache.MetaAnnotationStore) ClassTransformer(org.jboss.weld.resources.ClassTransformer) BeanIdentifierIndex(org.jboss.weld.serialization.BeanIdentifierIndex) InterceptorsApiAbstraction(org.jboss.weld.interceptor.builder.InterceptorsApiAbstraction) SharedObjectCache(org.jboss.weld.resources.SharedObjectCache) SimpleServiceRegistry(org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry) TypeStore(org.jboss.weld.metadata.TypeStore) InjectionTargetService(org.jboss.weld.injection.producer.InjectionTargetService) GlobalObserverNotifierService(org.jboss.weld.event.GlobalObserverNotifierService) WeldConfiguration(org.jboss.weld.config.WeldConfiguration) ContextualStoreImpl(org.jboss.weld.serialization.ContextualStoreImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 13 with WeldConfiguration

use of org.jboss.weld.config.WeldConfiguration in project core by weld.

the class WeldStartup method addImplementationServices.

private void addImplementationServices(ServiceRegistry services) {
    final WeldModules modules = new WeldModules();
    services.add(WeldModules.class, modules);
    final WeldConfiguration configuration = services.get(WeldConfiguration.class);
    services.add(SlimAnnotatedTypeStore.class, new SlimAnnotatedTypeStoreImpl());
    if (services.get(ClassTransformer.class) == null) {
        throw new IllegalStateException(ClassTransformer.class.getSimpleName() + " not installed.");
    }
    services.add(MemberTransformer.class, new MemberTransformer(services.get(ClassTransformer.class)));
    services.add(MetaAnnotationStore.class, new MetaAnnotationStore(services.get(ClassTransformer.class)));
    BeanIdentifierIndex beanIdentifierIndex = null;
    if (configuration.getBooleanProperty(ConfigurationKey.BEAN_IDENTIFIER_INDEX_OPTIMIZATION)) {
        beanIdentifierIndex = new BeanIdentifierIndex();
        services.add(BeanIdentifierIndex.class, beanIdentifierIndex);
    }
    services.add(ContextualStore.class, new ContextualStoreImpl(contextId, beanIdentifierIndex));
    services.add(CurrentInjectionPoint.class, new CurrentInjectionPoint());
    services.add(CurrentEventMetadata.class, new CurrentEventMetadata());
    services.add(SpecializationAndEnablementRegistry.class, new SpecializationAndEnablementRegistry());
    services.add(MissingDependenciesRegistry.class, new MissingDependenciesRegistry());
    /*
         * Setup ExecutorServices
         */
    ExecutorServices executor = services.get(ExecutorServices.class);
    if (executor == null) {
        executor = ExecutorServicesFactory.create(DefaultResourceLoader.INSTANCE, configuration);
        if (executor != null) {
            services.add(ExecutorServices.class, executor);
        }
    }
    services.add(RequiredAnnotationDiscovery.class, new RequiredAnnotationDiscovery(services.get(ReflectionCache.class)));
    services.add(GlobalEnablementBuilder.class, new GlobalEnablementBuilder());
    if (!services.contains(HttpContextActivationFilter.class)) {
        services.add(HttpContextActivationFilter.class, AcceptingHttpContextActivationFilter.INSTANCE);
    }
    services.add(ProtectionDomainCache.class, new ProtectionDomainCache());
    services.add(ProxyInstantiator.class, ProxyInstantiator.Factory.create(configuration));
    services.add(ObserverNotifierFactory.class, DefaultObserverNotifierFactory.INSTANCE);
    services.add(ResourceInjectionFactory.class, new ResourceInjectionFactory());
    modules.postServiceRegistration(contextId, services);
    /*
         * Setup Validator
         */
    if (configuration.getBooleanProperty(ConfigurationKey.CONCURRENT_DEPLOYMENT) && services.contains(ExecutorServices.class)) {
        services.add(Validator.class, new ConcurrentValidator(modules.getPluggableValidators(), executor));
    } else {
        services.add(Validator.class, new Validator(modules.getPluggableValidators()));
    }
    GlobalObserverNotifierService observerNotificationService = new GlobalObserverNotifierService(services, contextId);
    services.add(GlobalObserverNotifierService.class, observerNotificationService);
    /*
         * Preloader for container lifecycle events
         */
    ContainerLifecycleEventPreloader preloader = null;
    int preloaderThreadPoolSize = configuration.getIntegerProperty(ConfigurationKey.PRELOADER_THREAD_POOL_SIZE);
    if (preloaderThreadPoolSize > 0 && Permissions.hasPermission(Permissions.MODIFY_THREAD_GROUP)) {
        preloader = new ContainerLifecycleEventPreloader(preloaderThreadPoolSize, observerNotificationService.getGlobalLenientObserverNotifier());
    }
    services.add(ContainerLifecycleEvents.class, new ContainerLifecycleEvents(preloader, services.get(RequiredAnnotationDiscovery.class)));
    if (environment.isEEModulesAware()) {
        services.add(BeanDeploymentModules.class, new BeanDeploymentModules(contextId, services));
    }
}
Also used : MemberTransformer(org.jboss.weld.resources.MemberTransformer) RequiredAnnotationDiscovery(org.jboss.weld.bootstrap.events.RequiredAnnotationDiscovery) CurrentInjectionPoint(org.jboss.weld.injection.CurrentInjectionPoint) AcceptingHttpContextActivationFilter(org.jboss.weld.servlet.spi.helpers.AcceptingHttpContextActivationFilter) HttpContextActivationFilter(org.jboss.weld.servlet.spi.HttpContextActivationFilter) GlobalEnablementBuilder(org.jboss.weld.bootstrap.enablement.GlobalEnablementBuilder) ContainerLifecycleEventPreloader(org.jboss.weld.bootstrap.events.ContainerLifecycleEventPreloader) MetaAnnotationStore(org.jboss.weld.metadata.cache.MetaAnnotationStore) ClassTransformer(org.jboss.weld.resources.ClassTransformer) BeanIdentifierIndex(org.jboss.weld.serialization.BeanIdentifierIndex) ContainerLifecycleEvents(org.jboss.weld.bootstrap.events.ContainerLifecycleEvents) ContextualStoreImpl(org.jboss.weld.serialization.ContextualStoreImpl) ResourceInjectionFactory(org.jboss.weld.injection.ResourceInjectionFactory) WeldModules(org.jboss.weld.module.WeldModules) CurrentInjectionPoint(org.jboss.weld.injection.CurrentInjectionPoint) SlimAnnotatedTypeStoreImpl(org.jboss.weld.annotated.slim.SlimAnnotatedTypeStoreImpl) ExecutorServices(org.jboss.weld.manager.api.ExecutorServices) ProtectionDomainCache(org.jboss.weld.bean.proxy.ProtectionDomainCache) GlobalObserverNotifierService(org.jboss.weld.event.GlobalObserverNotifierService) WeldConfiguration(org.jboss.weld.config.WeldConfiguration) CurrentEventMetadata(org.jboss.weld.event.CurrentEventMetadata)

Example 14 with WeldConfiguration

use of org.jboss.weld.config.WeldConfiguration in project core by weld.

the class WeldStartup method startContainer.

public WeldRuntime startContainer(String contextId, Environment environment, Deployment deployment) {
    if (deployment == null) {
        throw BootstrapLogger.LOG.deploymentRequired();
    }
    tracker.start(Tracker.OP_BOOTSTRAP);
    tracker.start(Tracker.OP_START_CONTAINER);
    checkApiVersion();
    final ServiceRegistry registry = deployment.getServices();
    // initiate part of registry in order to allow access to WeldConfiguration
    new AdditionalServiceLoader(deployment).loadAdditionalServices(registry);
    // Resource Loader has to be loaded prior to WeldConfiguration
    if (!registry.contains(ResourceLoader.class)) {
        registry.add(ResourceLoader.class, DefaultResourceLoader.INSTANCE);
    }
    WeldConfiguration configuration = new WeldConfiguration(registry, deployment);
    registry.add(WeldConfiguration.class, configuration);
    String finalContextId = BeanDeployments.getFinalId(contextId, registry.get(WeldConfiguration.class).getStringProperty(ROLLING_UPGRADES_ID_DELIMITER));
    this.contextId = finalContextId;
    this.deployment = deployment;
    this.environment = environment;
    if (this.extensions == null) {
        setExtensions(deployment.getExtensions());
    }
    // Add extension to register built-in components
    this.extensions.add(MetadataImpl.from(new WeldExtension()));
    // Add Weld extensions
    String vetoTypeRegex = configuration.getStringProperty(ConfigurationKey.VETO_TYPES_WITHOUT_BEAN_DEFINING_ANNOTATION);
    if (!vetoTypeRegex.isEmpty()) {
        this.extensions.add(MetadataImpl.from(new WeldVetoExtension(vetoTypeRegex)));
    }
    // Finish the rest of registry init, setupInitialServices() requires already changed finalContextId
    tracker.start(Tracker.OP_INIT_SERVICES);
    setupInitialServices();
    registry.addAll(initialServices.entrySet());
    if (!registry.contains(ProxyServices.class)) {
        registry.add(ProxyServices.class, new SimpleProxyServices());
    }
    if (!registry.contains(SecurityServices.class)) {
        registry.add(SecurityServices.class, NoopSecurityServices.INSTANCE);
    }
    addImplementationServices(registry);
    tracker.end();
    verifyServices(registry, environment.getRequiredDeploymentServices(), contextId);
    if (!registry.contains(TransactionServices.class)) {
        BootstrapLogger.LOG.jtaUnavailable();
    }
    this.deploymentManager = BeanManagerImpl.newRootManager(finalContextId, "deployment", registry);
    Container.initialize(finalContextId, deploymentManager, ServiceRegistries.unmodifiableServiceRegistry(deployment.getServices()));
    getContainer().setState(ContainerState.STARTING);
    tracker.start(Tracker.OP_CONTEXTS);
    this.contexts = createContexts(registry);
    tracker.end();
    this.bdaMapping = new BeanDeploymentArchiveMapping();
    this.deploymentVisitor = new DeploymentVisitor(deploymentManager, environment, deployment, contexts, bdaMapping);
    if (deployment instanceof CDI11Deployment) {
        registry.add(BeanManagerLookupService.class, new BeanManagerLookupService((CDI11Deployment) deployment, bdaMapping.getBdaToBeanManagerMap()));
    } else {
        BootstrapLogger.LOG.legacyDeploymentMetadataProvided();
    }
    // Read the deployment structure, bdaMapping will be the physical structure
    // as caused by the presence of beans.xml
    tracker.start(Tracker.OP_READ_DEPLOYMENT);
    deploymentVisitor.visit();
    tracker.end();
    WeldRuntime weldRuntime = new WeldRuntime(finalContextId, deploymentManager, bdaMapping.getBdaToBeanManagerMap());
    tracker.end();
    return weldRuntime;
}
Also used : ProxyServices(org.jboss.weld.serialization.spi.ProxyServices) SimpleProxyServices(org.jboss.weld.bean.proxy.util.SimpleProxyServices) DefaultResourceLoader(org.jboss.weld.resources.DefaultResourceLoader) ResourceLoader(org.jboss.weld.resources.spi.ResourceLoader) SecurityServices(org.jboss.weld.security.spi.SecurityServices) NoopSecurityServices(org.jboss.weld.security.NoopSecurityServices) BeanManagerLookupService(org.jboss.weld.manager.BeanManagerLookupService) CDI11Deployment(org.jboss.weld.bootstrap.spi.CDI11Deployment) SimpleProxyServices(org.jboss.weld.bean.proxy.util.SimpleProxyServices) TransactionServices(org.jboss.weld.transaction.spi.TransactionServices) ServiceRegistry(org.jboss.weld.bootstrap.api.ServiceRegistry) SimpleServiceRegistry(org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry) WeldConfiguration(org.jboss.weld.config.WeldConfiguration)

Example 15 with WeldConfiguration

use of org.jboss.weld.config.WeldConfiguration in project core by weld.

the class BootstrapConfigurationConfigTest method testBootstrapConfiguration.

@Test
public void testBootstrapConfiguration() {
    WeldConfiguration configuration = manager.getServices().get(WeldConfiguration.class);
    assertFalse(configuration.getBooleanProperty(ConfigurationKey.CONCURRENT_DEPLOYMENT));
    assertEquals(Integer.valueOf(100), configuration.getIntegerProperty(ConfigurationKey.PRELOADER_THREAD_POOL_SIZE));
    assertTrue(configuration.getBooleanProperty(ConfigurationKey.NON_PORTABLE_MODE));
}
Also used : WeldConfiguration(org.jboss.weld.config.WeldConfiguration) Test(org.junit.Test)

Aggregations

WeldConfiguration (org.jboss.weld.config.WeldConfiguration)15 Test (org.junit.Test)8 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)3 SimpleServiceRegistry (org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry)2 ConfigurationKey (org.jboss.weld.config.ConfigurationKey)2 GlobalObserverNotifierService (org.jboss.weld.event.GlobalObserverNotifierService)2 ResourceInjectionFactory (org.jboss.weld.injection.ResourceInjectionFactory)2 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)2 MetaAnnotationStore (org.jboss.weld.metadata.cache.MetaAnnotationStore)2 ClassTransformer (org.jboss.weld.resources.ClassTransformer)2 BeanIdentifierIndex (org.jboss.weld.serialization.BeanIdentifierIndex)2 ContextualStoreImpl (org.jboss.weld.serialization.ContextualStoreImpl)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ArrayList (java.util.ArrayList)1 Bean (javax.enterprise.inject.spi.Bean)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 SlimAnnotatedTypeStoreImpl (org.jboss.weld.annotated.slim.SlimAnnotatedTypeStoreImpl)1 AbstractClassBean (org.jboss.weld.bean.AbstractClassBean)1 AbstractProducerBean (org.jboss.weld.bean.AbstractProducerBean)1 SessionBean (org.jboss.weld.bean.SessionBean)1