You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by ad...@apache.org on 2007/01/04 07:06:18 UTC

svn commit: r492419 - in /incubator/openejb/trunk/openejb3: container/openejb-core/src/main/java/org/apache/openejb/ container/openejb-core/src/main/java/org/apache/openejb/alt/config/ container/openejb-core/src/main/java/org/apache/openejb/assembler/c...

Author: adc
Date: Wed Jan  3 22:06:16 2007
New Revision: 492419

URL: http://svn.apache.org/viewvc?view=rev&rev=492419
Log:
OPENEJB-430 Transaction support wired in MDB Container by Manu T George

Added:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MdbContainerInfo.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/NamedMethodInfo.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MessageDrivenBeanManagedTxPolicy.java
Modified:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/BeanType.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/EjbJarInfoBuilder.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ContainerInfo.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ContainerSystemInfo.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanInfo.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/spring/Assembler.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/ejb-jar.xml

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/BeanType.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/BeanType.java?view=diff&rev=492419&r1=492418&r2=492419
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/BeanType.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/BeanType.java Wed Jan  3 22:06:16 2007
@@ -29,4 +29,8 @@
     public boolean isSession(){
         return this == STATEFUL || this == STATELESS;
     }
+
+    public boolean isMessageDriven() {
+        return this == MESSAGE_DRIVEN;
+    }
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java?view=diff&rev=492419&r1=492418&r2=492419
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java Wed Jan  3 22:06:16 2007
@@ -42,6 +42,7 @@
 import org.apache.openejb.assembler.classic.JndiContextInfo;
 import org.apache.openejb.assembler.classic.JndiEncInfo;
 import org.apache.openejb.assembler.classic.ManagedConnectionFactoryInfo;
+import org.apache.openejb.assembler.classic.MdbContainerInfo;
 import org.apache.openejb.assembler.classic.OpenEjbConfiguration;
 import org.apache.openejb.assembler.classic.OpenEjbConfigurationFactory;
 import org.apache.openejb.assembler.classic.RoleMappingInfo;
@@ -81,7 +82,7 @@
     private final List<EntityContainerInfo> entityContainers = new ArrayList<EntityContainerInfo>();
     private final List<StatefulSessionContainerInfo> sfsbContainers = new ArrayList<StatefulSessionContainerInfo>();
     private final List<StatelessSessionContainerInfo> slsbContainers = new ArrayList<StatelessSessionContainerInfo>();
-
+    private final List<MdbContainerInfo> mdbContainers = new ArrayList<MdbContainerInfo>();
     private Map<String,ContainerInfo> containerTable = new HashMap<String,ContainerInfo>();
 
     private Properties props;
@@ -163,7 +164,8 @@
         sys.containerSystem.entityContainers.addAll(entityContainers);
         sys.containerSystem.statefulContainers.addAll(sfsbContainers);
         sys.containerSystem.statelessContainers.addAll(slsbContainers);
-
+        sys.containerSystem.mdbContainers.addAll(mdbContainers);
+        
         List<AppInfo> appInfos = new ArrayList<AppInfo>();
         {
             AppInfo appInfo = new AppInfo();
@@ -478,8 +480,8 @@
                 entityContainers.add((EntityContainerInfo) ci);
             } else if (c.getCtype().equals("MESSAGE")) {
                 c = (Container) initService(c, DEFAULT_MDB_CONTAINER);
-                ci = new EntityContainerInfo();
-                entityContainers.add((EntityContainerInfo) ci);
+                ci = new MdbContainerInfo();
+                mdbContainers.add((MdbContainerInfo) ci);
             } else {
                 throw new OpenEJBException("Unrecognized contianer type " + c.getCtype());
             }
@@ -507,6 +509,7 @@
         this.containers.addAll(sfsbContainers);
         this.containers.addAll(slsbContainers);
         this.containers.addAll(entityContainers);
+        this.containers.addAll(mdbContainers);
 
         for (ContainerInfo containerInfo : this.containers) {
             containerTable.put(containerInfo.containerName, containerInfo);

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/EjbJarInfoBuilder.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/EjbJarInfoBuilder.java?view=diff&rev=492419&r1=492418&r2=492419
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/EjbJarInfoBuilder.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/EjbJarInfoBuilder.java Wed Jan  3 22:06:16 2007
@@ -30,6 +30,7 @@
 import org.apache.openejb.assembler.classic.MethodInterceptorInfo;
 import org.apache.openejb.assembler.classic.MethodPermissionInfo;
 import org.apache.openejb.assembler.classic.MethodTransactionInfo;
+import org.apache.openejb.assembler.classic.NamedMethodInfo;
 import org.apache.openejb.assembler.classic.QueryInfo;
 import org.apache.openejb.assembler.classic.SecurityRoleInfo;
 import org.apache.openejb.assembler.classic.SecurityRoleReferenceInfo;
@@ -463,8 +464,15 @@
 
         copyCallbacks(mdb.getPostConstruct(), bean.postConstruct);
         copyCallbacks(mdb.getPreDestroy(), bean.preDestroy);
-
+        NamedMethodInfo timeoutMethodInfo = new NamedMethodInfo();
+        if (mdb.getTimeoutMethod() != null) {
+            timeoutMethodInfo.methodName = mdb.getTimeoutMethod().getMethodName();
+            if (mdb.getTimeoutMethod().getMethodParams() != null) {
+                timeoutMethodInfo.methodParams = mdb.getTimeoutMethod().getMethodParams().getMethodParam();
+            }
+        }
         EjbDeployment d = (EjbDeployment) m.get(mdb.getEjbName());
+        bean.timeoutMethod = timeoutMethodInfo;
         if (d == null) {
             throw new OpenEJBException("No deployment information in openejb-jar.xml for bean "
                     + mdb.getEjbName()

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java?view=diff&rev=492419&r1=492418&r2=492419
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java Wed Jan  3 22:06:16 2007
@@ -143,7 +143,7 @@
         }
     }
 
-    public void applyTransactionAttributes(CoreDeploymentInfo deploymentInfo, List<MethodTransactionInfo> mtis) {
+    public void applyTransactionAttributes(CoreDeploymentInfo deploymentInfo, List<MethodTransactionInfo> mtis) throws OpenEJBException {
         /*TODO: Add better exception handling.  This method doesn't throws any exceptions!!
          there is a lot of complex code here, I'm sure something could go wrong the user
          might want to know about.
@@ -162,8 +162,11 @@
                             }
                             if (deploymentInfo.getHomeInterface() != null) {
                                 resolveMethods(methods, deploymentInfo.getHomeInterface(), methodInfo);
-                            } else {
                             }
+                            if(deploymentInfo.getMdbInterface() != null) {
+                            	resolveMethods(methods, deploymentInfo.getMdbInterface(), methodInfo);
+                            }
+
                         } else if (methodInfo.methodIntf.equals("Home")) {
                             resolveMethods(methods, deploymentInfo.getHomeInterface(), methodInfo);
                         } else if (methodInfo.methodIntf.equals("Remote")) {

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ContainerInfo.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ContainerInfo.java?view=diff&rev=492419&r1=492418&r2=492419
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ContainerInfo.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ContainerInfo.java Wed Jan  3 22:06:16 2007
@@ -23,6 +23,8 @@
 public abstract class ContainerInfo extends InfoObject {
 
     public static final int ENTITY_CONTAINER = 0;
+    
+    public static final int MDB_CONTAINER = 1;
 
     public static final int STATEFUL_SESSION_CONTAINER = 2;
 

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ContainerSystemInfo.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ContainerSystemInfo.java?view=diff&rev=492419&r1=492418&r2=492419
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ContainerSystemInfo.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ContainerSystemInfo.java Wed Jan  3 22:06:16 2007
@@ -30,6 +30,7 @@
     public final List<EntityContainerInfo> entityContainers = new ArrayList<EntityContainerInfo>();
     public final List<StatelessSessionContainerInfo> statelessContainers = new ArrayList<StatelessSessionContainerInfo>();
     public final List<StatefulSessionContainerInfo> statefulContainers = new ArrayList<StatefulSessionContainerInfo>();
+    public final List<MdbContainerInfo> mdbContainers = new ArrayList<MdbContainerInfo>();
     public final List<SecurityRoleInfo> securityRoles = new ArrayList<SecurityRoleInfo>();
     public final List<MethodPermissionInfo> methodPermissions= new ArrayList<MethodPermissionInfo>();
     public final List<MethodTransactionInfo> methodTransactions = new ArrayList<MethodTransactionInfo>();

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java?view=diff&rev=492419&r1=492418&r2=492419
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java Wed Jan  3 22:06:16 2007
@@ -152,6 +152,7 @@
 
         deployment.setPostConstruct(getCallback(ejbClass, bean.postConstruct));
         deployment.setPreDestroy(getCallback(ejbClass, bean.preDestroy));
+        deployment.setEjbTimeout(getTimeout(ejbClass, bean.timeoutMethod));
 
         // interceptors
         InterceptorBuilder interceptorBuilder = new InterceptorBuilder(defaultInterceptors, bean);
@@ -165,8 +166,8 @@
             deployment.setPrePassivate(getCallback(ejbClass, statefulBeanInfo.prePassivate));
             deployment.setPostActivate(getCallback(ejbClass, statefulBeanInfo.postActivate));
         }
-        
-        if (ejbType.isSession()) {
+
+        if (ejbType.isSession() || ejbType.isMessageDriven()) {
             deployment.setBeanManagedTransaction("Bean".equalsIgnoreCase(bean.transactionType));
         }
 
@@ -228,6 +229,34 @@
         }
         return callback;
     }
+
+    private Method getTimeout(Class ejbClass, NamedMethodInfo info) {
+        Method timeout = null;
+        try {
+            if (info.methodParams != null) {
+                List<Class> parameterTypes = new ArrayList<Class>();
+
+                for (String paramType : info.methodParams) {
+                    try {
+                        parameterTypes.add(Class.forName(paramType));
+                    } catch (ClassNotFoundException cnfe) {
+                        throw (IllegalStateException) new IllegalStateException("Parameter class could not be loaded for type " + paramType).initCause(cnfe);
+                    }
+                }
+
+                try {
+                    timeout = ejbClass.getMethod(info.methodName, parameterTypes.toArray(new Class[parameterTypes.size()]));
+                } catch (NoSuchMethodException e) {
+                    throw (IllegalStateException) new IllegalStateException("Timeout Callback method does not exist: " + ejbClass.getName() + "." + info.methodName).initCause(e);
+                }
+            }
+        } catch (Exception e) {
+            warnings.add(e);
+        }
+
+        return timeout;
+    }
+
 
     private Class loadClass(String className, String messageCode) throws OpenEJBException {
         Class clazz = load(className, messageCode);

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanInfo.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanInfo.java?view=diff&rev=492419&r1=492418&r2=492419
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanInfo.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanInfo.java Wed Jan  3 22:06:16 2007
@@ -48,6 +48,8 @@
 
     public String transactionType;
     public JndiEncInfo jndiEnc;
+    public NamedMethodInfo timeoutMethod;
+    
     public final List<SecurityRoleReferenceInfo> securityRoleReferences = new ArrayList<SecurityRoleReferenceInfo>();
 
     public final List<LifecycleCallbackInfo> postConstruct = new ArrayList<LifecycleCallbackInfo>();
@@ -56,4 +58,5 @@
     public boolean excludeDefaultInterceptors;
     public final List<InterceptorInfo> classInterceptors = new ArrayList<InterceptorInfo>();
     public final List<MethodInterceptorInfo> methodInterceptors = new ArrayList<MethodInterceptorInfo>();
+    
 }

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MdbContainerInfo.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MdbContainerInfo.java?view=auto&rev=492419
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MdbContainerInfo.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MdbContainerInfo.java Wed Jan  3 22:06:16 2007
@@ -0,0 +1,24 @@
+/**
+ * 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;
+
+public class MdbContainerInfo extends ContainerInfo {
+
+    public MdbContainerInfo() {
+        containerType = MDB_CONTAINER;
+    }
+}

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/NamedMethodInfo.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/NamedMethodInfo.java?view=auto&rev=492419
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/NamedMethodInfo.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/NamedMethodInfo.java Wed Jan  3 22:06:16 2007
@@ -0,0 +1,27 @@
+/**
+ * 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 java.util.List;
+
+
+public class NamedMethodInfo extends InfoObject {
+
+    public String methodName;
+    public List<String> methodParams;
+    public String id;
+}

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/spring/Assembler.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/spring/Assembler.java?view=diff&rev=492419&r1=492418&r2=492419
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/spring/Assembler.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/spring/Assembler.java Wed Jan  3 22:06:16 2007
@@ -224,7 +224,7 @@
         return wrappedContainers;
     }
 
-    protected void applyTransactionAttributes(CoreDeploymentInfo deploymentInfo, MethodTransactionInfo[] transactionInfos) {
+    protected void applyTransactionAttributes(CoreDeploymentInfo deploymentInfo, MethodTransactionInfo[] transactionInfos) throws OpenEJBException {
         if (deploymentInfo.isBeanManagedTransaction()) {
             // deployments with bean managed transactions don't have transaction attributes
             return;

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java?view=diff&rev=492419&r1=492418&r2=492419
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java Wed Jan  3 22:06:16 2007
@@ -32,6 +32,7 @@
 import javax.ejb.EnterpriseBean;
 import javax.ejb.SessionBean;
 import javax.ejb.MessageDrivenBean;
+import javax.ejb.TimedObject;
 
 import org.apache.openejb.Container;
 import org.apache.openejb.RpcContainer;
@@ -41,6 +42,7 @@
 import org.apache.openejb.DeploymentInfo;
 import org.apache.openejb.BeanType;
 import org.apache.openejb.Injection;
+import org.apache.openejb.OpenEJBException;
 import org.apache.openejb.core.cmp.KeyGenerator;
 import org.apache.openejb.core.entity.EntityEjbHomeHandler;
 import org.apache.openejb.core.ivm.EjbHomeProxyHandler;
@@ -51,6 +53,7 @@
 import org.apache.openejb.core.stateless.StatelessBeanManagedTxPolicy;
 import org.apache.openejb.core.stateless.StatelessEjbHomeHandler;
 import org.apache.openejb.core.transaction.TransactionContainer;
+import org.apache.openejb.core.transaction.TransactionContext;
 import org.apache.openejb.core.transaction.TransactionPolicy;
 import org.apache.openejb.core.transaction.TxManditory;
 import org.apache.openejb.core.transaction.TxNever;
@@ -58,8 +61,8 @@
 import org.apache.openejb.core.transaction.TxRequired;
 import org.apache.openejb.core.transaction.TxRequiresNew;
 import org.apache.openejb.core.transaction.TxSupports;
-import org.apache.openejb.core.transaction.TransactionContext;
 import org.apache.openejb.core.interceptor.InterceptorData;
+import org.apache.openejb.core.mdb.MessageDrivenBeanManagedTxPolicy;
 import org.apache.openejb.util.proxy.ProxyManager;
 
 /**
@@ -81,6 +84,7 @@
     private Method preDestroy;
     private Method prePassivate;
     private Method postActivate;
+    private Method ejbTimeout;
 
     private boolean isBeanManagedTransaction;
     private boolean isReentrant;
@@ -173,6 +177,13 @@
                 throw new SystemException(e);
             }
         }
+        if (TimedObject.class.isAssignableFrom(beanClass)) {
+            try {
+                this.ejbTimeout = beanClass.getMethod("ejbTimeout");
+            } catch (NoSuchMethodException e) {
+                throw new IllegalStateException(e);
+            }
+        }
     }
 
     public CoreDeploymentInfo(DeploymentContext context, Class beanClass, Class mdbInterface, Map<String, String> activationProperties) throws SystemException {
@@ -184,7 +195,14 @@
 
         if (MessageDrivenBean.class.isAssignableFrom(beanClass)){
             try {
-                this.preDestroy = MessageDrivenBean.class.getMethod("ejbRemove");
+                this.preDestroy = beanClass.getMethod("ejbRemove");
+            } catch (NoSuchMethodException e) {
+                throw new IllegalStateException(e);
+            }
+        }
+        if (TimedObject.class.isAssignableFrom(beanClass)) {
+            try {
+                this.ejbTimeout = beanClass.getMethod("ejbTimeout");
             } catch (NoSuchMethodException e) {
                 throw new IllegalStateException(e);
             }
@@ -232,6 +250,8 @@
                     policy = new StatefulBeanManagedTxPolicy((TransactionContainer) container);
                 } else if (componentType == BeanType.STATELESS) {
                     policy = new StatelessBeanManagedTxPolicy((TransactionContainer) container);
+                } else if (componentType == BeanType.MESSAGE_DRIVEN) {
+                    policy = new MessageDrivenBeanManagedTxPolicy((TransactionContainer) container);
                 }
             } else if (componentType == BeanType.STATEFUL) {
                 policy = new TxNotSupported((TransactionContainer) container);
@@ -416,7 +436,7 @@
         securityRoleReferenceMap.put(securityRoleReference, physicalRoles);
     }
 
-    public void setMethodTransactionAttribute(Method method, String transAttribute) {
+    public void setMethodTransactionAttribute(Method method, String transAttribute) throws OpenEJBException {
         Byte byteValue = null;
         TransactionPolicy policy = null;
 
@@ -477,6 +497,24 @@
                 policy = new StatefulContainerManagedTxPolicy(policy);
             }
         }
+
+        /**
+           Only the NOT_SUPPORTED and REQUIRED transaction attributes may be used for message-driven
+           bean message listener methods. The use of the other transaction attributes is not meaningful
+           for message-driven bean message listener methods because there is no pre-existing client transaction
+           context(REQUIRES_NEW, SUPPORTS) and no client to handle exceptions (MANDATORY, NEVER).
+         */
+        if (componentType.isMessageDriven() && !isBeanManagedTransaction && container instanceof TransactionContainer) {
+            if (policy.policyType != policy.NotSupported && policy.policyType != policy.Required) {
+                if (method.equals(this.ejbTimeout) && policy.policyType == policy.RequiresNew) {
+                    // do nothing. This is allowed as the timer callback method for a message driven bean
+                    // can also have a transaction policy of RequiresNew Sec 5.4.12 of Ejb 3.0 Core Spec
+                } else {
+                    throw new OpenEJBException("The transaction attribute " + policy.policyToString() + "is not supported for the method "
+                                               + method.getName() + " of the Message Driven Bean " + beanClass.getName());
+                }
+            }
+        }
         methodTransactionAttributes.put(method, byteValue);
         methodTransactionPolicies.put(method, policy);
     }
@@ -659,7 +697,7 @@
                     beanMethod = beanClass.getMethod(ejbCreateName.toString(), method.getParameterTypes());
                     createMethod = beanMethod;
                     /*
-                    Entity beans have a ejbCreate and ejbPostCreate methods with matching 
+                    Entity beans have a ejbCreate and ejbPostCreate methods with matching
                     parameters. This code maps that relationship.
                     */
                     if (this.componentType == BeanType.BMP_ENTITY || this.componentType == BeanType.CMP_ENTITY) {
@@ -843,5 +881,13 @@
 
     public String getJarPath() {
         return jarPath;
+    }
+
+    public Method getEjbTimeout() {
+        return ejbTimeout;
+    }
+
+    public void setEjbTimeout(Method ejbTimeout) {
+        this.ejbTimeout = ejbTimeout;
     }
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java?view=diff&rev=492419&r1=492418&r2=492419
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java Wed Jan  3 22:06:16 2007
@@ -25,6 +25,7 @@
 import org.apache.openejb.spi.SecurityService;
 import org.apache.openejb.core.ThreadContext;
 import org.apache.openejb.core.CoreDeploymentInfo;
+import org.apache.openejb.core.transaction.TransactionContainer;
 import org.apache.openejb.core.transaction.TransactionContext;
 import org.apache.openejb.core.transaction.TransactionPolicy;
 import org.apache.log4j.Logger;
@@ -41,7 +42,7 @@
 import java.util.Map;
 import java.util.Arrays;
 
-public class MdbContainer implements Container {
+public class MdbContainer implements Container, TransactionContainer {
     protected static final Logger logger = Logger.getLogger("OpenEJB");
     private static final Object[] NO_ARGS = new Object[0];
 
@@ -316,6 +317,7 @@
         }
     }
 
+
     private static class MdbCallContext {
         private Method deliveryMethod;
         private ClassLoader adapterClassLoader;
@@ -335,5 +337,9 @@
     private void restoreAdapterClassLoader(MdbCallContext mdbCallContext) {
         Thread.currentThread().setContextClassLoader(mdbCallContext.adapterClassLoader);
         mdbCallContext.adapterClassLoader = null;
+    }
+
+    public void discardInstance(Object instance, ThreadContext context) {
+        // TODO Auto-generated method stub
     }
 }

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MessageDrivenBeanManagedTxPolicy.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MessageDrivenBeanManagedTxPolicy.java?view=auto&rev=492419
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MessageDrivenBeanManagedTxPolicy.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MessageDrivenBeanManagedTxPolicy.java Wed Jan  3 22:06:16 2007
@@ -0,0 +1,111 @@
+/**
+ * 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.core.mdb;
+
+import java.rmi.RemoteException;
+import javax.transaction.Status;
+
+import org.apache.openejb.ApplicationException;
+import org.apache.openejb.SystemException;
+import org.apache.openejb.core.transaction.TransactionContainer;
+import org.apache.openejb.core.transaction.TransactionContext;
+import org.apache.openejb.core.transaction.TransactionPolicy;
+
+
+public class MessageDrivenBeanManagedTxPolicy extends TransactionPolicy {
+
+    public MessageDrivenBeanManagedTxPolicy(TransactionContainer container) {
+        this();
+        if (container instanceof org.apache.openejb.Container &&
+            ((org.apache.openejb.Container) container).getContainerType() != org.apache.openejb.Container.MESSAGE_DRIVEN)
+        {
+            throw new IllegalArgumentException();
+        }
+
+        this.container = container;
+    }
+
+    public MessageDrivenBeanManagedTxPolicy() {
+        policyType = BeanManaged;
+    }
+
+    public String policyToString() {
+        return "TX_BeanManaged: ";
+    }
+
+    public void beforeInvoke(Object instance, TransactionContext context) throws SystemException, ApplicationException {
+        context.clientTx = suspendTransaction(context);
+    }
+
+    @SuppressWarnings({"EmptyCatchBlock"})
+    public void afterInvoke(Object instance, TransactionContext context) throws ApplicationException, SystemException {
+
+        try {
+            /*
+            * The Container must detect the case in which a transaction was started, but
+            * not completed, in the business method, and handle it as follows:
+            */
+            context.currentTx = context.getTransactionManager().getTransaction();
+
+            if (context.currentTx == null) return;
+
+            if (context.currentTx.getStatus() != Status.STATUS_ROLLEDBACK && context.currentTx.getStatus() != Status.STATUS_COMMITTED) {
+                String message = "The message driven bean started a transaction but did not complete it.";
+
+                /* [1] Log this as an application error ********/
+                logger.error(message);
+
+                /* [2] Roll back the started transaction *******/
+                try {
+                    rollbackTransaction(context, context.currentTx);
+                } catch (Throwable ignore) {
+
+                }
+
+                /* [3] Throw the RemoteException to the client */
+                throwAppExceptionToServer(new RemoteException(message));
+            }
+
+        } catch (javax.transaction.SystemException e) {
+            throw new SystemException(e);
+        } finally {
+            resumeTransaction(context, context.clientTx);
+        }
+    }
+
+    public void handleApplicationException(Throwable appException, TransactionContext context) throws ApplicationException {
+        throw new ApplicationException(appException);
+    }
+
+    public void handleSystemException(Throwable sysException, Object instance, TransactionContext context) throws ApplicationException, SystemException {
+        try {
+            context.currentTx = context.getTransactionManager().getTransaction();
+        } catch (javax.transaction.SystemException e) {
+            context.currentTx = null;
+        }
+
+        logSystemException(sysException);
+
+        if (context.currentTx != null) markTxRollbackOnly(context.currentTx);
+
+        discardBeanInstance(instance, context.callContext);
+
+        throwExceptionToServer(sysException);
+    }
+
+}
+

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/ejb-jar.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/ejb-jar.xml?view=diff&rev=492419&r1=492418&r2=492419
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/ejb-jar.xml (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/ejb-jar.xml Wed Jan  3 22:06:16 2007
@@ -909,7 +909,7 @@
 		<persistence-unit-ref-name>persistence/TestUnit</persistence-unit-ref-name>
 		<persistence-unit-name>openjpa-test-unit</persistence-unit-name>
 	    </persistence-unit-ref>
-            
+
         </session>
 
         <!--
@@ -1010,7 +1010,7 @@
 		<persistence-unit-ref-name>persistence/TestUnit</persistence-unit-ref-name>
 		<persistence-unit-name>openjpa-test-unit</persistence-unit-name>
 	    </persistence-unit-ref>
-            
+
         </session>
 
         <!--
@@ -1573,7 +1573,7 @@
 		<persistence-unit-ref-name>persistence/TestUnit</persistence-unit-ref-name>
 		<persistence-unit-name>openjpa-test-unit</persistence-unit-name>
 	    </persistence-unit-ref>
-            
+
         </session>
 
         <!--
@@ -1794,7 +1794,7 @@
 		<persistence-unit-ref-name>persistence/TestUnit</persistence-unit-ref-name>
 		<persistence-unit-name>openjpa-test-unit</persistence-unit-name>
 	    </persistence-unit-ref>
-            
+
         </entity>
 
         <!--
@@ -1898,7 +1898,7 @@
 		<persistence-unit-ref-name>persistence/TestUnit</persistence-unit-ref-name>
 		<persistence-unit-name>openjpa-test-unit</persistence-unit-name>
 	    </persistence-unit-ref>
-            
+
         </entity>
 
         <!--
@@ -1948,19 +1948,19 @@
 
         <message-driven>
             <description>
-            Blah blah blah . . . 
+            Blah blah blah . . .
             </description>
             <ejb-name>BasicMdbBean</ejb-name>
             <ejb-class>org.apache.openejb.test.mdb.BasicMdbBean</ejb-class>
             <messaging-type>javax.jms.MessageListener</messaging-type>
-            <transaction-type>Container</transaction-type>            
+            <transaction-type>Container</transaction-type>
             <message-destination-type>javax.jms.Queue</message-destination-type>
             <message-destination-link>SendReceiveQueue</message-destination-link>
             <activation-config>
-           		<activation-property>
-                	<activation-config-property-name>destination</activation-config-property-name>
+                <activation-config-property>
+                    <activation-config-property-name>destination</activation-config-property-name>
                     <activation-config-property-value>SendReceiveQueue</activation-config-property-value>
-                </activation-property>
+                </activation-config-property>
             </activation-config>
         </message-driven>
     </enterprise-beans>
@@ -2271,6 +2271,12 @@
             </method>
             <trans-attribute>Never</trans-attribute>
         </container-transaction>
-
+        <container-transaction>
+            <method>
+                <ejb-name>BasicMdbBean</ejb-name>
+                <method-name>*</method-name>
+            </method>
+            <trans-attribute>Required</trans-attribute>
+        </container-transaction>
     </assembly-descriptor>
 </ejb-jar>



Re: Patch for JIRA 430

Posted by David Blevins <da...@visi.com>.
On Jan 12, 2007, at 11:05 AM, Karan Malhi wrote:

> So for something like below, should i be throwing a  
> InternalErrorException?
> Where is the InternalErrorException class?
>
>   private static void checkPermissions(File file) {
>        if (!file.canRead())
>            throw new RuntimeException("The file " +  
> file.getAbsolutePath()
> + " does not have read permissions.  Please add read permission");
>        if (!file.canWrite()) {
>            throw new RuntimeException("The file " +  
> file.getAbsolutePath()
> + " does not have write permissions.  Please add write permission");
>        }
>
>    }

There is no InternalErrorException clas, Alan is just confusing you :)

But in general, patches don't have to be absolutely perfect all the  
time.  If in doubt, make a judgment call of your own and submit the  
patch (provided it basically works).  When you do, maybe make a note  
on the dev list or the jira asking for feedback on places you have  
doubts in.

-David


>
> On 1/12/07, Alan D. Cabrera <li...@toolazydogs.com> wrote:
>>
>>
>> On Jan 5, 2007, at 9:35 AM, Dain Sundstrom wrote:
>>
>> > On Jan 5, 2007, at 9:23 AM, Alan D. Cabrera wrote:
>> >
>> >> We throw a number of vanilla RuntimeExceptions.  Should we not
>> >> build a few OpenEJB exceptions on top of these?
>> >
>> > I agree that vanilla RuntimeExceptions are bad, but I think we
>> > should be careful when replacing these.  In general, I think we
>> > should favor the standard Java exception classes like NullPointer,
>> > IllegalArgument, and IllegalState.  I hope we can avoid the
>> > coupling that happened in Geronimo when we had lots of "common"
>> > exceptions in the geronimo-common module.
>>
>> Agreed.  Useful and informative runtime exceptions should be left as
>> is.  But, I also think that we should wrap exceptions that would make
>> no sense to the bean developer.  For example, when calling a session
>> context getBusinessObject, that method could theoretically throw an
>> IllegalAccessException when it returns a proxy to the business
>> object.  I think that it should be wrapped with another runtime
>> exception such as InternalErrorException.
>>
>>
>> Regards,
>> Alan
>>
>>
>>
>>
>>
>
>
> -- 
> Karan Malhi


Re: Patch for JIRA 430

Posted by Karan Malhi <ka...@gmail.com>.
So for something like below, should i be throwing a InternalErrorException?
Where is the InternalErrorException class?

   private static void checkPermissions(File file) {
        if (!file.canRead())
            throw new RuntimeException("The file " + file.getAbsolutePath()
+ " does not have read permissions.  Please add read permission");
        if (!file.canWrite()) {
            throw new RuntimeException("The file " + file.getAbsolutePath()
+ " does not have write permissions.  Please add write permission");
        }

    }

On 1/12/07, Alan D. Cabrera <li...@toolazydogs.com> wrote:
>
>
> On Jan 5, 2007, at 9:35 AM, Dain Sundstrom wrote:
>
> > On Jan 5, 2007, at 9:23 AM, Alan D. Cabrera wrote:
> >
> >> We throw a number of vanilla RuntimeExceptions.  Should we not
> >> build a few OpenEJB exceptions on top of these?
> >
> > I agree that vanilla RuntimeExceptions are bad, but I think we
> > should be careful when replacing these.  In general, I think we
> > should favor the standard Java exception classes like NullPointer,
> > IllegalArgument, and IllegalState.  I hope we can avoid the
> > coupling that happened in Geronimo when we had lots of "common"
> > exceptions in the geronimo-common module.
>
> Agreed.  Useful and informative runtime exceptions should be left as
> is.  But, I also think that we should wrap exceptions that would make
> no sense to the bean developer.  For example, when calling a session
> context getBusinessObject, that method could theoretically throw an
> IllegalAccessException when it returns a proxy to the business
> object.  I think that it should be wrapped with another runtime
> exception such as InternalErrorException.
>
>
> Regards,
> Alan
>
>
>
>
>


-- 
Karan Malhi

Re: Patch for JIRA 430

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Jan 5, 2007, at 9:35 AM, Dain Sundstrom wrote:

> On Jan 5, 2007, at 9:23 AM, Alan D. Cabrera wrote:
>
>> We throw a number of vanilla RuntimeExceptions.  Should we not  
>> build a few OpenEJB exceptions on top of these?
>
> I agree that vanilla RuntimeExceptions are bad, but I think we  
> should be careful when replacing these.  In general, I think we  
> should favor the standard Java exception classes like NullPointer,  
> IllegalArgument, and IllegalState.  I hope we can avoid the  
> coupling that happened in Geronimo when we had lots of "common"  
> exceptions in the geronimo-common module.

Agreed.  Useful and informative runtime exceptions should be left as  
is.  But, I also think that we should wrap exceptions that would make  
no sense to the bean developer.  For example, when calling a session  
context getBusinessObject, that method could theoretically throw an  
IllegalAccessException when it returns a proxy to the business  
object.  I think that it should be wrapped with another runtime  
exception such as InternalErrorException.


Regards,
Alan




Re: Patch for JIRA 430

Posted by Dain Sundstrom <da...@iq80.com>.
On Jan 5, 2007, at 9:23 AM, Alan D. Cabrera wrote:

> On Jan 4, 2007, at 10:57 PM, Manu George wrote:
>
>> On 1/4/07, Dain Sundstrom <da...@iq80.com> wrote:
>>>
>>> We should add this check to the verifier.  Also it would be helpful
>>> to explicitly say in the exception message that only NotSupported  
>>> and
>>> Required are allowed.
>> Ok but I am a bit hazy about how validation takes place. A pointer on
>> where to look or how validation is done will be nice :). Also it  
>> would
>> be nice if we have a framework for exception handling where we can
>> give error codes in the exceptions and the messages will be picked up
>> from a property file or something like that. That way error message
>> changes won't need code changes
>
>
> This touches on some questions that I have been meaning to ask.
>
> How and where do we want to support i18n?

Lots of OpenEJB already uses a message catalog.  I think the correct  
question is when are we going to sweep the code base for non-message  
catalog messages.

BTW we should be able to simplify the message catalog now that Java  
has printf.

> We throw a number of vanilla RuntimeExceptions.  Should we not  
> build a few OpenEJB exceptions on top of these?

I agree that vanilla RuntimeExceptions are bad, but I think we should  
be careful when replacing these.  In general, I think we should favor  
the standard Java exception classes like NullPointer,  
IllegalArgument, and IllegalState.  I hope we can avoid the coupling  
that happened in Geronimo when we had lots of "common" exceptions in  
the geronimo-common module.

-dain

i18n and Error handing (Re: Patch for JIRA 430)

Posted by David Blevins <da...@visi.com>.
On Jan 5, 2007, at 9:23 AM, Alan D. Cabrera wrote:

>
> On Jan 4, 2007, at 10:57 PM, Manu George wrote:
>
>> On 1/4/07, Dain Sundstrom <da...@iq80.com> wrote:
>>>
>>> We should add this check to the verifier.  Also it would be helpful
>>> to explicitly say in the exception message that only NotSupported  
>>> and
>>> Required are allowed.
>> Ok but I am a bit hazy about how validation takes place. A pointer on
>> where to look or how validation is done will be nice :). Also it  
>> would
>> be nice if we have a framework for exception handling where we can
>> give error codes in the exceptions and the messages will be picked up
>> from a property file or something like that. That way error message
>> changes won't need code changes
>
>
> This touches on some questions that I have been meaning to ask.
>
> How and where do we want to support i18n?

We're still using the code you wrote in this area, i.e. Logger with  
the inner i18n instance of the logger.  Or the  
o.a.openejb.util.Messages class directly.

We should be doing it everywhere....  Definitely feel free to yank  
messages out of any code you touch and put them in the closest  
Message.properties file.

>
> We throw a number of vanilla RuntimeExceptions.  Should we not  
> build a few OpenEJB exceptions on top of these?

You mean like catch them and wrap them with OpenEJBExceptions?   
That'd be fine.  We certainly should catch Throwable in more places  
as we're definitely not the only ones throwing RuntimeExceptions.

-David

>
> Regards,
> Alan
>
>


Re: Patch for JIRA 430

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Jan 4, 2007, at 10:57 PM, Manu George wrote:

> On 1/4/07, Dain Sundstrom <da...@iq80.com> wrote:
>>
>> We should add this check to the verifier.  Also it would be helpful
>> to explicitly say in the exception message that only NotSupported and
>> Required are allowed.
> Ok but I am a bit hazy about how validation takes place. A pointer on
> where to look or how validation is done will be nice :). Also it would
> be nice if we have a framework for exception handling where we can
> give error codes in the exceptions and the messages will be picked up
> from a property file or something like that. That way error message
> changes won't need code changes


This touches on some questions that I have been meaning to ask.

How and where do we want to support i18n?

We throw a number of vanilla RuntimeExceptions.  Should we not build  
a few OpenEJB exceptions on top of these?


Regards,
Alan



Re: Patch for JIRA 430

Posted by Dain Sundstrom <da...@iq80.com>.
On Jan 4, 2007, at 10:57 PM, Manu George wrote:

> On 1/4/07, Dain Sundstrom <da...@iq80.com> wrote:
>>
>> In EJB3 is there an annotation for Timeout?
> Yes javax.ejb.Timeout. The timeout functionality is not yet wired in
> though. I don't have much of a clue on how to do this and so am hoping
> someone else will do it :-).Should a JIRA be opened for that or is
> there an existing JIRA?

Ah, there is a JIRA for this OPENEJB-245.

>> We should add this check to the verifier.  Also it would be helpful
>> to explicitly say in the exception message that only NotSupported and
>> Required are allowed.
> Ok but I am a bit hazy about how validation takes place. A pointer on
> where to look or how validation is done will be nice :). Also it would
> be nice if we have a framework for exception handling where we can
> give error codes in the exceptions and the messages will be picked up
> from a property file or something like that. That way error message
> changes won't need code changes

I don't really understand how valication works either.  Hopefully,  
David can fill us all in on this.  We need to write new validation  
logic for MDB and CMP2 in addition to updating all of the other ones  
for the EJB3 specification.

>> BTW, have you tried sending a message through the container yet?
>>
> Yes I have tried a basic case where the onMessage gets called and also
> the transaction related interceptor methods.

And it worked?

> Not yet tried testing
> Transaction rollback etc. It will be helpful if we can have the
> embedded AMQ service for the Tests as well so that we can start
> writing Test cases for the MDB container.

I agree.  I'm not going to be able to look at it until I get the  
Geronimo integration working, so maybe someone else can take a crack  
at getting it working.

-dain

Re: Patch for JIRA 430

Posted by Manu George <ma...@gmail.com>.
On 1/4/07, Dain Sundstrom <da...@iq80.com> wrote:
> I was just reading over the commit logs and noticed this patch to the
> MDB code.  I'd like to echo everyone else's comments that is is very
> high quality work, and I am excited to see that MDBs deploy now.  I
> have some specific comments below...
>
>
> > ======================================================================
> > ========
> > --- incubator/openejb/trunk/openejb3/container/openejb-core/src/
> > main/java/org/apache/openejb/core/CoreDeploymentInfo.java (original)
> > +++ incubator/openejb/trunk/openejb3/container/openejb-core/src/
> > main/java/org/apache/openejb/core/CoreDeploymentInfo.java Wed Jan
> > 3 22:06:16 2007
> > @@ -173,6 +177,13 @@
> >                  throw new SystemException(e);
> >              }
> >          }
> > +        if (TimedObject.class.isAssignableFrom(beanClass)) {
> > +            try {
> > +                this.ejbTimeout = beanClass.getMethod("ejbTimeout");
> > +            } catch (NoSuchMethodException e) {
> > +                throw new IllegalStateException(e);
> > +            }
> > +        }
> >      }
>
> In EJB3 is there an annotation for Timeout?
Yes javax.ejb.Timeout. The timeout functionality is not yet wired in
though. I don't have much of a clue on how to do this and so am hoping
someone else will do it :-).Should a JIRA be opened for that or is
there an existing JIRA?

>
> > +
> > +        /**
> > +           Only the NOT_SUPPORTED and REQUIRED transaction
> > attributes may be used for message-driven
> > +           bean message listener methods. The use of the other
> > transaction attributes is not meaningful
> > +           for message-driven bean message listener methods
> > because there is no pre-existing client transaction
> > +           context(REQUIRES_NEW, SUPPORTS) and no client to handle
> > exceptions (MANDATORY, NEVER).
> > +         */
> > +        if (componentType.isMessageDriven() && !
> > isBeanManagedTransaction && container instanceof
> > TransactionContainer) {
> > +            if (policy.policyType != policy.NotSupported &&
> > policy.policyType != policy.Required) {
> > +                if (method.equals(this.ejbTimeout) &&
> > policy.policyType == policy.RequiresNew) {
> > +                    // do nothing. This is allowed as the timer
> > callback method for a message driven bean
> > +                    // can also have a transaction policy of
> > RequiresNew Sec 5.4.12 of Ejb 3.0 Core Spec
> > +                } else {
> > +                    throw new OpenEJBException("The transaction
> > attribute " + policy.policyToString() + "is not supported for the
> > method "
> > +                                               + method.getName()
> > + " of the Message Driven Bean " + beanClass.getName());
> > +                }
> > +            }
> > +        }
>
> We should add this check to the verifier.  Also it would be helpful
> to explicitly say in the exception message that only NotSupported and
> Required are allowed.
Ok but I am a bit hazy about how validation takes place. A pointer on
where to look or how validation is done will be nice :). Also it would
be nice if we have a framework for exception handling where we can
give error codes in the exceptions and the messages will be picked up
from a property file or something like that. That way error message
changes won't need code changes

>
> BTW, have you tried sending a message through the container yet?
>
Yes I have tried a basic case where the onMessage gets called and also
the transaction related interceptor methods. Not yet tried testing
Transaction rollback etc. It will be helpful if we can have the
embedded AMQ service for the Tests as well so that we can start
writing Test cases for the MDB container.

> Very good work!
Thanks
>
> -dain
>
>
>

Patch for JIRA 430

Posted by Dain Sundstrom <da...@iq80.com>.
I was just reading over the commit logs and noticed this patch to the  
MDB code.  I'd like to echo everyone else's comments that is is very  
high quality work, and I am excited to see that MDBs deploy now.  I  
have some specific comments below...


> ====================================================================== 
> ========
> --- incubator/openejb/trunk/openejb3/container/openejb-core/src/ 
> main/java/org/apache/openejb/core/CoreDeploymentInfo.java (original)
> +++ incubator/openejb/trunk/openejb3/container/openejb-core/src/ 
> main/java/org/apache/openejb/core/CoreDeploymentInfo.java Wed Jan   
> 3 22:06:16 2007
> @@ -173,6 +177,13 @@
>                  throw new SystemException(e);
>              }
>          }
> +        if (TimedObject.class.isAssignableFrom(beanClass)) {
> +            try {
> +                this.ejbTimeout = beanClass.getMethod("ejbTimeout");
> +            } catch (NoSuchMethodException e) {
> +                throw new IllegalStateException(e);
> +            }
> +        }
>      }

In EJB3 is there an annotation for Timeout?

> +
> +        /**
> +           Only the NOT_SUPPORTED and REQUIRED transaction  
> attributes may be used for message-driven
> +           bean message listener methods. The use of the other  
> transaction attributes is not meaningful
> +           for message-driven bean message listener methods  
> because there is no pre-existing client transaction
> +           context(REQUIRES_NEW, SUPPORTS) and no client to handle  
> exceptions (MANDATORY, NEVER).
> +         */
> +        if (componentType.isMessageDriven() && ! 
> isBeanManagedTransaction && container instanceof  
> TransactionContainer) {
> +            if (policy.policyType != policy.NotSupported &&  
> policy.policyType != policy.Required) {
> +                if (method.equals(this.ejbTimeout) &&  
> policy.policyType == policy.RequiresNew) {
> +                    // do nothing. This is allowed as the timer  
> callback method for a message driven bean
> +                    // can also have a transaction policy of  
> RequiresNew Sec 5.4.12 of Ejb 3.0 Core Spec
> +                } else {
> +                    throw new OpenEJBException("The transaction  
> attribute " + policy.policyToString() + "is not supported for the  
> method "
> +                                               + method.getName()  
> + " of the Message Driven Bean " + beanClass.getName());
> +                }
> +            }
> +        }

We should add this check to the verifier.  Also it would be helpful  
to explicitly say in the exception message that only NotSupported and  
Required are allowed.

BTW, have you tried sending a message through the container yet?

Very good work!

-dain