You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by ga...@apache.org on 2010/08/30 22:32:30 UTC
svn commit: r990932 - in /openejb/trunk/openejb3/container:
openejb-core/src/main/java/org/apache/openejb/assembler/classic/
openejb-core/src/main/java/org/apache/openejb/config/
openejb-core/src/test/java/org/apache/openejb/assembler/classic/ openejb-...
Author: gawor
Date: Mon Aug 30 20:32:29 2010
New Revision: 990932
URL: http://svn.apache.org/viewvc?rev=990932&view=rev
Log:
OPENEJB-1346: Improved @AccessTimeout annotation processing
Added:
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/AccessTimeoutTest.java (with props)
Removed:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ConcurrentMethodBuilder.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ConcurrentMethodInfo.java
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanInfo.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodConcurrencyBuilder.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodConcurrencyInfo.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulConcurrencyTest.java
openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ContainerConcurrency.java
openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionBean.java
openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java
openejb/trunk/openejb3/container/openejb-jee/src/test/resources/ejb-jar-timeout.xml
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java?rev=990932&r1=990931&r2=990932&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java Mon Aug 30 20:32:29 2010
@@ -59,8 +59,6 @@ public class EjbJarBuilder {
MethodScheduleBuilder methodScheduleBuilder = new MethodScheduleBuilder();
- ConcurrentMethodBuilder concurrentMethodBuilder = new ConcurrentMethodBuilder();
-
for (EnterpriseBeanInfo ejbInfo : ejbJar.enterpriseBeans) {
try {
EnterpriseBeanBuilder deploymentBuilder = new EnterpriseBeanBuilder(ejbInfo, new ArrayList<String>(), moduleContext, moduleInjections);
@@ -70,8 +68,6 @@ public class EjbJarBuilder {
methodScheduleBuilder.build(deployment, ejbInfo);
- concurrentMethodBuilder.build(deployment, ejbInfo);
-
deployments.put(ejbInfo.ejbDeploymentId, deployment);
// TODO: replace with get() on application context or parent
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java?rev=990932&r1=990931&r2=990932&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java Mon Aug 30 20:32:29 2010
@@ -168,10 +168,6 @@ class EnterpriseBeanBuilder {
deployment.setStatefulTimeout(new Duration(bean.statefulTimeout.time, TimeUnit.valueOf(bean.statefulTimeout.unit)));
}
- if (bean.accessTimeout != null) {
- deployment.setAccessTimeout(new Duration(bean.accessTimeout.time, TimeUnit.valueOf(bean.accessTimeout.unit)));
- }
-
if (bean instanceof StatefulBeanInfo) {
StatefulBeanInfo statefulBeanInfo = (StatefulBeanInfo) bean;
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanInfo.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanInfo.java?rev=990932&r1=990931&r2=990932&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanInfo.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanInfo.java Mon Aug 30 20:32:29 2010
@@ -80,8 +80,7 @@ public abstract class EnterpriseBeanInfo
public boolean loadOnStartup;
public final List<String> dependsOn = new ArrayList<String>() ;
- public TimeoutInfo statefulTimeout;
- public TimeoutInfo accessTimeout;
+ public TimeoutInfo statefulTimeout;
public List<MethodScheduleInfo> methodScheduleInfos = new ArrayList<MethodScheduleInfo>();
- public final List<ConcurrentMethodInfo> concurrentMethodInfos = new ArrayList<ConcurrentMethodInfo>();
+
}
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodConcurrencyBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodConcurrencyBuilder.java?rev=990932&r1=990931&r2=990932&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodConcurrencyBuilder.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodConcurrencyBuilder.java Mon Aug 30 20:32:29 2010
@@ -16,11 +16,13 @@
*/
package org.apache.openejb.assembler.classic;
+import org.apache.openejb.util.Duration;
import org.apache.openejb.util.Logger;
import org.apache.openejb.util.LogCategory;
import org.apache.openejb.DeploymentInfo;
import org.apache.openejb.OpenEJBException;
import org.apache.openejb.core.CoreDeploymentInfo;
+import org.apache.openejb.core.MethodContext;
import javax.ejb.LockType;
import java.util.HashMap;
@@ -28,6 +30,7 @@ import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.concurrent.TimeUnit;
import java.lang.reflect.Method;
/**
@@ -56,16 +59,24 @@ public class MethodConcurrencyBuilder {
for (Map.Entry<Method, MethodAttributeInfo> entry : attributes.entrySet()) {
Method method = entry.getKey();
MethodConcurrencyInfo value = (MethodConcurrencyInfo) entry.getValue();
- log.debug("Concurrency Attribute: " + method + " -- " + MethodInfoUtil.toString(value));
+ log.debug("Concurrency Attribute: " + method + " -- " + MethodInfoUtil.toString(value));
}
}
for (Map.Entry<Method, MethodAttributeInfo> entry : attributes.entrySet()) {
MethodConcurrencyInfo value = (MethodConcurrencyInfo) entry.getValue();
-// logger.info(entry.getKey().toString() +" "+ value.transAttribute);
- String s = value.concurrencyAttribute.toUpperCase();
- deploymentInfo.setMethodConcurrencyAttribute(entry.getKey(), LockType.valueOf(s));
+ MethodContext methodContext = deploymentInfo.getMethodContext(entry.getKey());
+
+ if (value.concurrencyAttribute != null) {
+ String s = value.concurrencyAttribute.toUpperCase();
+ methodContext.setLockType(LockType.valueOf(s));
+ }
+
+ if (value.accessTimeout != null) {
+ Duration accessTimeout = new Duration(value.accessTimeout.time, TimeUnit.valueOf(value.accessTimeout.unit));
+ methodContext.setAccessTimeout(accessTimeout);
+ }
}
}
@@ -88,6 +99,7 @@ public class MethodConcurrencyBuilder {
newInfo.description = oldInfo.description;
newInfo.methods.add(methodInfo);
newInfo.concurrencyAttribute = oldInfo.concurrencyAttribute;
+ newInfo.accessTimeout = oldInfo.accessTimeout;
normalized.add(newInfo);
}
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodConcurrencyInfo.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodConcurrencyInfo.java?rev=990932&r1=990931&r2=990932&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodConcurrencyInfo.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodConcurrencyInfo.java Mon Aug 30 20:32:29 2010
@@ -20,5 +20,6 @@ public class MethodConcurrencyInfo exten
public String description;
public String concurrencyAttribute;
+ public TimeoutInfo accessTimeout;
}
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=990932&r1=990931&r2=990932&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java Mon Aug 30 20:32:29 2010
@@ -1097,39 +1097,6 @@ public class AnnotationDeployer implemen
*/
processSecurityAnnotations(clazz, ejbName, ejbModule, inheritedClassFinder, bean);
- if (bean instanceof SessionBean) {
- SessionBean sessionBean = (SessionBean) bean;
-
- // Merge AccessTimeout value from XML - XML value takes precedence
- if(sessionBean.getAccessTimeout() == null) {
- final AccessTimeout annotation = getInheritableAnnotation(clazz, AccessTimeout.class);
- if(annotation != null) {
- final Timeout timeout = new Timeout();
- timeout.setTimeout(annotation.value());
- timeout.setUnit(annotation.unit());
- sessionBean.setAccessTimeout(timeout);
- }
- }
-
- // Merge StatefulTimeout value from XML - XML value takes precedence
- if(sessionBean.getStatefulTimeout() == null) {
- final StatefulTimeout annotation = getInheritableAnnotation(clazz, StatefulTimeout.class);
- if(annotation != null) {
- final Timeout timeout = new Timeout();
- timeout.setTimeout(annotation.value());
- timeout.setUnit(annotation.unit());
- sessionBean.setStatefulTimeout(timeout);
- }
- }
-
- /*
- * @AccessTimeout
- * @Lock
- */
- processAccessTimeoutAndLock(sessionBean, inheritedClassFinder);
- }
-
-
/*
* @Schedule
* @Schedules
@@ -1337,13 +1304,21 @@ public class AnnotationDeployer implemen
/*
* @Lock
*/
+ LockHandler lockHandler = new LockHandler(assemblyDescriptor, sessionBean);
if (sessionBean.getConcurrencyManagementType() == ConcurrencyManagementType.CONTAINER) {
- processAttributes(new ConcurrencyAttributeHandler(assemblyDescriptor, ejbName), clazz, inheritedClassFinder);
+ processAttributes(lockHandler, clazz, inheritedClassFinder);
} else {
- checkAttributes(new ConcurrencyAttributeHandler(assemblyDescriptor, ejbName), ejbName, ejbModule, classFinder, "invalidConcurrencyAttribute");
+ checkAttributes(lockHandler, ejbName, ejbModule, classFinder, "invalidConcurrencyAttribute");
}
/*
+ * @AccessTimeout
+ */
+ AccessTimeoutHandler accessTimeoutHandler =
+ new AccessTimeoutHandler(assemblyDescriptor, sessionBean, lockHandler.getContainerConcurrency());
+ processAttributes(accessTimeoutHandler, clazz, inheritedClassFinder);
+
+ /*
* @Startup
*/
if (!sessionBean.hasInitOnStartup()) {
@@ -1351,6 +1326,30 @@ public class AnnotationDeployer implemen
sessionBean.setInitOnStartup(startup != null);
}
+ } else if (sessionBean.getSessionType() == SessionType.STATEFUL) {
+ /*
+ * Annotations specific to @Stateful beans
+ */
+
+ /*
+ * @StatefulTimeout
+ */
+ if (sessionBean.getStatefulTimeout() == null) {
+ final StatefulTimeout annotation = getInheritableAnnotation(clazz, StatefulTimeout.class);
+ if(annotation != null) {
+ final Timeout timeout = new Timeout();
+ timeout.setTimeout(annotation.value());
+ timeout.setUnit(annotation.unit());
+ sessionBean.setStatefulTimeout(timeout);
+ }
+ }
+
+ /*
+ * @AccessTimeout
+ */
+ AccessTimeoutHandler accessTimeoutHandler = new AccessTimeoutHandler(assemblyDescriptor, sessionBean);
+ processAttributes(accessTimeoutHandler, clazz, inheritedClassFinder);
+
}
}
}
@@ -2119,64 +2118,6 @@ public class AnnotationDeployer implemen
}
}
}
-
- private ConcurrentMethod findConcurrentMethod(Map<NamedMethod, ConcurrentMethod> methodMap, Method method) {
- // step 1: lookup by method name and parameters
- NamedMethod lookup = new NamedMethod(method);
- ConcurrentMethod concurrentMethod = methodMap.get(lookup);
- if (concurrentMethod == null) {
- // step 2: lookup by method name only
- lookup.setMethodParams(null);
- concurrentMethod = methodMap.get(lookup);
- }
- return concurrentMethod;
- }
-
- private void processAccessTimeoutAndLock(SessionBean bean, ClassFinder classFinder) {
- Map<NamedMethod, ConcurrentMethod> methodMap = new HashMap<NamedMethod, ConcurrentMethod>();
- for (ConcurrentMethod concurrentMethod : bean.getConcurrentMethod()) {
- methodMap.put(concurrentMethod.getMethod(), concurrentMethod);
- }
-
- for (Method method : classFinder.findAnnotatedMethods(AccessTimeout.class)) {
- ConcurrentMethod concurrentMethod = findConcurrentMethod(methodMap, method);
- if (concurrentMethod == null) {
- // create new and add to the list
- concurrentMethod = new ConcurrentMethod();
- concurrentMethod.setMethod(new NamedMethod(method));
- bean.getConcurrentMethod().add(concurrentMethod);
- }
-
- AccessTimeout annotation = method.getAnnotation(AccessTimeout.class);
-
- if (concurrentMethod.getAccessTimeout() == null) {
- Timeout timeout = new Timeout();
- timeout.setTimeout(annotation.value());
- timeout.setUnit(annotation.unit());
- concurrentMethod.setAccessTimeout(timeout);
- }
- }
-
- for (Method method : classFinder.findAnnotatedMethods(Lock.class)) {
- ConcurrentMethod concurrentMethod = findConcurrentMethod(methodMap, method);
- if (concurrentMethod == null) {
- // create new and add to the list
- concurrentMethod = new ConcurrentMethod();
- concurrentMethod.setMethod(new NamedMethod(method));
- bean.getConcurrentMethod().add(concurrentMethod);
- }
-
- Lock annotation = method.getAnnotation(Lock.class);
-
- if (concurrentMethod.getLock() == null) {
- if (LockType.READ.equals(annotation.value())) {
- concurrentMethod.setLock(ConcurrentLockType.READ);
- } else if (LockType.WRITE.equals(annotation.value())) {
- concurrentMethod.setLock(ConcurrentLockType.WRITE);
- }
- }
- }
- }
private void processCallbacks(Lifecycle bean, ClassFinder classFinder) {
/*
@@ -3301,39 +3242,132 @@ public class AnnotationDeployer implemen
}
}
- public static class ConcurrencyAttributeHandler implements AnnotationHandler<javax.ejb.Lock> {
+ private static class ConcurrentMethodHandler {
+
+ protected final AssemblyDescriptor assemblyDescriptor;
+ protected final SessionBean bean;
+ protected final Map<Object, ContainerConcurrency> methods;
+
+ public ConcurrentMethodHandler(AssemblyDescriptor assemblyDescriptor,
+ SessionBean bean,
+ Map<Object, ContainerConcurrency> methods) {
+ this.assemblyDescriptor = assemblyDescriptor;
+ this.bean = bean;
+ this.methods = methods;
+ }
+
+ public Map<String, List<MethodAttribute>> getExistingDeclarations() {
+ Map<String, List<MethodAttribute>> declarations = new HashMap<String, List<MethodAttribute>>();
+ List<ConcurrentMethod> methods = bean.getConcurrentMethod();
+ for (ConcurrentMethod method : methods) {
+ List<MethodAttribute> list = declarations.get(method.getMethod().getMethodName());
+ if (list == null) {
+ list = new ArrayList<MethodAttribute>();
+ declarations.put(method.getMethod().getMethodName(), list);
+ }
+ list.add(new MethodAttribute(null, bean.getEjbName(), method.getMethod()));
+ }
+ return declarations;
+ }
+
+ public ContainerConcurrency getContainerConcurrency(Method method) {
+ ContainerConcurrency concurrency = methods.get(method);
+ if (concurrency == null) {
+ concurrency = new ContainerConcurrency(null, bean.getEjbName(), method);
+ methods.put(method, concurrency);
+ assemblyDescriptor.getContainerConcurrency().add(concurrency);
+ }
+ return concurrency;
+ }
+
+ public ContainerConcurrency getContainerConcurrency(Class clazz) {
+ ContainerConcurrency concurrency = methods.get(clazz);
+ if (concurrency == null) {
+ concurrency = new ContainerConcurrency(null, clazz.getName(), bean.getEjbName(), "*");
+ methods.put(clazz, concurrency);
+ assemblyDescriptor.getContainerConcurrency().add(concurrency);
+ }
+ return concurrency;
+ }
+
+ protected Map<Object, ContainerConcurrency> getContainerConcurrency() {
+ return methods;
+ }
+ }
+
+ public static class LockHandler extends ConcurrentMethodHandler implements AnnotationHandler<Lock> {
+
+ public LockHandler(AssemblyDescriptor assemblyDescriptor,
+ SessionBean bean) {
+ this(assemblyDescriptor, bean, new HashMap<Object, ContainerConcurrency>());
+ }
- private final AssemblyDescriptor assemblyDescriptor;
- private final String ejbName;
+ public LockHandler(AssemblyDescriptor assemblyDescriptor,
+ SessionBean bean,
+ Map<Object, ContainerConcurrency> methods) {
+ super(assemblyDescriptor, bean, methods);
+ }
+
+ public void addClassLevelDeclaration(Lock attribute, Class type) {
+ ContainerConcurrency concurrency = getContainerConcurrency(type);
+ concurrency.setLock(toLock(attribute));
+ }
- public ConcurrencyAttributeHandler(AssemblyDescriptor assemblyDescriptor, String ejbName) {
- this.assemblyDescriptor = assemblyDescriptor;
- this.ejbName = ejbName;
+ public void addMethodLevelDeclaration(Lock attribute, Method method) {
+ ContainerConcurrency concurrency = getContainerConcurrency(method);
+ concurrency.setLock(toLock(attribute));
}
- public Map<String, List<MethodAttribute>> getExistingDeclarations() {
- return assemblyDescriptor.getMethodConcurrencyMap(ejbName);
+ private ConcurrentLockType toLock(Lock annotation) {
+ if (LockType.READ.equals(annotation.value())) {
+ return ConcurrentLockType.READ;
+ } else if (LockType.WRITE.equals(annotation.value())) {
+ return ConcurrentLockType.WRITE;
+ } else {
+ throw new IllegalArgumentException("Unknown lock annotation: " + annotation.value());
+ }
+ }
+
+ public Class<Lock> getAnnotationClass() {
+ return Lock.class;
+ }
+
+ }
+
+ public static class AccessTimeoutHandler extends ConcurrentMethodHandler implements AnnotationHandler<AccessTimeout> {
+
+ public AccessTimeoutHandler(AssemblyDescriptor assemblyDescriptor,
+ SessionBean bean) {
+ this(assemblyDescriptor, bean, new HashMap<Object, ContainerConcurrency>());
}
- //TODO uses non-existent ContainerConcurrency
- public void addClassLevelDeclaration(javax.ejb.Lock attribute, Class type) {
- ContainerConcurrency ctx = new ContainerConcurrency(cast(attribute.value()), type.getName(), ejbName, "*");
- assemblyDescriptor.getContainerConcurrency().add(ctx);
+ public AccessTimeoutHandler(AssemblyDescriptor assemblyDescriptor,
+ SessionBean bean,
+ Map<Object, ContainerConcurrency> methods) {
+ super(assemblyDescriptor, bean, methods);
}
- //TODO uses non-existent ContainerConcurrency
- public void addMethodLevelDeclaration(javax.ejb.Lock attribute, Method method) {
- ContainerConcurrency ctx = new ContainerConcurrency(cast(attribute.value()), ejbName, method);
- assemblyDescriptor.getContainerConcurrency().add(ctx);
+ public void addClassLevelDeclaration(AccessTimeout attribute, Class type) {
+ ContainerConcurrency concurrency = getContainerConcurrency(type);
+ concurrency.setAccessTimeout(toTimeout(attribute));
}
- public Class<javax.ejb.Lock> getAnnotationClass() {
- return javax.ejb.Lock.class;
+ public void addMethodLevelDeclaration(AccessTimeout attribute, Method method) {
+ ContainerConcurrency concurrency = getContainerConcurrency(method);
+ concurrency.setAccessTimeout(toTimeout(attribute));
}
- private ConcurrentLockType cast(javax.ejb.LockType lockType) {
- return ConcurrentLockType.valueOf(lockType.toString());
+ private Timeout toTimeout(AccessTimeout annotation) {
+ Timeout timeout = new Timeout();
+ timeout.setTimeout(annotation.value());
+ timeout.setUnit(annotation.unit());
+ return timeout;
+ }
+
+ public Class<AccessTimeout> getAnnotationClass() {
+ return AccessTimeout.class;
}
+
}
private <A extends Annotation> void checkAttributes(AnnotationHandler<A> handler, String ejbName, EjbModule ejbModule, ClassFinder classFinder, String messageKey) {
@@ -3375,7 +3409,6 @@ public class AnnotationDeployer implemen
}
}
-
List<Method> methods = classFinder.findAnnotatedMethods(annotationClass);
for (Method method : methods) {
A attribute = method.getAnnotation(annotationClass);
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java?rev=990932&r1=990931&r2=990932&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java Mon Aug 30 20:32:29 2010
@@ -26,13 +26,10 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import javax.ejb.LockType;
-
import org.apache.openejb.OpenEJBException;
import org.apache.openejb.assembler.classic.ApplicationExceptionInfo;
import org.apache.openejb.assembler.classic.CallbackInfo;
import org.apache.openejb.assembler.classic.CmrFieldInfo;
-import org.apache.openejb.assembler.classic.ConcurrentMethodInfo;
import org.apache.openejb.assembler.classic.EjbJarInfo;
import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
import org.apache.openejb.assembler.classic.EntityBeanInfo;
@@ -64,7 +61,6 @@ import org.apache.openejb.jee.CallbackMe
import org.apache.openejb.jee.CmpField;
import org.apache.openejb.jee.CmpVersion;
import org.apache.openejb.jee.ConcurrencyManagementType;
-import org.apache.openejb.jee.ConcurrentLockType;
import org.apache.openejb.jee.ConcurrentMethod;
import org.apache.openejb.jee.ContainerConcurrency;
import org.apache.openejb.jee.ContainerTransaction;
@@ -152,7 +148,7 @@ public class EjbJarInfoBuilder {
for (EnterpriseBean bean : jar.getEjbJar().getEnterpriseBeans()) {
EnterpriseBeanInfo beanInfo;
if (bean instanceof org.apache.openejb.jee.SessionBean) {
- beanInfo = initSessionBean((SessionBean) bean, ejbds);
+ beanInfo = initSessionBean((SessionBean) bean, ejbJar, ejbds);
} else if (bean instanceof org.apache.openejb.jee.EntityBean) {
beanInfo = initEntityBean((EntityBean) bean, ejbds);
} else if (bean instanceof org.apache.openejb.jee.MessageDrivenBean) {
@@ -325,7 +321,6 @@ public class EjbJarInfoBuilder {
}
private void initMethodTransactions(EjbModule jar, Map ejbds, EjbJarInfo ejbJarInfo) {
-
List<ContainerTransaction> containerTransactions = jar.getEjbJar().getAssemblyDescriptor().getContainerTransaction();
for (ContainerTransaction cTx : containerTransactions) {
MethodTransactionInfo info = new MethodTransactionInfo();
@@ -338,14 +333,33 @@ public class EjbJarInfoBuilder {
}
private void initMethodConcurrency(EjbModule jar, Map ejbds, EjbJarInfo ejbJarInfo) {
-
List<ContainerConcurrency> containerConcurrency = jar.getEjbJar().getAssemblyDescriptor().getContainerConcurrency();
for (ContainerConcurrency att : containerConcurrency) {
MethodConcurrencyInfo info = new MethodConcurrencyInfo();
info.description = att.getDescription();
- info.concurrencyAttribute = att.getLock().toString();
- info.methods.addAll(getMethodInfos(att.getMethod(), ejbds));
+ if (att.getLock() != null) {
+ info.concurrencyAttribute = att.getLock().toString();
+ }
+ info.accessTimeout = toInfo(att.getAccessTimeout());
+
+ info.methods.addAll(getMethodInfos(att.getMethod(), ejbds));
+ ejbJarInfo.methodConcurrency.add(info);
+ }
+ }
+
+ private void copyConcurrentMethods(SessionBean bean, EjbJarInfo ejbJarInfo, Map ejbds) {
+ for (ConcurrentMethod method : bean.getConcurrentMethod()) {
+ MethodConcurrencyInfo info = new MethodConcurrencyInfo();
+
+ if (method.getLock() != null) {
+ info.concurrencyAttribute = method.getLock().toString();
+ }
+ info.accessTimeout = toInfo(method.getAccessTimeout());
+
+ Method m = new Method(bean.getEjbName(), null, method.getMethod().getMethodName());
+ m.setMethodParams(method.getMethod().getMethodParams());
+ info.methods.add(getMethodInfo(m, ejbds));
ejbJarInfo.methodConcurrency.add(info);
}
}
@@ -504,7 +518,7 @@ public class EjbJarInfoBuilder {
return methodInfo;
}
- private EnterpriseBeanInfo initSessionBean(SessionBean s, Map m) throws OpenEJBException {
+ private EnterpriseBeanInfo initSessionBean(SessionBean s, EjbJarInfo ejbJar, Map m) throws OpenEJBException {
EnterpriseBeanInfo bean = null;
if (s.getSessionType() == SessionType.STATEFUL) {
@@ -532,7 +546,7 @@ public class EjbJarInfoBuilder {
stateful.removeMethods.add(remove);
}
- copyConcurrentMethods(s.getConcurrentMethod(), bean.concurrentMethodInfos);
+ copyConcurrentMethods(s, ejbJar, m);
} else if (s.getSessionType() == SessionType.MANAGED) {
bean = new ManagedBeanInfo();
@@ -559,7 +573,7 @@ public class EjbJarInfoBuilder {
// See JndiEncInfoBuilder.buildDependsOnRefs for processing of DependsOn
// bean.dependsOn.addAll(s.getDependsOn());
- copyConcurrentMethods(s.getConcurrentMethod(), bean.concurrentMethodInfos);
+ copyConcurrentMethods(s, ejbJar, m);
} else {
bean = new StatelessBeanInfo();
copySchedules(s.getTimer(), bean.methodScheduleInfos);
@@ -606,7 +620,6 @@ public class EjbJarInfoBuilder {
bean.properties.putAll(d.getProperties());
bean.statefulTimeout = toInfo(s.getStatefulTimeout());
- bean.accessTimeout = toInfo(s.getAccessTimeout());
return bean;
}
@@ -790,15 +803,4 @@ public class EjbJarInfoBuilder {
return bean;
}
- private void copyConcurrentMethods(List<ConcurrentMethod> from, List<ConcurrentMethodInfo> to) {
- for (ConcurrentMethod method : from) {
- ConcurrentMethodInfo methodInfo = new ConcurrentMethodInfo();
- methodInfo.accessTimeout = toInfo(method.getAccessTimeout());
- methodInfo.method = toInfo(method.getMethod());
- if (method.getLock() != null) {
- methodInfo.lockType = method.getLock().value().toUpperCase();
- }
- to.add(methodInfo);
- }
- }
}
Added: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/AccessTimeoutTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/AccessTimeoutTest.java?rev=990932&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/AccessTimeoutTest.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/AccessTimeoutTest.java Mon Aug 30 20:32:29 2010
@@ -0,0 +1,212 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.assembler.classic;
+
+import junit.framework.TestCase;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.core.CoreDeploymentInfo;
+import org.apache.openejb.jee.ConcurrentLockType;
+import org.apache.openejb.jee.ContainerConcurrency;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.SingletonBean;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+
+import javax.ejb.AccessTimeout;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import static javax.ejb.LockType.READ;
+import static javax.ejb.LockType.WRITE;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AccessTimeoutTest extends TestCase {
+ private Map<Method, MethodAttributeInfo> attributes;
+
+ public void test() throws Exception {
+ Assembler assembler = new Assembler();
+ ConfigurationFactory config = new ConfigurationFactory();
+
+ assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
+ assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+ assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+
+ EjbJar ejbJar = new EjbJar();
+ ejbJar.addEnterpriseBean(new SingletonBean(Color.class));
+ ejbJar.addEnterpriseBean(new SingletonBean(Red.class));
+ ejbJar.addEnterpriseBean(new SingletonBean(Crimson.class));
+ ejbJar.addEnterpriseBean(new SingletonBean(Scarlet.class));
+
+ EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
+ assembler.createApplication(ejbJarInfo);
+
+ loadAttributes(ejbJarInfo, "Color");
+
+ assertAttribute(2, TimeUnit.SECONDS, Color.class.getMethod("color"));
+ assertAttribute(3, TimeUnit.SECONDS, Color.class.getMethod("color", Object.class));
+ assertAttribute(1, TimeUnit.SECONDS, Color.class.getMethod("color", String.class));
+ assertAttribute(1, TimeUnit.SECONDS, Color.class.getMethod("color", Boolean.class));
+ assertAttribute(1, TimeUnit.SECONDS, Color.class.getMethod("color", Integer.class));
+
+ loadAttributes(ejbJarInfo, "Red");
+
+ assertAttribute(2, TimeUnit.SECONDS, Red.class.getMethod("color"));
+ assertNullAttribute(Red.class.getMethod("color", Object.class));
+ assertAttribute(1, TimeUnit.SECONDS, Red.class.getMethod("color", String.class));
+ assertAttribute(1, TimeUnit.SECONDS, Red.class.getMethod("color", Boolean.class));
+ assertAttribute(1, TimeUnit.SECONDS, Red.class.getMethod("color", Integer.class));
+
+ assertAttribute(1, TimeUnit.MINUTES, Red.class.getMethod("red"));
+ assertNullAttribute(Red.class.getMethod("red", Object.class));
+ assertNullAttribute(Red.class.getMethod("red", String.class));
+
+ loadAttributes(ejbJarInfo, "Crimson");
+
+ assertAttribute(1, TimeUnit.HOURS, Crimson.class.getMethod("color"));
+ assertNullAttribute(Crimson.class.getMethod("color", Object.class));
+ assertAttribute(1, TimeUnit.HOURS, Crimson.class.getMethod("color", String.class));
+ assertAttribute(1, TimeUnit.SECONDS, Crimson.class.getMethod("color", Boolean.class));
+ assertAttribute(1, TimeUnit.SECONDS, Crimson.class.getMethod("color", Integer.class));
+
+ assertAttribute(1, TimeUnit.MINUTES, Crimson.class.getMethod("red"));
+ assertNullAttribute(Crimson.class.getMethod("red", Object.class));
+ assertNullAttribute(Crimson.class.getMethod("red", String.class));
+
+ assertAttribute(2, TimeUnit.HOURS, Crimson.class.getMethod("crimson"));
+ assertAttribute(1, TimeUnit.HOURS, Crimson.class.getMethod("crimson", String.class));
+
+ loadAttributes(ejbJarInfo, "Scarlet");
+
+ assertAttribute(2, TimeUnit.SECONDS, Scarlet.class.getMethod("color"));
+ assertNullAttribute(Scarlet.class.getMethod("color", Object.class));
+ assertAttribute(1, TimeUnit.SECONDS, Scarlet.class.getMethod("color", String.class));
+ assertAttribute(1, TimeUnit.SECONDS, Scarlet.class.getMethod("color", Boolean.class));
+ assertAttribute(1, TimeUnit.SECONDS, Scarlet.class.getMethod("color", Integer.class));
+
+ assertAttribute(1, TimeUnit.MINUTES, Scarlet.class.getMethod("red"));
+ assertNullAttribute(Scarlet.class.getMethod("red", Object.class));
+ assertNullAttribute(Scarlet.class.getMethod("red", String.class));
+
+ assertAttribute(2, TimeUnit.DAYS, Scarlet.class.getMethod("scarlet"));
+ assertAttribute(1, TimeUnit.DAYS, Scarlet.class.getMethod("scarlet", String.class));
+ }
+
+ private void loadAttributes(EjbJarInfo ejbJarInfo, String deploymentId) {
+ ContainerSystem system = SystemInstance.get().getComponent(ContainerSystem.class);
+ CoreDeploymentInfo deploymentInfo = (CoreDeploymentInfo) system.getDeploymentInfo(deploymentId);
+ List<MethodConcurrencyInfo> infos = MethodConcurrencyBuilder.normalize(ejbJarInfo.methodConcurrency);
+ attributes = MethodInfoUtil.resolveAttributes(infos, deploymentInfo);
+ }
+
+ private void assertAttribute(long time, TimeUnit unit, Method method) {
+ MethodConcurrencyInfo info = (MethodConcurrencyInfo) attributes.get(method);
+ assertTrue("Null timeout for " + method, info != null && info.accessTimeout != null);
+ assertEquals("Timeout time for " + method, time, info.accessTimeout.time);
+ assertEquals("Timeout unit for " + method, unit, TimeUnit.valueOf(info.accessTimeout.unit));
+ }
+
+ private void assertNullAttribute(Method method) {
+ MethodConcurrencyInfo info = (MethodConcurrencyInfo) attributes.get(method);
+ assertTrue("Non-null timeout for " + method, info == null || info.accessTimeout == null);
+ }
+
+ @Local
+ public static interface ColorLocal {
+ }
+
+ @Remote
+ public static interface ColorRemote {
+ }
+
+ @AccessTimeout(value = 1, unit = TimeUnit.SECONDS)
+ public static class Color implements ColorLocal, ColorRemote {
+
+
+ @AccessTimeout(value = 2, unit = TimeUnit.SECONDS)
+ public void color() {
+ }
+
+
+ @AccessTimeout(value = 3, unit = TimeUnit.SECONDS)
+ public void color(Object o) {
+ }
+
+ public void color(String s) {
+ }
+
+ public void color(Boolean b) {
+ }
+
+ public void color(Integer i) {
+ }
+ }
+
+
+ public static class Red extends Color {
+
+ public void color(Object o) {
+ super.color(o);
+ }
+
+ @AccessTimeout(value = 1, unit = TimeUnit.MINUTES)
+ public void red() {
+ }
+
+ public void red(Object o) {
+ }
+
+ public void red(String s) {
+ }
+
+ }
+
+ @AccessTimeout(value = 1, unit = TimeUnit.HOURS)
+ public static class Crimson extends Red {
+
+
+ public void color() {
+ }
+
+ public void color(String s) {
+ }
+
+ @AccessTimeout(value = 2, unit = TimeUnit.HOURS)
+ public void crimson() {
+ }
+
+ public void crimson(String s) {
+ }
+ }
+
+ @AccessTimeout(value = 1, unit = TimeUnit.DAYS)
+ public static class Scarlet extends Red {
+
+ @AccessTimeout(value = 2, unit = TimeUnit.DAYS)
+ public void scarlet() {
+ }
+
+ public void scarlet(String s) {
+ }
+ }
+
+}
Propchange: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/AccessTimeoutTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/AccessTimeoutTest.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/AccessTimeoutTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulConcurrencyTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulConcurrencyTest.java?rev=990932&r1=990931&r2=990932&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulConcurrencyTest.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulConcurrencyTest.java Mon Aug 30 20:32:29 2010
@@ -33,7 +33,9 @@ import org.apache.openejb.assembler.clas
import org.apache.openejb.assembler.classic.TransactionServiceInfo;
import org.apache.openejb.client.LocalInitialContextFactory;
import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.jee.ConcurrentMethod;
import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.NamedMethod;
import org.apache.openejb.jee.StatefulBean;
import org.apache.openejb.jee.Timeout;
@@ -61,13 +63,19 @@ public class StatefulConcurrencyTest ext
Timeout timeout1 = new Timeout();
timeout1.setTimeout(1000);
timeout1.setUnit(TimeUnit.MILLISECONDS);
- bean1.setAccessTimeout(timeout1);
+ ConcurrentMethod method1 = new ConcurrentMethod();
+ method1.setMethod(new NamedMethod("*"));
+ method1.setAccessTimeout(timeout1);
+ bean1.getConcurrentMethod().add(method1);
StatefulBean bean2 = new StatefulBean("BeanNegative", MyLocalBeanImpl.class);
Timeout timeout2 = new Timeout();
timeout2.setTimeout(-1);
timeout2.setUnit(TimeUnit.MILLISECONDS);
- bean2.setAccessTimeout(timeout2);
+ ConcurrentMethod method2 = new ConcurrentMethod();
+ method2.setMethod(new NamedMethod("*"));
+ method2.setAccessTimeout(timeout2);
+ bean2.getConcurrentMethod().add(method2);
ejbJar.addEnterpriseBean(bean1);
ejbJar.addEnterpriseBean(bean2);
Modified: openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ContainerConcurrency.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ContainerConcurrency.java?rev=990932&r1=990931&r2=990932&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ContainerConcurrency.java (original)
+++ openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ContainerConcurrency.java Mon Aug 30 20:32:29 2010
@@ -43,6 +43,8 @@ public class ContainerConcurrency implem
protected List<Method> method;
@XmlElement(name = "concurrency-attribute", required = true)
protected ConcurrentLockType lock;
+ @XmlTransient
+ protected Timeout accessTimeout;
@XmlAttribute
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlID
@@ -97,6 +99,14 @@ public class ContainerConcurrency implem
this.lock = value;
}
+ public Timeout getAccessTimeout() {
+ return accessTimeout;
+ }
+
+ public void setAccessTimeout(Timeout value) {
+ this.accessTimeout = value;
+ }
+
public String getId() {
return id;
}
Modified: openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionBean.java?rev=990932&r1=990931&r2=990932&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionBean.java (original)
+++ openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionBean.java Mon Aug 30 20:32:29 2010
@@ -140,9 +140,7 @@ import javax.xml.bind.annotation.adapter
"postActivate",
"prePassivate",
"securityRoleRef",
- "securityIdentity",
- //TODO not actually specified in schema
- "accessTimeout"
+ "securityIdentity"
})
public class SessionBean implements RemoteBean, Session, TimerConsumer {
@XmlTransient
@@ -251,11 +249,6 @@ public class SessionBean implements Remo
@XmlTransient
private List<LifecycleCallback> afterCompletion;
- //Not in schema, but can be specified with annotation
-// @XmlTransient
- @XmlElement(name = "access-timeout")
- protected Timeout accessTimeout;
-
public SessionBean() {
}
@@ -868,14 +861,6 @@ public class SessionBean implements Remo
return this.timer;
}
- public Timeout getAccessTimeout() {
- return accessTimeout;
- }
-
- public void setAccessTimeout(Timeout accessTimeout) {
- this.accessTimeout = accessTimeout;
- }
-
public void addAroundTimeout(String method) {
assert ejbClass != null : "Set the ejbClass before calling this method";
getAroundTimeout().add(new AroundTimeout(ejbClass, method));
Modified: openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java?rev=990932&r1=990931&r2=990932&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java (original)
+++ openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java Mon Aug 30 20:32:29 2010
@@ -99,7 +99,6 @@ public class JeeTest extends TestCase {
assertTrue("The bean A is not a SessionBean", bean instanceof SessionBean);
SessionBean sbean = (SessionBean) bean;
- assertNotNull("Unable to get the AccessTimeout value", sbean.getAccessTimeout());
assertNotNull("Unable to get the StatefulTimeout value", sbean.getStatefulTimeout());
}
Modified: openejb/trunk/openejb3/container/openejb-jee/src/test/resources/ejb-jar-timeout.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/test/resources/ejb-jar-timeout.xml?rev=990932&r1=990931&r2=990932&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-jee/src/test/resources/ejb-jar-timeout.xml (original)
+++ openejb/trunk/openejb3/container/openejb-jee/src/test/resources/ejb-jar-timeout.xml Mon Aug 30 20:32:29 2010
@@ -26,11 +26,6 @@
<timeout>1234</timeout>
<unit>Seconds</unit>
</stateful-timeout>
- <access-timeout>
- <timeout>1234</timeout>
- <unit>Seconds</unit>
- </access-timeout>
-
</session>
</enterprise-beans>
</ejb-jar>