Skip to content

Commit

Permalink
Concurrency management
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Aug 24, 2011
1 parent 1542f0e commit 8bc8b15
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 139 deletions.
Expand Up @@ -297,30 +297,8 @@ public ConcurrencyManagementType getConcurrencyManagementType() {
return this.concurrencyManagementType;
}

/**
* Marks the bean for bean managed concurrency.
*
* @throws IllegalStateException If the bean has already been marked for a different concurrency management type
*/
public void beanManagedConcurrency() {
if (this.concurrencyManagementType != null && this.concurrencyManagementType != ConcurrencyManagementType.BEAN) {
throw new IllegalStateException(this.getEJBName() + " bean has been marked for " + this.concurrencyManagementType + " cannot change it now!");
}
this.concurrencyManagementType = ConcurrencyManagementType.BEAN;
}


/**
* Marks this bean for container managed concurrency.
*
* @throws IllegalStateException If the bean has already been marked for a different concurrency management type
*/
public void containerManagedConcurrency() {
if (this.concurrencyManagementType != null && this.concurrencyManagementType != ConcurrencyManagementType.CONTAINER) {
throw new IllegalStateException(this.getEJBName() + " bean has been marked for " + this.concurrencyManagementType + " cannot change it now!");
}
this.concurrencyManagementType = ConcurrencyManagementType.CONTAINER;

public void setConcurrencyManagementType(final ConcurrencyManagementType concurrencyManagementType) {
this.concurrencyManagementType = concurrencyManagementType;
}

/**
Expand Down

This file was deleted.

@@ -0,0 +1,50 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.annotation;

import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;

import javax.ejb.ConcurrencyManagement;
import javax.ejb.ConcurrencyManagementType;

/**
* Processes the {@link javax.ejb.ConcurrencyManagement} annotation on a session bean
*
* @author Stuart Douglas
*/
public class ConcurrencyManagementAnnotationInformationFactory extends ClassAnnotationInformationFactory<ConcurrencyManagement, ConcurrencyManagementType> {

protected ConcurrencyManagementAnnotationInformationFactory() {
super(ConcurrencyManagement.class, null);
}

@Override
protected ConcurrencyManagementType fromAnnotation(final AnnotationInstance annotationInstance) {
final AnnotationValue value = annotationInstance.value();
if(value == null) {
return ConcurrencyManagementType.CONTAINER;
}
return ConcurrencyManagementType.valueOf(value.asEnum());
}
}
Expand Up @@ -41,6 +41,7 @@ public class EjbAnnotationProcessor extends AbstractEEAnnotationProcessor {
public EjbAnnotationProcessor() {
List<ClassAnnotationInformationFactory> factories = new ArrayList<ClassAnnotationInformationFactory>();
factories.add(new LockAnnotationInformationFactory());
factories.add(new ConcurrencyManagementAnnotationInformationFactory());
factories.add(new AccessTimeoutAnnotationInformationFactory());
factories.add(new TransactionAttributeAnnotationInformationFactory());
factories.add(new TransactionManagementAnnotationInformationFactory());
Expand Down
Expand Up @@ -49,7 +49,6 @@
import org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData;

import javax.ejb.AccessTimeout;
import javax.ejb.ConcurrencyManagementType;
import javax.interceptor.InvocationContext;
import java.lang.annotation.Annotation;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -205,14 +204,6 @@ private void processSingletonBean(SessionBean31MetaData singletonBeanMetaData, S
singletonComponentDescription.initOnStartup();
}

// concurrency management type
ConcurrencyManagementType concurrencyManagementType = singletonBeanMetaData.getConcurrencyManagementType();
if (concurrencyManagementType == ConcurrencyManagementType.BEAN) {
singletonComponentDescription.beanManagedConcurrency();
} else {
singletonComponentDescription.containerManagedConcurrency();
}

// bean level access timeout
// TODO: This should apply to other bean types too (JBoss specific feature) and not just singleton beans
AccessTimeoutMetaData accessTimeoutMetaData = singletonBeanMetaData.getAccessTimeout();
Expand Down
@@ -0,0 +1,76 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;

import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.metadata.ClassAnnotationInformation;
import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.metadata.ejb.spec.SessionBean31MetaData;
import org.jboss.metadata.ejb.spec.SessionBeanMetaData;

import javax.ejb.ConcurrencyManagement;
import javax.ejb.ConcurrencyManagementType;

/**
* @author Stuart Douglas
*/
public class ConcurrencyManagementMergingProcessor extends AbstractMergingProcessor<SessionBeanComponentDescription> {

public ConcurrencyManagementMergingProcessor() {
super(SessionBeanComponentDescription.class);
}

@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
final EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
//we only care about annotations on the bean class itself
if (clazz == null) {
return;
}
ClassAnnotationInformation<ConcurrencyManagement, ConcurrencyManagementType> management = clazz.getAnnotationInformation(ConcurrencyManagement.class);
if (management == null) {
return;
}
if (!management.getClassLevelAnnotations().isEmpty()) {
componentConfiguration.setConcurrencyManagementType(management.getClassLevelAnnotations().get(0));
}
}

@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
if (componentConfiguration.getDescriptorData() == null) {
return;
}
SessionBeanMetaData data = componentConfiguration.getDescriptorData();
if (data instanceof SessionBean31MetaData) {
SessionBean31MetaData descriptor = (SessionBean31MetaData) data;
final ConcurrencyManagementType type = descriptor.getConcurrencyManagementType();
if (type != null) {
componentConfiguration.setConcurrencyManagementType(type);
}
}
}
}
Expand Up @@ -53,29 +53,33 @@ public RemoveMethodMergingProcessor() {

protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final StatefulComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
ClassAnnotationInformation<Remove, Boolean> annotations = clazz.getAnnotationInformation(Remove.class);
if(annotations.getMethodLevelAnnotations().size() > 1) {
throw new DeploymentUnitProcessingException("More than one @Remove method found on class " + componentClass);
} else if(!annotations.getMethodLevelAnnotations().isEmpty()) {
final Map.Entry<MethodIdentifier, List<Boolean>> entry = annotations.getMethodLevelAnnotations().entrySet().iterator().next();
final Boolean retainIfException = entry.getValue().get(0);
componentConfiguration.addRemoveMethod(entry.getKey(), retainIfException);
if (clazz != null) {
ClassAnnotationInformation<Remove, Boolean> annotations = clazz.getAnnotationInformation(Remove.class);
if (annotations != null) {
if (annotations.getMethodLevelAnnotations().size() > 1) {
throw new DeploymentUnitProcessingException("More than one @Remove method found on class " + componentClass);
} else if (!annotations.getMethodLevelAnnotations().isEmpty()) {
final Map.Entry<MethodIdentifier, List<Boolean>> entry = annotations.getMethodLevelAnnotations().entrySet().iterator().next();
final Boolean retainIfException = entry.getValue().get(0);
componentConfiguration.addRemoveMethod(entry.getKey(), retainIfException);
}
}
}

}

protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final StatefulComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
SessionBeanMetaData beanMetaData = componentConfiguration.getDescriptorData();
if(beanMetaData == null) {
if (beanMetaData == null) {
return;
}
if(beanMetaData.getRemoveMethods() == null || beanMetaData.getRemoveMethods().isEmpty()){
if (beanMetaData.getRemoveMethods() == null || beanMetaData.getRemoveMethods().isEmpty()) {
return;
}

final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);

for(final RemoveMethodMetaData removeMethod : beanMetaData.getRemoveMethods()) {
for (final RemoveMethodMetaData removeMethod : beanMetaData.getRemoveMethods()) {
final NamedMethodMetaData methodData = removeMethod.getBeanMethod();
final Method method = MethodResolutionUtils.resolveMethod(methodData, componentClass, reflectionIndex);
componentConfiguration.addRemoveMethod(MethodIdentifier.getIdentifierForMethod(method), removeMethod.isRetainIfException());
Expand Down

0 comments on commit 8bc8b15

Please sign in to comment.