Search in sources :

Example 16 with ComponentConfiguration

use of org.jboss.as.ee.component.ComponentConfiguration 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 17 with ComponentConfiguration

use of org.jboss.as.ee.component.ComponentConfiguration in project wildfly by wildfly.

the class ComponentInstallProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(MODULE);
    final EEModuleConfiguration moduleConfiguration = deploymentUnit.getAttachment(EE_MODULE_CONFIGURATION);
    if (module == null || moduleConfiguration == null) {
        return;
    }
    ComponentRegistry componentRegistry = deploymentUnit.getAttachment(COMPONENT_REGISTRY);
    final List<ServiceName> dependencies = deploymentUnit.getAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES);
    final ServiceName bindingDependencyService = JndiNamingDependencyProcessor.serviceName(deploymentUnit.getServiceName());
    // Iterate through each component, installing it into the container
    for (final ComponentConfiguration configuration : moduleConfiguration.getComponentConfigurations()) {
        try {
            ROOT_LOGGER.tracef("Installing component %s", configuration.getComponentClass().getName());
            deployComponent(phaseContext, configuration, dependencies, bindingDependencyService);
            componentRegistry.addComponent(configuration);
            //we need to make sure that the web deployment has a dependency on all components it the app, so web components are started
            //when the web subsystem is starting
            //we only add a dependency on components in the same sub deployment, otherwise we get circular dependencies when initialize-in-order is used
            deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.WEB_DEPENDENCIES, configuration.getComponentDescription().getStartServiceName());
        } catch (Exception e) {
            throw EeLogger.ROOT_LOGGER.failedToInstallComponent(e, configuration.getComponentName());
        }
    }
}
Also used : ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ComponentRegistry(org.jboss.as.ee.component.ComponentRegistry) ServiceName(org.jboss.msc.service.ServiceName) EEModuleConfiguration(org.jboss.as.ee.component.EEModuleConfiguration) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) CircularDependencyException(org.jboss.msc.service.CircularDependencyException) DuplicateServiceException(org.jboss.msc.service.DuplicateServiceException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException)

Example 18 with ComponentConfiguration

use of org.jboss.as.ee.component.ComponentConfiguration 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 19 with ComponentConfiguration

use of org.jboss.as.ee.component.ComponentConfiguration 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 20 with ComponentConfiguration

use of org.jboss.as.ee.component.ComponentConfiguration 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)

Aggregations

ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)37 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)28 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)26 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)19 ViewConfiguration (org.jboss.as.ee.component.ViewConfiguration)19 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)16 ViewConfigurator (org.jboss.as.ee.component.ViewConfigurator)15 ViewDescription (org.jboss.as.ee.component.ViewDescription)15 ImmediateInterceptorFactory (org.jboss.invocation.ImmediateInterceptorFactory)14 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)13 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)11 Method (java.lang.reflect.Method)10 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)9 ServiceName (org.jboss.msc.service.ServiceName)8 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)7 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)6 EEModuleConfiguration (org.jboss.as.ee.component.EEModuleConfiguration)6 SessionBeanComponentDescription (org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)6 Module (org.jboss.modules.Module)6 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)6