Search in sources :

Example 1 with WeldBootstrapService

use of org.jboss.as.weld.WeldBootstrapService in project wildfly by wildfly.

the class WeldComponentIntegrationProcessor method addWeldInterceptorBindingService.

private static ServiceName addWeldInterceptorBindingService(final ServiceTarget target, final ComponentConfiguration configuration, final Class<?> componentClass, final String beanName, final ServiceName weldServiceName, final ServiceName weldStartService, final String beanDeploymentArchiveId, final ComponentInterceptorSupport componentInterceptorSupport) {
    ServiceName bindingServiceName = configuration.getComponentDescription().getServiceName().append(WeldInterceptorBindingsService.SERVICE_NAME);
    final ServiceBuilder<?> sb = target.addService(bindingServiceName);
    final Consumer<InterceptorBindings> interceptorBindingsConsumer = sb.provides(bindingServiceName);
    final Supplier<WeldBootstrapService> weldContainerSupplier = sb.requires(weldServiceName);
    sb.requires(weldStartService);
    sb.setInstance(new WeldInterceptorBindingsService(interceptorBindingsConsumer, weldContainerSupplier, beanDeploymentArchiveId, beanName, componentClass, componentInterceptorSupport));
    sb.install();
    return bindingServiceName;
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) WeldInterceptorBindingsService(org.jboss.as.weld.ejb.WeldInterceptorBindingsService) InterceptorBindings(org.jboss.weld.ejb.spi.InterceptorBindings) WeldBootstrapService(org.jboss.as.weld.WeldBootstrapService)

Example 2 with WeldBootstrapService

use of org.jboss.as.weld.WeldBootstrapService 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 ServiceBuilder<?> builder = target.addService(serviceName);
    builder.requires(weldStartService);
    configuration.setInstanceFactory(WeldManagedReferenceFactory.INSTANCE);
    configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {

        @Override
        public void configureDependency(final ServiceBuilder<?> serviceBuilder, ComponentStartService service) throws DeploymentUnitProcessingException {
            serviceBuilder.requires(serviceName);
        }
    });
    boolean isComponentIntegrationPerformed = false;
    for (ComponentIntegrator componentIntegrator : componentIntegrators) {
        Supplier<ServiceName> bindingServiceNameSupplier = () -> {
            if (componentInterceptorSupport == null) {
                throw WeldLogger.DEPLOYMENT_LOGGER.componentInterceptorSupportNotAvailable(componentClass);
            }
            return addWeldInterceptorBindingService(target, configuration, componentClass, beanName, weldServiceName, weldStartService, beanDeploymentArchiveId, componentInterceptorSupport);
        };
        DefaultInterceptorIntegrationAction integrationAction = (bindingServiceName) -> {
            if (componentInterceptorSupport == null) {
                throw 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;
        }
    }
    final Supplier<WeldBootstrapService> weldContainerSupplier = builder.requires(weldServiceName);
    final WeldComponentService weldComponentService = new WeldComponentService(weldContainerSupplier, componentClass, beanName, interceptorClasses, classLoader, beanDeploymentArchiveId, description.isCDIInterceptorEnabled(), description, isComponentWithView(description, componentIntegrators));
    builder.setInstance(weldComponentService);
    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) WeldDeploymentMarker(org.jboss.as.weld._private.WeldDeploymentMarker) 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) 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) Consumer(java.util.function.Consumer) 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) ComponentStartService(org.jboss.as.ee.component.ComponentStartService) WeldComponentService(org.jboss.as.weld.injection.WeldComponentService) WeldInterceptorInjectionInterceptor(org.jboss.as.weld.injection.WeldInterceptorInjectionInterceptor)

Example 3 with WeldBootstrapService

use of org.jboss.as.weld.WeldBootstrapService in project wildfly by wildfly.

the class WeldDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final DeploymentUnit parent = Utils.getRootDeploymentUnit(deploymentUnit);
    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
        // if there are CDI annotation present and this is the top level deployment we log a warning
        if (deploymentUnit.getParent() == null && CdiAnnotationMarker.cdiAnnotationsPresent(deploymentUnit)) {
            WeldLogger.DEPLOYMENT_LOGGER.cdiAnnotationsButNotBeanArchive(deploymentUnit.getName());
        }
        return;
    }
    // add a dependency on the weld service to web deployments
    final ServiceName weldBootstrapServiceName = parent.getServiceName().append(WeldBootstrapService.SERVICE_NAME);
    final ServiceName weldBootstrapServiceInternalName = parent.getServiceName().append(WeldBootstrapService.INTERNAL_SERVICE_NAME);
    ServiceName weldStartServiceName = parent.getServiceName().append(WeldStartService.SERVICE_NAME);
    deploymentUnit.addToAttachmentList(Attachments.WEB_DEPENDENCIES, weldStartServiceName);
    final Set<ServiceName> dependencies = new HashSet<ServiceName>();
    // we only start weld on top level deployments
    if (deploymentUnit.getParent() != null) {
        return;
    }
    WeldLogger.DEPLOYMENT_LOGGER.startingServicesForCDIDeployment(phaseContext.getDeploymentUnit().getName());
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final Set<BeanDeploymentArchiveImpl> beanDeploymentArchives = new HashSet<BeanDeploymentArchiveImpl>();
    final Map<ModuleIdentifier, BeanDeploymentModule> bdmsByIdentifier = new HashMap<ModuleIdentifier, BeanDeploymentModule>();
    final Map<ModuleIdentifier, ModuleSpecification> moduleSpecByIdentifier = new HashMap<ModuleIdentifier, ModuleSpecification>();
    final Map<ModuleIdentifier, EEModuleDescriptor> eeModuleDescriptors = new HashMap<>();
    // the root module only has access to itself. For most deployments this will be the only module
    // for ear deployments this represents the ear/lib directory.
    // war and jar deployment visibility will depend on the dependencies that
    // exist in the application, and mirror inter module dependencies
    final BeanDeploymentModule rootBeanDeploymentModule = deploymentUnit.getAttachment(WeldAttachments.BEAN_DEPLOYMENT_MODULE);
    putIfValueNotNull(eeModuleDescriptors, module.getIdentifier(), rootBeanDeploymentModule.getModuleDescriptor());
    bdmsByIdentifier.put(module.getIdentifier(), rootBeanDeploymentModule);
    moduleSpecByIdentifier.put(module.getIdentifier(), moduleSpecification);
    beanDeploymentArchives.addAll(rootBeanDeploymentModule.getBeanDeploymentArchives());
    final List<DeploymentUnit> subDeployments = deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS);
    final Set<ClassLoader> subDeploymentLoaders = new HashSet<ClassLoader>();
    final ServiceLoader<DeploymentUnitDependenciesProvider> dependenciesProviders = ServiceLoader.load(DeploymentUnitDependenciesProvider.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldDeploymentProcessor.class));
    final ServiceLoader<ModuleServicesProvider> moduleServicesProviders = ServiceLoader.load(ModuleServicesProvider.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldDeploymentProcessor.class));
    getDependencies(deploymentUnit, dependencies, dependenciesProviders);
    for (DeploymentUnit subDeployment : subDeployments) {
        getDependencies(subDeployment, dependencies, dependenciesProviders);
        final Module subDeploymentModule = subDeployment.getAttachment(Attachments.MODULE);
        if (subDeploymentModule == null) {
            continue;
        }
        subDeploymentLoaders.add(subDeploymentModule.getClassLoader());
        final ModuleSpecification subDeploymentModuleSpec = subDeployment.getAttachment(Attachments.MODULE_SPECIFICATION);
        final BeanDeploymentModule bdm = subDeployment.getAttachment(WeldAttachments.BEAN_DEPLOYMENT_MODULE);
        if (bdm == null) {
            continue;
        }
        // add the modules bdas to the global set of bdas
        beanDeploymentArchives.addAll(bdm.getBeanDeploymentArchives());
        bdmsByIdentifier.put(subDeploymentModule.getIdentifier(), bdm);
        moduleSpecByIdentifier.put(subDeploymentModule.getIdentifier(), subDeploymentModuleSpec);
        putIfValueNotNull(eeModuleDescriptors, subDeploymentModule.getIdentifier(), bdm.getModuleDescriptor());
        // we have to do this here as the aggregate components are not available in earlier phases
        final ResourceRoot subDeploymentRoot = subDeployment.getAttachment(Attachments.DEPLOYMENT_ROOT);
        // Add module services to bean deployment module
        for (Entry<Class<? extends Service>, Service> entry : ServiceLoaders.loadModuleServices(moduleServicesProviders, deploymentUnit, subDeployment, subDeploymentModule, subDeploymentRoot).entrySet()) {
            bdm.addService(entry.getKey(), Reflections.cast(entry.getValue()));
        }
    }
    for (Map.Entry<ModuleIdentifier, BeanDeploymentModule> entry : bdmsByIdentifier.entrySet()) {
        final ModuleSpecification bdmSpec = moduleSpecByIdentifier.get(entry.getKey());
        final BeanDeploymentModule bdm = entry.getValue();
        if (bdm == rootBeanDeploymentModule) {
            // the root module only has access to itself
            continue;
        }
        for (ModuleDependency dependency : bdmSpec.getSystemDependencies()) {
            BeanDeploymentModule other = bdmsByIdentifier.get(dependency.getIdentifier());
            if (other != null && other != bdm) {
                bdm.addBeanDeploymentModule(other);
            }
        }
    }
    Map<Class<? extends Service>, Service> rootModuleServices = ServiceLoaders.loadModuleServices(moduleServicesProviders, deploymentUnit, deploymentUnit, module, deploymentRoot);
    // Add root module services to root bean deployment module
    for (Entry<Class<? extends Service>, Service> entry : rootModuleServices.entrySet()) {
        rootBeanDeploymentModule.addService(entry.getKey(), Reflections.cast(entry.getValue()));
    }
    // Add root module services to additional bean deployment archives
    for (final BeanDeploymentArchiveImpl additional : deploymentUnit.getAttachmentList(WeldAttachments.ADDITIONAL_BEAN_DEPLOYMENT_MODULES)) {
        beanDeploymentArchives.add(additional);
        for (Entry<Class<? extends Service>, Service> entry : rootModuleServices.entrySet()) {
            additional.getServices().add(entry.getKey(), Reflections.cast(entry.getValue()));
        }
    }
    final Collection<Metadata<Extension>> extensions = WeldPortableExtensions.getPortableExtensions(deploymentUnit).getExtensions();
    final WeldDeployment deployment = new WeldDeployment(beanDeploymentArchives, extensions, module, subDeploymentLoaders, deploymentUnit, rootBeanDeploymentModule, eeModuleDescriptors);
    installBootstrapConfigurationService(deployment, parent);
    // add the weld service
    final ServiceBuilder<?> weldBootstrapServiceBuilder = serviceTarget.addService(weldBootstrapServiceInternalName);
    final Consumer<WeldBootstrapService> weldBootstrapServiceConsumer = weldBootstrapServiceBuilder.provides(weldBootstrapServiceInternalName);
    weldBootstrapServiceBuilder.requires(TCCLSingletonService.SERVICE_NAME);
    final Supplier<ExecutorServices> executorServicesSupplier = weldBootstrapServiceBuilder.requires(WeldExecutorServices.SERVICE_NAME);
    final Supplier<ExecutorService> serverExecutorSupplier = weldBootstrapServiceBuilder.requires(Services.JBOSS_SERVER_EXECUTOR);
    Supplier<SecurityServices> securityServicesSupplier = null;
    Supplier<TransactionServices> weldTransactionServicesSupplier = null;
    // Install additional services
    final ServiceLoader<BootstrapDependencyInstaller> installers = ServiceLoader.load(BootstrapDependencyInstaller.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldDeploymentProcessor.class));
    for (BootstrapDependencyInstaller installer : installers) {
        ServiceName serviceName = installer.install(serviceTarget, deploymentUnit, jtsEnabled);
        // Add dependency for recognized services
        if (ServiceNames.WELD_SECURITY_SERVICES_SERVICE_NAME.getSimpleName().equals(serviceName.getSimpleName())) {
            securityServicesSupplier = weldBootstrapServiceBuilder.requires(serviceName);
        } else if (ServiceNames.WELD_TRANSACTION_SERVICES_SERVICE_NAME.getSimpleName().equals(serviceName.getSimpleName())) {
            weldTransactionServicesSupplier = weldBootstrapServiceBuilder.requires(serviceName);
        }
    }
    ServiceName deploymentServiceName = Utils.getRootDeploymentUnit(deploymentUnit).getServiceName();
    final WeldBootstrapService weldBootstrapService = new WeldBootstrapService(deployment, WildFlyWeldEnvironment.INSTANCE, deploymentUnit.getName(), weldBootstrapServiceConsumer, executorServicesSupplier, serverExecutorSupplier, securityServicesSupplier, weldTransactionServicesSupplier, deploymentServiceName, weldBootstrapServiceName);
    // Add root module services to WeldDeployment
    for (Entry<Class<? extends Service>, Service> entry : rootModuleServices.entrySet()) {
        weldBootstrapService.addWeldService(entry.getKey(), Reflections.cast(entry.getValue()));
    }
    weldBootstrapServiceBuilder.setInstance(weldBootstrapService);
    weldBootstrapServiceBuilder.install();
    final List<SetupAction> setupActions = getSetupActions(deploymentUnit);
    ServiceBuilder<?> startService = serviceTarget.addService(weldStartServiceName);
    for (final ServiceName dependency : dependencies) {
        startService.requires(dependency);
    }
    // make sure JNDI bindings are up
    startService.requires(JndiNamingDependencyProcessor.serviceName(deploymentUnit));
    final CapabilityServiceSupport capabilities = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
    boolean tx = capabilities.hasCapability("org.wildfly.transactions");
    // [WFLY-5232]
    for (final ServiceName jndiSubsystemDependency : getJNDISubsytemDependencies(tx)) {
        startService.requires(jndiSubsystemDependency);
    }
    final EarMetaData earConfig = deploymentUnit.getAttachment(org.jboss.as.ee.structure.Attachments.EAR_METADATA);
    if (earConfig == null || !earConfig.getInitializeInOrder()) {
        // in-order install of sub-deployments may result in service dependencies deadlocks if the jndi dependency services of subdeployments are added as dependencies
        for (DeploymentUnit sub : subDeployments) {
            startService.requires(JndiNamingDependencyProcessor.serviceName(sub));
        }
    }
    final Supplier<WeldBootstrapService> bootstrapSupplier = startService.requires(weldBootstrapServiceName);
    startService.setInstance(new WeldStartService(bootstrapSupplier, setupActions, module.getClassLoader(), deploymentServiceName));
    startService.install();
}
Also used : ModuleDependency(org.jboss.as.server.deployment.module.ModuleDependency) HashMap(java.util.HashMap) WeldDeployment(org.jboss.as.weld.deployment.WeldDeployment) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) WeldStartService(org.jboss.as.weld.WeldStartService) WeldBootstrapService(org.jboss.as.weld.WeldBootstrapService) HashSet(java.util.HashSet) ModuleServicesProvider(org.jboss.as.weld.spi.ModuleServicesProvider) ServiceTarget(org.jboss.msc.service.ServiceTarget) SetupAction(org.jboss.as.server.deployment.SetupAction) ConcurrentContextSetupAction(org.jboss.as.ee.concurrent.ConcurrentContextSetupAction) ServiceName(org.jboss.msc.service.ServiceName) Module(org.jboss.modules.Module) BeanDeploymentModule(org.jboss.as.weld.deployment.BeanDeploymentModule) Map(java.util.Map) HashMap(java.util.HashMap) EEModuleDescriptor(org.jboss.weld.bootstrap.spi.EEModuleDescriptor) SecurityServices(org.jboss.weld.security.spi.SecurityServices) Metadata(org.jboss.weld.bootstrap.spi.Metadata) DeploymentUnitDependenciesProvider(org.jboss.as.weld.spi.DeploymentUnitDependenciesProvider) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) BootstrapDependencyInstaller(org.jboss.as.weld.spi.BootstrapDependencyInstaller) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) BeanDeploymentArchiveImpl(org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl) TCCLSingletonService(org.jboss.as.weld.services.TCCLSingletonService) DefaultNamespaceContextSelectorService(org.jboss.as.naming.service.DefaultNamespaceContextSelectorService) Service(org.jboss.weld.bootstrap.api.Service) WeldBootstrapService(org.jboss.as.weld.WeldBootstrapService) NamingService(org.jboss.as.naming.service.NamingService) WeldStartService(org.jboss.as.weld.WeldStartService) ExecutorService(java.util.concurrent.ExecutorService) TransactionServices(org.jboss.weld.transaction.spi.TransactionServices) ModuleSpecification(org.jboss.as.server.deployment.module.ModuleSpecification) ExecutorServices(org.jboss.weld.manager.api.ExecutorServices) WeldExecutorServices(org.jboss.as.weld.services.bootstrap.WeldExecutorServices) ExecutorService(java.util.concurrent.ExecutorService) BeanDeploymentModule(org.jboss.as.weld.deployment.BeanDeploymentModule) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 4 with WeldBootstrapService

use of org.jboss.as.weld.WeldBootstrapService in project wildfly by wildfly.

the class WeldDeploymentCleanupProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final DeploymentUnit parent = Utils.getRootDeploymentUnit(deploymentUnit);
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    // obtain service names
    ServiceName weldStartCompletionServiceName = parent.getServiceName().append(WeldStartCompletionService.SERVICE_NAME);
    ServiceName weldBootstrapServiceName = parent.getServiceName().append(WeldBootstrapService.SERVICE_NAME);
    ServiceName weldStartServiceName = parent.getServiceName().append(WeldStartService.SERVICE_NAME);
    // if it is not Weld deployment, we skip it
    if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
        return;
    }
    // only register this on top level deployments
    if (deploymentUnit.getParent() != null) {
        return;
    }
    // add dependency on our WeldBootstrapService and WeldStartService to ensure this goes after them
    ServiceBuilder<?> weldStartCompletionServiceBuilder = serviceTarget.addService(weldStartCompletionServiceName);
    final Supplier<WeldBootstrapService> bootstrapSupplier = weldStartCompletionServiceBuilder.requires(weldBootstrapServiceName);
    weldStartCompletionServiceBuilder.requires(weldStartServiceName);
    // require component start services from top level deployment
    for (ServiceName componentStartSN : getComponentStartServiceNames(deploymentUnit)) {
        weldStartCompletionServiceBuilder.requires(componentStartSN);
    }
    // require component start services from sub-deployments
    final List<DeploymentUnit> subDeployments = deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS);
    for (DeploymentUnit sub : subDeployments) {
        ServiceRegistry registry = sub.getServiceRegistry();
        List<ServiceName> componentStartServiceNames = getComponentStartServiceNames(sub);
        for (ServiceName componentStartSN : componentStartServiceNames) {
            weldStartCompletionServiceBuilder.requires(componentStartSN);
        }
    }
    weldStartCompletionServiceBuilder.setInstance(new WeldStartCompletionService(bootstrapSupplier, WeldDeploymentProcessor.getSetupActions(deploymentUnit), module.getClassLoader()));
    weldStartCompletionServiceBuilder.install();
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) WeldStartCompletionService(org.jboss.as.weld.WeldStartCompletionService) ServiceTarget(org.jboss.msc.service.ServiceTarget) WeldBootstrapService(org.jboss.as.weld.WeldBootstrapService) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 5 with WeldBootstrapService

use of org.jboss.as.weld.WeldBootstrapService in project wildfly by wildfly.

the class WeldComponentIntegrationProcessor method addJsr299BindingsCreateInterceptor.

private static void addJsr299BindingsCreateInterceptor(final ComponentConfiguration configuration, final ComponentDescription description, final String beanName, final ServiceName weldServiceName, ServiceBuilder<?> builder, final ServiceName bindingServiceName, final ComponentInterceptorSupport componentInterceptorSupport) {
    // add the create interceptor that creates the Jakarta Contexts and Dependency Injection Interceptors
    final Supplier<WeldBootstrapService> weldContainerSupplier = builder.requires(weldServiceName);
    final Supplier<InterceptorBindings> interceptorBindingsSupplier = builder.requires(bindingServiceName);
    final Jsr299BindingsCreateInterceptor createInterceptor = new Jsr299BindingsCreateInterceptor(weldContainerSupplier, interceptorBindingsSupplier, description.getBeanDeploymentArchiveId(), beanName, componentInterceptorSupport);
    configuration.addPostConstructInterceptor(new ImmediateInterceptorFactory(createInterceptor), InterceptorOrder.ComponentPostConstruct.CREATE_CDI_INTERCEPTORS);
}
Also used : InterceptorBindings(org.jboss.weld.ejb.spi.InterceptorBindings) Jsr299BindingsCreateInterceptor(org.jboss.as.weld.interceptors.Jsr299BindingsCreateInterceptor) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) WeldBootstrapService(org.jboss.as.weld.WeldBootstrapService)

Aggregations

WeldBootstrapService (org.jboss.as.weld.WeldBootstrapService)6 ServiceName (org.jboss.msc.service.ServiceName)5 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)4 ServiceTarget (org.jboss.msc.service.ServiceTarget)4 Module (org.jboss.modules.Module)3 InterceptorBindings (org.jboss.weld.ejb.spi.InterceptorBindings)3 HashSet (java.util.HashSet)2 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)2 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)2 SetupAction (org.jboss.as.server.deployment.SetupAction)2 WeldStartService (org.jboss.as.weld.WeldStartService)2 WeldInterceptorBindingsService (org.jboss.as.weld.ejb.WeldInterceptorBindingsService)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ServiceLoader (java.util.ServiceLoader)1 Set (java.util.Set)1 ExecutorService (java.util.concurrent.ExecutorService)1 Consumer (java.util.function.Consumer)1 Supplier (java.util.function.Supplier)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1