use of org.jboss.as.ejb3.component.session.SessionBeanComponentDescription 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);
}
}
}
}
}
});
}
}
}
use of org.jboss.as.ejb3.component.session.SessionBeanComponentDescription 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, deploymentUnitServiceName, beanMetaData);
break;
case STATEFUL:
sessionBeanDescription = new StatefulComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, 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:
sessionBeanDescription = new SingletonComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, beanMetaData);
break;
default:
throw EjbLogger.ROOT_LOGGER.unknownSessionBeanType(sessionBeanType.name());
}
addComponent(deploymentUnit, sessionBeanDescription);
}
EjbDeploymentMarker.mark(deploymentUnit);
}
use of org.jboss.as.ejb3.component.session.SessionBeanComponentDescription in project wildfly by wildfly.
the class EjbConcurrencyMergingProcessor method handleDeploymentDescriptor.
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
if (componentConfiguration.getDescriptorData() == null) {
return;
}
SessionBeanMetaData sessionBeanMetaData = componentConfiguration.getDescriptorData();
if (sessionBeanMetaData instanceof SessionBean31MetaData) {
SessionBean31MetaData descriptor = (SessionBean31MetaData) sessionBeanMetaData;
//handle lock
if (descriptor.getLockType() != null) {
componentConfiguration.setBeanLevelLockType(componentConfiguration.getEJBClassName(), descriptor.getLockType());
}
//handle access timeout
if (descriptor.getAccessTimeout() != null) {
componentConfiguration.setBeanLevelAccessTimeout(componentConfiguration.getEJBClassName(), new AccessTimeoutDetails(descriptor.getAccessTimeout().getTimeout(), descriptor.getAccessTimeout().getUnit()));
}
final ConcurrentMethodsMetaData methods = descriptor.getConcurrentMethods();
if (methods != null) {
for (final ConcurrentMethodMetaData method : methods) {
final Method realMethod = resolveMethod(deploymentReflectionIndex, componentClass, componentClass, method.getMethod());
final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(realMethod);
if (method.getLockType() != null) {
componentConfiguration.setLockType(method.getLockType(), methodIdentifier);
}
if (method.getAccessTimeout() != null) {
componentConfiguration.setAccessTimeout(new AccessTimeoutDetails(method.getAccessTimeout().getTimeout(), method.getAccessTimeout().getUnit()), methodIdentifier);
}
}
}
}
}
use of org.jboss.as.ejb3.component.session.SessionBeanComponentDescription in project wildfly by wildfly.
the class HomeViewMergingProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
if (eeModuleDescription == null) {
return;
}
final Collection<ComponentDescription> componentConfigurations = eeModuleDescription.getComponentDescriptions();
final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
for (ComponentDescription componentConfiguration : componentConfigurations) {
if (componentConfiguration instanceof SessionBeanComponentDescription) {
try {
processComponentConfig(deploymentUnit, applicationClasses, module, deploymentReflectionIndex, (SessionBeanComponentDescription) componentConfiguration);
} catch (Exception e) {
throw EjbLogger.ROOT_LOGGER.failToMergeData(componentConfiguration.getComponentName(), e);
}
}
}
if (appclient) {
for (ComponentDescription componentDescription : deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
if (componentDescription instanceof SessionBeanComponentDescription) {
try {
processComponentConfig(deploymentUnit, applicationClasses, module, deploymentReflectionIndex, (SessionBeanComponentDescription) componentDescription);
} catch (Exception e) {
throw EjbLogger.ROOT_LOGGER.failToMergeData(componentDescription.getComponentName(), e);
}
}
}
}
}
use of org.jboss.as.ejb3.component.session.SessionBeanComponentDescription 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();
}
}
}
Aggregations