Search in sources :

Example 11 with DeploymentPhaseContext

use of org.jboss.as.server.deployment.DeploymentPhaseContext in project wildfly by wildfly.

the class StatefulComponentDescription method createConfiguration.

@Override
public ComponentConfiguration createConfiguration(final ClassReflectionIndex classIndex, final ClassLoader moduleClassLoader, final ModuleLoader moduleLoader) {
    final ComponentConfiguration statefulComponentConfiguration = new ComponentConfiguration(this, classIndex, moduleClassLoader, moduleLoader);
    // setup the component create service
    statefulComponentConfiguration.setComponentCreateServiceFactory(new StatefulComponentCreateServiceFactory());
    if (getTransactionManagementType() == TransactionManagementType.BEAN) {
        getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                final ComponentInstanceInterceptorFactory bmtComponentInterceptorFactory = new ComponentInstanceInterceptorFactory() {

                    @Override
                    protected Interceptor create(Component component, InterceptorFactoryContext context) {
                        if (!(component instanceof StatefulSessionComponent)) {
                            throw EjbLogger.ROOT_LOGGER.componentNotInstanceOfSessionComponent(component, component.getComponentClass(), "stateful");
                        }
                        return new StatefulBMTInterceptor((StatefulSessionComponent) component);
                    }
                };
                configuration.addComponentInterceptor(bmtComponentInterceptorFactory, InterceptorOrder.Component.BMT_TRANSACTION_INTERCEPTOR, false);
            }
        });
    } else {
        getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                final EEApplicationClasses applicationClasses = context.getDeploymentUnit().getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
                InterceptorClassDescription interceptorConfig = ComponentDescription.mergeInterceptorConfig(configuration.getComponentClass(), applicationClasses.getClassByName(description.getComponentClassName()), description, MetadataCompleteMarker.isMetadataComplete(context.getDeploymentUnit()));
                configuration.addPostConstructInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPostConstruct(), false), InterceptorOrder.ComponentPostConstruct.TRANSACTION_INTERCEPTOR);
                configuration.addPreDestroyInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPreDestroy(), false), InterceptorOrder.ComponentPreDestroy.TRANSACTION_INTERCEPTOR);
                if (description.isPassivationApplicable()) {
                    configuration.addPrePassivateInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPrePassivate(), false), InterceptorOrder.ComponentPassivation.TRANSACTION_INTERCEPTOR);
                    configuration.addPostActivateInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPostActivate(), false), InterceptorOrder.ComponentPassivation.TRANSACTION_INTERCEPTOR);
                }
            }
        });
    }
    addStatefulSessionSynchronizationInterceptor();
    return statefulComponentConfiguration;
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ComponentInstanceInterceptorFactory(org.jboss.as.ee.component.ComponentInstanceInterceptorFactory) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) ComponentTypeIdentityInterceptorFactory(org.jboss.as.ejb3.component.interceptors.ComponentTypeIdentityInterceptorFactory) InterceptorFactory(org.jboss.invocation.InterceptorFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) ComponentInstanceInterceptorFactory(org.jboss.as.ee.component.ComponentInstanceInterceptorFactory) StatefulBMTInterceptor(org.jboss.as.ejb3.tx.StatefulBMTInterceptor) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) InterceptorFactoryContext(org.jboss.invocation.InterceptorFactoryContext) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) Component(org.jboss.as.ee.component.Component) Interceptor(org.jboss.invocation.Interceptor) LifecycleCMTTxInterceptor(org.jboss.as.ejb3.tx.LifecycleCMTTxInterceptor) StatefulBMTInterceptor(org.jboss.as.ejb3.tx.StatefulBMTInterceptor)

Example 12 with DeploymentPhaseContext

use of org.jboss.as.server.deployment.DeploymentPhaseContext in project wildfly by wildfly.

the class AsynchronousMergingProcessor method handleDeploymentDescriptor.

@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription description) throws DeploymentUnitProcessingException {
    final SessionBeanMetaData data = description.getDescriptorData();
    final boolean isSecurityDomainKnown = description.isSecurityDomainKnown();
    if (data != null) {
        if (data instanceof SessionBean31MetaData) {
            final SessionBean31MetaData sessionBeanData = (SessionBean31MetaData) data;
            final AsyncMethodsMetaData async = sessionBeanData.getAsyncMethods();
            if (async != null) {
                for (AsyncMethodMetaData method : async) {
                    final Collection<Method> methods = MethodResolutionUtils.resolveMethods(method.getMethodName(), method.getMethodParams(), componentClass, deploymentReflectionIndex);
                    for (final Method m : methods) {
                        description.addAsynchronousMethod(MethodIdentifier.getIdentifierForMethod(m));
                    }
                }
            }
        }
    }
    if (!description.getAsynchronousClasses().isEmpty() || !description.getAsynchronousMethods().isEmpty()) {
        //setup a dependency on the executor service
        description.getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                configuration.getCreateDependencies().add(new DependencyConfigurator<SessionBeanComponentCreateService>() {

                    @Override
                    public void configureDependency(final ServiceBuilder<?> serviceBuilder, final SessionBeanComponentCreateService service) throws DeploymentUnitProcessingException {
                        serviceBuilder.addDependency(asynchronousThreadPoolService, ExecutorService.class, service.getAsyncExecutorService());
                    }
                });
            }
        });
        for (final ViewDescription view : description.getViews()) {
            final EJBViewDescription ejbView = (EJBViewDescription) view;
            ejbView.getConfigurators().add(new ViewConfigurator() {

                @Override
                public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
                    final SessionBeanComponentDescription componentDescription = (SessionBeanComponentDescription) componentConfiguration.getComponentDescription();
                    for (final Method method : configuration.getProxyFactory().getCachedMethods()) {
                        //we need the component method to get the correct declaring class
                        final Method componentMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndex, componentClass, method);
                        if (componentMethod != null) {
                            if (componentDescription.getAsynchronousClasses().contains(componentMethod.getDeclaringClass().getName())) {
                                addAsyncInterceptor(configuration, method, isSecurityDomainKnown);
                                configuration.addAsyncMethod(method);
                            } else {
                                MethodIdentifier id = MethodIdentifier.getIdentifierForMethod(method);
                                if (componentDescription.getAsynchronousMethods().contains(id)) {
                                    addAsyncInterceptor(configuration, method, isSecurityDomainKnown);
                                    configuration.addAsyncMethod(method);
                                }
                            }
                        }
                    }
                }
            });
        }
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) SessionBeanMetaData(org.jboss.metadata.ejb.spec.SessionBeanMetaData) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) DependencyConfigurator(org.jboss.as.ee.component.DependencyConfigurator) Method(java.lang.reflect.Method) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) SessionBean31MetaData(org.jboss.metadata.ejb.spec.SessionBean31MetaData) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) AsyncMethodsMetaData(org.jboss.metadata.ejb.spec.AsyncMethodsMetaData) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) AsyncMethodMetaData(org.jboss.metadata.ejb.spec.AsyncMethodMetaData) SessionBeanComponentCreateService(org.jboss.as.ejb3.component.session.SessionBeanComponentCreateService) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)

Example 13 with DeploymentPhaseContext

use of org.jboss.as.server.deployment.DeploymentPhaseContext in project wildfly by wildfly.

the class StartupAwaitDeploymentUnitProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    for (ComponentDescription component : moduleDescription.getComponentDescriptions()) {
        if (component instanceof EJBComponentDescription) {
            component.getConfigurators().add(new ComponentConfigurator() {

                @Override
                public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) {
                    StartupCountdown countdown = context.getDeploymentUnit().getAttachment(Attachments.STARTUP_COUNTDOWN);
                    for (ViewConfiguration view : configuration.getViews()) {
                        EJBViewConfiguration ejbView = (EJBViewConfiguration) view;
                        if (INTFS.contains(ejbView.getMethodIntf())) {
                            ejbView.addViewInterceptor(new ImmediateInterceptorFactory(new StartupAwaitInterceptor(countdown)), InterceptorOrder.View.STARTUP_AWAIT_INTERCEPTOR);
                        }
                    }
                }
            });
        }
    }
}
Also used : EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) EJBViewConfiguration(org.jboss.as.ejb3.component.EJBViewConfiguration) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) EJBViewConfiguration(org.jboss.as.ejb3.component.EJBViewConfiguration) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) StartupCountdown(org.jboss.as.ee.component.deployers.StartupCountdown)

Example 14 with DeploymentPhaseContext

use of org.jboss.as.server.deployment.DeploymentPhaseContext in project wildfly by wildfly.

the class SessionBeanMergingProcessor method handleDeploymentDescriptor.

@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription description) throws DeploymentUnitProcessingException {
    if (SessionBean.class.isAssignableFrom(componentClass)) {
        // add the setSessionContext(SessionContext) method invocation interceptor for session bean implementing the javax.ejb.SessionContext
        // interface
        description.getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                if (SessionBean.class.isAssignableFrom(configuration.getComponentClass())) {
                    configuration.addPostConstructInterceptor(SessionBeanSetSessionContextMethodInvocationInterceptor.FACTORY, InterceptorOrder.ComponentPostConstruct.EJB_SET_CONTEXT_METHOD_INVOCATION_INTERCEPTOR);
                }
            }
        });
        //now lifecycle callbacks
        final MethodIdentifier ejbRemoveIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbRemove");
        final MethodIdentifier ejbActivateIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbActivate");
        final MethodIdentifier ejbPassivateIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbPassivate");
        boolean ejbActivate = false, ejbPassivate = false, ejbRemove = false;
        Class<?> c = componentClass;
        while (c != null && c != Object.class) {
            final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(c);
            if (!ejbActivate) {
                final Method method = index.getMethod(ejbActivateIdentifier);
                if (method != null) {
                    final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                    builder.setPostActivate(ejbActivateIdentifier);
                    description.addInterceptorMethodOverride(c.getName(), builder.build());
                    ejbActivate = true;
                }
            }
            if (!ejbPassivate) {
                final Method method = index.getMethod(ejbPassivateIdentifier);
                if (method != null) {
                    final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                    builder.setPrePassivate(ejbPassivateIdentifier);
                    description.addInterceptorMethodOverride(c.getName(), builder.build());
                    ejbPassivate = true;
                }
            }
            if (!ejbRemove) {
                final Method method = index.getMethod(ejbRemoveIdentifier);
                if (method != null) {
                    final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                    builder.setPreDestroy(ejbRemoveIdentifier);
                    description.addInterceptorMethodOverride(c.getName(), builder.build());
                    ejbRemove = true;
                }
            }
            c = c.getSuperclass();
        }
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) Method(java.lang.reflect.Method) SessionBean(javax.ejb.SessionBean) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription)

Example 15 with DeploymentPhaseContext

use of org.jboss.as.server.deployment.DeploymentPhaseContext in project wildfly by wildfly.

the class WeldComponentIntegrationProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!WeldDeploymentMarker.isWeldDeployment(deploymentUnit)) {
        return;
    }
    final DeploymentUnit topLevelDeployment = getRootDeploymentUnit(deploymentUnit);
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final ServiceName weldBootstrapService = topLevelDeployment.getServiceName().append(WeldBootstrapService.SERVICE_NAME);
    final ServiceName weldStartService = topLevelDeployment.getServiceName().append(WeldStartService.SERVICE_NAME);
    final ServiceName beanManagerService = ServiceNames.beanManagerServiceName(deploymentUnit);
    final Iterable<ComponentIntegrator> componentIntegrators = ServiceLoader.load(ComponentIntegrator.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldComponentIntegrationProcessor.class));
    final ComponentInterceptorSupport componentInterceptorSupport = ServiceLoaders.loadSingle(ComponentInterceptorSupport.class, WeldComponentIntegrationProcessor.class).orElse(null);
    WeldClassIntrospector.install(deploymentUnit, phaseContext.getServiceTarget());
    eeModuleDescription.setDefaultClassIntrospectorServiceName(WeldClassIntrospector.serviceName(deploymentUnit));
    for (ComponentDescription component : eeModuleDescription.getComponentDescriptions()) {
        final String beanName;
        if (isBeanNameRequired(component, componentIntegrators)) {
            beanName = component.getComponentName();
        } else {
            beanName = null;
        }
        component.getConfigurators().add((context, description, configuration) -> {
            //add interceptor to activate the request scope if required
            final EjbRequestScopeActivationInterceptor.Factory requestFactory = new EjbRequestScopeActivationInterceptor.Factory(beanManagerService);
            for (ViewConfiguration view : configuration.getViews()) {
                view.addViewInterceptor(requestFactory, InterceptorOrder.View.CDI_REQUEST_SCOPE);
            }
            configuration.addTimeoutViewInterceptor(requestFactory, InterceptorOrder.View.CDI_REQUEST_SCOPE);
        });
        component.getConfigurators().addFirst(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                final Class<?> componentClass = configuration.getComponentClass();
                final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
                final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
                final ModuleClassLoader classLoader = module.getClassLoader();
                //get the interceptors so they can be injected as well
                final Set<Class<?>> interceptorClasses = new HashSet<Class<?>>();
                for (InterceptorDescription interceptorDescription : description.getAllInterceptors()) {
                    try {
                        interceptorClasses.add(ClassLoadingUtils.loadClass(interceptorDescription.getInterceptorClassName(), module));
                    } catch (ClassNotFoundException e) {
                        throw WeldLogger.ROOT_LOGGER.couldNotLoadInterceptorClass(interceptorDescription.getInterceptorClassName(), e);
                    }
                }
                addWeldIntegration(componentIntegrators, componentInterceptorSupport, context.getServiceTarget(), configuration, description, componentClass, beanName, weldBootstrapService, weldStartService, beanManagerService, interceptorClasses, classLoader, description.getBeanDeploymentArchiveId());
            }
        });
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) Set(java.util.Set) HashSet(java.util.HashSet) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) UserInterceptorFactory(org.jboss.as.ee.component.interceptors.UserInterceptorFactory) WeldManagedReferenceFactory(org.jboss.as.weld.injection.WeldManagedReferenceFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) InterceptorDescription(org.jboss.as.ee.component.InterceptorDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ComponentIntegrator(org.jboss.as.weld.spi.ComponentIntegrator) ComponentInterceptorSupport(org.jboss.as.weld.spi.ComponentInterceptorSupport) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ServiceName(org.jboss.msc.service.ServiceName) EjbRequestScopeActivationInterceptor(org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) Utils.getRootDeploymentUnit(org.jboss.as.weld.util.Utils.getRootDeploymentUnit)

Aggregations

DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)29 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)27 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)25 ViewConfiguration (org.jboss.as.ee.component.ViewConfiguration)18 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)15 ViewConfigurator (org.jboss.as.ee.component.ViewConfigurator)15 ViewDescription (org.jboss.as.ee.component.ViewDescription)15 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)14 ImmediateInterceptorFactory (org.jboss.invocation.ImmediateInterceptorFactory)13 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)11 Method (java.lang.reflect.Method)10 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)8 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)8 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)7 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)6 SessionBeanComponentDescription (org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)6 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)5 InterceptorClassDescription (org.jboss.as.ee.component.interceptors.InterceptorClassDescription)5 ClassReflectionIndex (org.jboss.as.server.deployment.reflect.ClassReflectionIndex)5 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)5