Search in sources :

Example 1 with WeldComponentService

use of org.jboss.as.weld.injection.WeldComponentService in project wildfly by wildfly.

the class WeldComponentIntegrationProcessor method addWeldIntegration.

/**
     * As the weld based instantiator needs access to the bean manager it is installed as a service.
     */
private void addWeldIntegration(final Iterable<ComponentIntegrator> componentIntegrators, final ComponentInterceptorSupport componentInterceptorSupport, final ServiceTarget target, final ComponentConfiguration configuration, final ComponentDescription description, final Class<?> componentClass, final String beanName, final ServiceName weldServiceName, final ServiceName weldStartService, final ServiceName beanManagerService, final Set<Class<?>> interceptorClasses, final ClassLoader classLoader, final String beanDeploymentArchiveId) {
    final ServiceName serviceName = configuration.getComponentDescription().getServiceName().append("WeldInstantiator");
    final WeldComponentService weldComponentService = new WeldComponentService(componentClass, beanName, interceptorClasses, classLoader, beanDeploymentArchiveId, description.isCDIInterceptorEnabled(), description, isComponentWithView(description, componentIntegrators));
    final ServiceBuilder<WeldComponentService> builder = target.addService(serviceName, weldComponentService).addDependency(weldServiceName, WeldBootstrapService.class, weldComponentService.getWeldContainer()).addDependency(weldStartService);
    configuration.setInstanceFactory(WeldManagedReferenceFactory.INSTANCE);
    configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {

        @Override
        public void configureDependency(final ServiceBuilder<?> serviceBuilder, ComponentStartService service) throws DeploymentUnitProcessingException {
            serviceBuilder.addDependency(serviceName);
        }
    });
    boolean isComponentIntegrationPerformed = false;
    for (ComponentIntegrator componentIntegrator : componentIntegrators) {
        Supplier<ServiceName> bindingServiceNameSupplier = () -> {
            if (componentInterceptorSupport == null) {
                WeldLogger.DEPLOYMENT_LOGGER.componentInterceptorSupportNotAvailable(componentClass);
            }
            return addWeldInterceptorBindingService(target, configuration, componentClass, beanName, weldServiceName, weldStartService, beanDeploymentArchiveId, componentInterceptorSupport);
        };
        DefaultInterceptorIntegrationAction integrationAction = (bindingServiceName) -> {
            if (componentInterceptorSupport == null) {
                WeldLogger.DEPLOYMENT_LOGGER.componentInterceptorSupportNotAvailable(componentClass);
            }
            addJsr299BindingsCreateInterceptor(configuration, description, beanName, weldServiceName, builder, bindingServiceName, componentInterceptorSupport);
            addCommonLifecycleInterceptionSupport(configuration, builder, bindingServiceName, beanManagerService, componentInterceptorSupport);
            configuration.addComponentInterceptor(new UserInterceptorFactory(factory(InterceptionType.AROUND_INVOKE, builder, bindingServiceName, componentInterceptorSupport), factory(InterceptionType.AROUND_TIMEOUT, builder, bindingServiceName, componentInterceptorSupport)), InterceptorOrder.Component.CDI_INTERCEPTORS, false);
        };
        if (componentIntegrator.integrate(beanManagerService, configuration, description, builder, bindingServiceNameSupplier, integrationAction, componentInterceptorSupport)) {
            isComponentIntegrationPerformed = true;
            break;
        }
    }
    if (!isComponentIntegrationPerformed) {
        //otherwise they will be called twice
        description.setIgnoreLifecycleInterceptors(true);
        // for components with no view register interceptors that delegate to InjectionTarget lifecycle methods to trigger lifecycle interception
        configuration.addPostConstructInterceptor(new ImmediateInterceptorFactory(new AbstractInjectionTargetDelegatingInterceptor() {

            @Override
            protected void run(Object instance) {
                weldComponentService.getInjectionTarget().postConstruct(instance);
            }
        }), InterceptorOrder.ComponentPostConstruct.CDI_INTERCEPTORS);
        configuration.addPreDestroyInterceptor(new ImmediateInterceptorFactory(new AbstractInjectionTargetDelegatingInterceptor() {

            @Override
            protected void run(Object instance) {
                weldComponentService.getInjectionTarget().preDestroy(instance);
            }
        }), InterceptorOrder.ComponentPreDestroy.CDI_INTERCEPTORS);
    }
    builder.install();
    configuration.addPostConstructInterceptor(new ImmediateInterceptorFactory(new WeldInjectionContextInterceptor(weldComponentService)), InterceptorOrder.ComponentPostConstruct.WELD_INJECTION_CONTEXT_INTERCEPTOR);
    configuration.addPostConstructInterceptor(new ImmediateInterceptorFactory(new WeldInterceptorInjectionInterceptor(interceptorClasses)), InterceptorOrder.ComponentPostConstruct.INTERCEPTOR_WELD_INJECTION);
    configuration.addPostConstructInterceptor(WeldInjectionInterceptor.FACTORY, InterceptorOrder.ComponentPostConstruct.COMPONENT_WELD_INJECTION);
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) WeldInterceptorInjectionInterceptor(org.jboss.as.weld.injection.WeldInterceptorInjectionInterceptor) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) UserInterceptorFactory(org.jboss.as.ee.component.interceptors.UserInterceptorFactory) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) InterceptorDescription(org.jboss.as.ee.component.InterceptorDescription) Jsr299BindingsInterceptor.factory(org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.factory) WeldManagedReferenceFactory(org.jboss.as.weld.injection.WeldManagedReferenceFactory) ManagedReference(org.jboss.as.naming.ManagedReference) ServiceNames(org.jboss.as.weld.ServiceNames) InterceptorOrder(org.jboss.as.ee.component.interceptors.InterceptorOrder) ServiceTarget(org.jboss.msc.service.ServiceTarget) WeldLogger(org.jboss.as.weld.logging.WeldLogger) ComponentStartService(org.jboss.as.ee.component.ComponentStartService) WeldComponentService(org.jboss.as.weld.injection.WeldComponentService) Set(java.util.Set) ServiceLoader(java.util.ServiceLoader) WeldBootstrapService(org.jboss.as.weld.WeldBootstrapService) InterceptorContext(org.jboss.invocation.InterceptorContext) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) WeldInterceptorBindingsService(org.jboss.as.weld.ejb.WeldInterceptorBindingsService) WildFlySecurityManager(org.wildfly.security.manager.WildFlySecurityManager) Module(org.jboss.modules.Module) ServiceName(org.jboss.msc.service.ServiceName) WeldInjectionInterceptor(org.jboss.as.weld.injection.WeldInjectionInterceptor) ComponentIntegrator(org.jboss.as.weld.spi.ComponentIntegrator) Interceptor(org.jboss.invocation.Interceptor) DependencyConfigurator(org.jboss.as.ee.component.DependencyConfigurator) WeldConstructionStartInterceptor(org.jboss.as.weld.injection.WeldConstructionStartInterceptor) Supplier(java.util.function.Supplier) Utils.getRootDeploymentUnit(org.jboss.as.weld.util.Utils.getRootDeploymentUnit) HashSet(java.util.HashSet) WeldDeploymentMarker(org.jboss.as.ee.weld.WeldDeploymentMarker) DefaultInterceptorIntegrationAction(org.jboss.as.weld.spi.ComponentIntegrator.DefaultInterceptorIntegrationAction) ComponentInterceptorSupport(org.jboss.as.weld.spi.ComponentInterceptorSupport) InterceptorBindings(org.jboss.weld.ejb.spi.InterceptorBindings) WeldStartService(org.jboss.as.weld.WeldStartService) DeploymentUnitProcessor(org.jboss.as.server.deployment.DeploymentUnitProcessor) EjbRequestScopeActivationInterceptor(org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ServiceLoaders(org.jboss.as.weld.util.ServiceLoaders) Jsr299BindingsCreateInterceptor(org.jboss.as.weld.interceptors.Jsr299BindingsCreateInterceptor) WeldClassIntrospector(org.jboss.as.weld.deployment.WeldClassIntrospector) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) WeldInjectionContextInterceptor(org.jboss.as.weld.injection.WeldInjectionContextInterceptor) ComponentInstance(org.jboss.as.ee.component.ComponentInstance) ClassLoadingUtils(org.jboss.as.ee.utils.ClassLoadingUtils) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) BasicComponentInstance(org.jboss.as.ee.component.BasicComponentInstance) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) Attachments(org.jboss.as.server.deployment.Attachments) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) InterceptionType(javax.enterprise.inject.spi.InterceptionType) WeldInjectionContextInterceptor(org.jboss.as.weld.injection.WeldInjectionContextInterceptor) ServiceName(org.jboss.msc.service.ServiceName) ComponentIntegrator(org.jboss.as.weld.spi.ComponentIntegrator) UserInterceptorFactory(org.jboss.as.ee.component.interceptors.UserInterceptorFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) DefaultInterceptorIntegrationAction(org.jboss.as.weld.spi.ComponentIntegrator.DefaultInterceptorIntegrationAction) WeldBootstrapService(org.jboss.as.weld.WeldBootstrapService) WeldComponentService(org.jboss.as.weld.injection.WeldComponentService) ComponentStartService(org.jboss.as.ee.component.ComponentStartService) WeldInterceptorInjectionInterceptor(org.jboss.as.weld.injection.WeldInterceptorInjectionInterceptor)

Aggregations

HashSet (java.util.HashSet)1 ServiceLoader (java.util.ServiceLoader)1 Set (java.util.Set)1 Supplier (java.util.function.Supplier)1 InterceptionType (javax.enterprise.inject.spi.InterceptionType)1 BasicComponentInstance (org.jboss.as.ee.component.BasicComponentInstance)1 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)1 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)1 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)1 ComponentInstance (org.jboss.as.ee.component.ComponentInstance)1 ComponentStartService (org.jboss.as.ee.component.ComponentStartService)1 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)1 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)1 InterceptorDescription (org.jboss.as.ee.component.InterceptorDescription)1 ViewConfiguration (org.jboss.as.ee.component.ViewConfiguration)1 InterceptorOrder (org.jboss.as.ee.component.interceptors.InterceptorOrder)1 UserInterceptorFactory (org.jboss.as.ee.component.interceptors.UserInterceptorFactory)1 ClassLoadingUtils (org.jboss.as.ee.utils.ClassLoadingUtils)1 WeldDeploymentMarker (org.jboss.as.ee.weld.WeldDeploymentMarker)1 ManagedReference (org.jboss.as.naming.ManagedReference)1