Search in sources :

Example 11 with StatefulComponentDescription

use of org.jboss.as.ejb3.component.stateful.StatefulComponentDescription in project wildfly by wildfly.

the class SessionBeanComponentDescriptionFactory method processSessionBeans.

private void processSessionBeans(final DeploymentUnit deploymentUnit, final List<AnnotationInstance> sessionBeanAnnotations, final SessionBeanComponentDescription.SessionBeanType annotatedSessionBeanType) {
    final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit);
    final ServiceName deploymentUnitServiceName = deploymentUnit.getServiceName();
    PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
    // process these session bean annotations and create component descriptions out of it
    for (final AnnotationInstance sessionBeanAnnotation : sessionBeanAnnotations) {
        final AnnotationTarget target = sessionBeanAnnotation.target();
        if (!(target instanceof ClassInfo)) {
            // Let's just WARN and move on. No need to throw an error
            EjbLogger.DEPLOYMENT_LOGGER.warn(EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(sessionBeanAnnotation.name().toString(), target).getMessage());
            continue;
        }
        final ClassInfo sessionBeanClassInfo = (ClassInfo) target;
        // skip if it's not a valid class for session bean
        if (!assertSessionBeanClassValidity(sessionBeanClassInfo)) {
            continue;
        }
        final String ejbName = sessionBeanClassInfo.name().local();
        final AnnotationValue nameValue = sessionBeanAnnotation.value("name");
        final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? ejbName : propertyReplacer.replaceProperties(nameValue.asString());
        final SessionBeanMetaData beanMetaData = getEnterpriseBeanMetaData(deploymentUnit, beanName, SessionBeanMetaData.class);
        final SessionBeanComponentDescription.SessionBeanType sessionBeanType;
        final String beanClassName;
        if (beanMetaData != null) {
            beanClassName = override(sessionBeanClassInfo.name().toString(), beanMetaData.getEjbClass());
            sessionBeanType = override(annotatedSessionBeanType, descriptionOf(((SessionBeanMetaData) beanMetaData).getSessionType()));
        } else {
            beanClassName = sessionBeanClassInfo.name().toString();
            sessionBeanType = annotatedSessionBeanType;
        }
        final SessionBeanComponentDescription sessionBeanDescription;
        switch(sessionBeanType) {
            case STATELESS:
                sessionBeanDescription = new StatelessComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, beanMetaData, defaultSlsbPoolAvailable);
                break;
            case STATEFUL:
                sessionBeanDescription = new StatefulComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, beanMetaData);
                // If passivation is disabled for the SFSB, either via annotation or via DD, then setup the component
                // description appropriately
                final boolean passivationCapableAnnotationValue = sessionBeanAnnotation.value("passivationCapable") == null ? true : sessionBeanAnnotation.value("passivationCapable").asBoolean();
                final Boolean passivationCapableDeploymentDescriptorValue;
                if ((beanMetaData instanceof SessionBean32MetaData)) {
                    passivationCapableDeploymentDescriptorValue = ((SessionBean32MetaData) beanMetaData).isPassivationCapable();
                } else {
                    passivationCapableDeploymentDescriptorValue = null;
                }
                final boolean passivationApplicable = override(passivationCapableDeploymentDescriptorValue, passivationCapableAnnotationValue);
                ((StatefulComponentDescription) sessionBeanDescription).setPassivationApplicable(passivationApplicable);
                break;
            case SINGLETON:
                if (sessionBeanClassInfo.interfaceNames().contains(SESSION_BEAN_INTERFACE)) {
                    EjbLogger.ROOT_LOGGER.singletonCantImplementSessionBean(beanClassName);
                }
                sessionBeanDescription = new SingletonComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, beanMetaData);
                break;
            default:
                throw EjbLogger.ROOT_LOGGER.unknownSessionBeanType(sessionBeanType.name());
        }
        addComponent(deploymentUnit, sessionBeanDescription);
        final AnnotationValue mappedNameValue = sessionBeanAnnotation.value("mappedName");
        if (mappedNameValue != null && !mappedNameValue.asString().isEmpty()) {
            EjbLogger.ROOT_LOGGER.mappedNameNotSupported(mappedNameValue != null ? mappedNameValue.asString() : "", ejbName);
        }
    }
    EjbDeploymentMarker.mark(deploymentUnit);
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) SessionBeanMetaData(org.jboss.metadata.ejb.spec.SessionBeanMetaData) ServiceName(org.jboss.msc.service.ServiceName) StatelessComponentDescription(org.jboss.as.ejb3.component.stateless.StatelessComponentDescription) StatefulComponentDescription(org.jboss.as.ejb3.component.stateful.StatefulComponentDescription) AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.getEjbJarDescription(org.jboss.as.ejb3.deployment.processors.AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.getEjbJarDescription) EjbJarDescription(org.jboss.as.ejb3.deployment.EjbJarDescription) SessionBean32MetaData(org.jboss.metadata.ejb.spec.SessionBean32MetaData) AnnotationValue(org.jboss.jandex.AnnotationValue) PropertyReplacer(org.jboss.metadata.property.PropertyReplacer) SingletonComponentDescription(org.jboss.as.ejb3.component.singleton.SingletonComponentDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 12 with StatefulComponentDescription

use of org.jboss.as.ejb3.component.stateful.StatefulComponentDescription in project wildfly by wildfly.

the class StatefulSessionBeanRuntimeHandler method executeReadAttribute.

@Override
protected void executeReadAttribute(String attributeName, OperationContext context, StatefulSessionComponent component, PathAddress address) {
    final StatefulComponentDescription componentDescription = (StatefulComponentDescription) component.getComponentDescription();
    final ModelNode result = context.getResult();
    if (STATEFUL_TIMEOUT.getName().equals(attributeName)) {
        final StatefulTimeoutInfo statefulTimeout = componentDescription.getStatefulTimeout();
        if (statefulTimeout != null) {
            result.set(statefulTimeout.getValue() + ' ' + statefulTimeout.getTimeUnit().toString());
        }
    } else if (AFTER_BEGIN_METHOD.getName().equals(attributeName)) {
        final Method afterBeginMethod = component.getAfterBeginMethod();
        if (afterBeginMethod != null) {
            result.set(afterBeginMethod.toString());
        }
    } else if (BEFORE_COMPLETION_METHOD.getName().equals(attributeName)) {
        final Method beforeCompletionMethod = component.getBeforeCompletionMethod();
        if (beforeCompletionMethod != null) {
            result.set(beforeCompletionMethod.toString());
        }
    } else if (AFTER_COMPLETION_METHOD.getName().equals(attributeName)) {
        final Method afterCompletionMethod = component.getAfterCompletionMethod();
        if (afterCompletionMethod != null) {
            result.set(afterCompletionMethod.toString());
        }
    } else if (PASSIVATION_CAPABLE.getName().equals(attributeName)) {
        result.set(componentDescription.isPassivationApplicable());
    } else if (REMOVE_METHODS.getName().equals(attributeName)) {
        final Collection<StatefulComponentDescription.StatefulRemoveMethod> removeMethods = componentDescription.getRemoveMethods();
        for (StatefulComponentDescription.StatefulRemoveMethod removeMethod : removeMethods) {
            ModelNode removeMethodNode = result.add();
            final ModelNode beanMethodNode = removeMethodNode.get(BEAN_METHOD.getName());
            final MethodIdentifier methodIdentifier = removeMethod.getMethodIdentifier();
            beanMethodNode.set(methodIdentifier.getReturnType() + ' ' + methodIdentifier.getName() + '(' + String.join(", ", methodIdentifier.getParameterTypes()) + ')');
            final ModelNode retainIfExceptionNode = removeMethodNode.get(RETAIN_IF_EXCEPTION.getName());
            retainIfExceptionNode.set(removeMethod.getRetainIfException());
        }
    } else {
        super.executeReadAttribute(attributeName, context, component, address);
    }
// TODO expose the cache
}
Also used : StatefulComponentDescription(org.jboss.as.ejb3.component.stateful.StatefulComponentDescription) StatefulTimeoutInfo(org.jboss.as.ejb3.component.stateful.StatefulTimeoutInfo) Collection(java.util.Collection) Method(java.lang.reflect.Method) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) ModelNode(org.jboss.dmr.ModelNode)

Example 13 with StatefulComponentDescription

use of org.jboss.as.ejb3.component.stateful.StatefulComponentDescription in project wildfly by wildfly.

the class EjbComponentIntegrator method integrate.

@Override
public boolean integrate(ServiceName beanManagerServiceName, ComponentConfiguration configuration, ComponentDescription description, ServiceBuilder<?> weldComponentServiceBuilder, Supplier<ServiceName> bindingServiceNameSupplier, DefaultInterceptorIntegrationAction integrationAction, ComponentInterceptorSupport interceptorSupport) {
    if (description instanceof EJBComponentDescription) {
        ServiceName bindingServiceName = bindingServiceNameSupplier.get();
        integrationAction.perform(bindingServiceName);
        if (description.isPassivationApplicable()) {
            configuration.addPrePassivateInterceptor(factory(InterceptionType.PRE_PASSIVATE, weldComponentServiceBuilder, bindingServiceName, interceptorSupport), InterceptorOrder.ComponentPassivation.CDI_INTERCEPTORS);
            configuration.addPostActivateInterceptor(factory(InterceptionType.POST_ACTIVATE, weldComponentServiceBuilder, bindingServiceName, interceptorSupport), InterceptorOrder.ComponentPassivation.CDI_INTERCEPTORS);
        }
        if (description instanceof StatefulComponentDescription) {
            // add a context key for weld interceptor replication
            configuration.getInterceptorContextKeys().add(SerializedCdiInterceptorsKey.class);
        }
        return true;
    } else if (description instanceof ManagedBeanComponentDescription) {
        integrationAction.perform(bindingServiceNameSupplier.get());
        return true;
    }
    return false;
}
Also used : ManagedBeanComponentDescription(org.jboss.as.ee.managedbean.component.ManagedBeanComponentDescription) ServiceName(org.jboss.msc.service.ServiceName) StatefulComponentDescription(org.jboss.as.ejb3.component.stateful.StatefulComponentDescription) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription)

Aggregations

StatefulComponentDescription (org.jboss.as.ejb3.component.stateful.StatefulComponentDescription)7 ServiceName (org.jboss.msc.service.ServiceName)5 StatefulTimeoutInfo (org.jboss.as.ejb3.component.stateful.StatefulTimeoutInfo)4 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)3 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)3 CacheInfo (org.jboss.as.ejb3.cache.CacheInfo)3 SessionBeanComponentDescription (org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 Method (java.lang.reflect.Method)2 HashSet (java.util.HashSet)2 Supplier (java.util.function.Supplier)2 CapabilityServiceConfigurator (org.jboss.as.clustering.controller.CapabilityServiceConfigurator)2 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)2 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)2 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)2 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)2 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)2 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)2 SessionID (org.jboss.ejb.client.SessionID)2 MethodIdentifier (org.jboss.invocation.proxy.MethodIdentifier)2