[jboss-cvs] JBossAS SVN: r105858 - in projects/ejb3/trunk/core: src/main/java/org/jboss/ejb3/mdb and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jun 9 08:20:32 EDT 2010


Author: jaikiran
Date: 2010-06-09 08:20:31 -0400 (Wed, 09 Jun 2010)
New Revision: 105858

Modified:
   projects/ejb3/trunk/core/pom.xml
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingContainer.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java
Log:
EJBTHREE-2109 Upgrade to latest timerservice-spi and implement the new interface method

Modified: projects/ejb3/trunk/core/pom.xml
===================================================================
--- projects/ejb3/trunk/core/pom.xml	2010-06-09 12:09:30 UTC (rev 105857)
+++ projects/ejb3/trunk/core/pom.xml	2010-06-09 12:20:31 UTC (rev 105858)
@@ -399,7 +399,7 @@
     <dependency>
       <groupId>org.jboss.ejb3</groupId>
       <artifactId>jboss-ejb3-timerservice-spi</artifactId>
-      <version>1.0.0</version>
+      <version>1.0.1</version>
     </dependency>
 
     <dependency>

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingContainer.java	2010-06-09 12:09:30 UTC (rev 105857)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingContainer.java	2010-06-09 12:20:31 UTC (rev 105858)
@@ -21,6 +21,7 @@
  */
 package org.jboss.ejb3.mdb;
 
+import java.io.Serializable;
 import java.lang.reflect.Method;
 import java.util.Hashtable;
 import java.util.Map;
@@ -48,6 +49,7 @@
 import org.jboss.ejb3.jms.JMSDestinationFactory;
 import org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory;
 import org.jboss.ejb3.proxy.factory.ProxyFactoryHelper;
+import org.jboss.ejb3.timerservice.spi.MultiTimeoutMethodTimedObjectInvoker;
 import org.jboss.ejb3.timerservice.spi.TimedObjectInvoker;
 import org.jboss.jms.jndi.JMSProviderAdapter;
 import org.jboss.logging.Logger;
@@ -59,7 +61,7 @@
  * @version <tt>$Revision$</tt>
  * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
  */
-public abstract class MessagingContainer extends TimerServiceContainer implements TimedObjectInvoker
+public abstract class MessagingContainer extends TimerServiceContainer implements MultiTimeoutMethodTimedObjectInvoker
 {
    private static final Logger log = Logger.getLogger(MessagingContainer.class);
    
@@ -280,22 +282,13 @@
       }
    }
 
-   
+   @Override
    public void callTimeout(Timer timer) throws Exception
    {
+      // the method annotated with @Timeout or it's xml equivalent
       if (timeout == null) throw new EJBException("No method has been annotated with @Timeout");
-      Object[] args = {timer};
-      if(timeout.getParameterTypes().length == 0)
-         args = null;
-      try
-      {
-         localInvoke(timeout, args);
-      }
-      catch (Throwable throwable)
-      {
-         if (throwable instanceof Exception) throw (Exception) throwable;
-         throw new RuntimeException(throwable);
-      }
+      // call the timeout method
+      this.callTimeout(timer, this.timeout);
    }
 
    @Override
@@ -639,4 +632,74 @@
       return this;
    }
    
+   /**
+    * {@inheritDoc}
+    * 
+    * @throws IllegalArgumentException If the passed <code>timeoutMethodName</code> or <code>timer</code> is null
+    */
+   @Override
+   public void callTimeout(Timer timer, String timeoutMethodName, String[] timeoutMethodParams) throws Exception
+   {
+      if (timer == null)
+      {
+         throw new IllegalArgumentException("Timer instance is null on callTimeout");
+      }
+      if (timeoutMethodName == null)
+      {
+         throw new IllegalArgumentException("Timeout method name is null on callTimeout");
+      }
+      // load the method param classes
+      Class<?>[] methodParams = null;
+      if (timeoutMethodParams != null)
+      {
+         methodParams = new Class<?>[timeoutMethodParams.length];
+         int i = 0;
+         for (String param : timeoutMethodParams)
+         {
+            Class<?> methodParam = this.classloader.loadClass(param);
+            methodParams[i++] = methodParam;
+         }
+      }
+      Method autoTimeoutMethod = null;
+      try
+      {
+         // NOTE: We do *not* do any semantic validations on the timeout method. 
+         // Any relevant validations should be done outside the container during metadata
+         // creation stage.
+         autoTimeoutMethod = this.getBeanClass().getMethod(timeoutMethodName, methodParams);
+      }
+      catch (NoSuchMethodException nsme)
+      {
+         log.error("Timeout method not found for bean " + this.getEjbName() + " for timer " + timer);
+         throw nsme;
+      }
+
+      // call the timeout method
+      this.callTimeout(timer, autoTimeoutMethod);
+      
+   }
+   
+   /**
+    * Invokes the passed timeout method for the passed {@link Timer}, on a bean instance.
+    * 
+    * @param timer The {@link Timer} for which the timeout has occurred 
+    * @param tMethod The timeout method
+    * @throws Exception If any exception occurs during invocation of timeout method on the target bean
+    * @throws {@link NullPointerException} If the passed <code>tMethod</code> is null
+    */
+   private void callTimeout(Timer timer, Method tMethod) throws Exception
+   {
+      Object[] args = {timer};
+      if(tMethod.getParameterTypes().length == 0)
+         args = null;
+      try
+      {
+         localInvoke(tMethod, args);
+      }
+      catch (Throwable throwable)
+      {
+         if (throwable instanceof Exception) throw (Exception) throwable;
+         throw new RuntimeException(throwable);
+      }
+   }
 }
\ No newline at end of file

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java	2010-06-09 12:09:30 UTC (rev 105857)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java	2010-06-09 12:20:31 UTC (rev 105858)
@@ -72,6 +72,7 @@
 import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.ejb3.session.SessionContainerInvocation;
 import org.jboss.ejb3.session.SessionSpecContainer;
+import org.jboss.ejb3.timerservice.spi.MultiTimeoutMethodTimedObjectInvoker;
 import org.jboss.ejb3.timerservice.spi.TimedObjectInvoker;
 import org.jboss.ejb3.timerservice.spi.TimerServiceFactory;
 import org.jboss.ejb3.util.CollectionHelper;
@@ -99,7 +100,7 @@
  * @version $Revision$
  */
 public class StatelessContainer extends SessionSpecContainer
-  implements TimedObjectInvoker, ServiceEndpointContainer, InvokableContext
+  implements MultiTimeoutMethodTimedObjectInvoker, ServiceEndpointContainer, InvokableContext
 {
    private static final Logger log = Logger.getLogger(StatelessContainer.class);
 
@@ -184,39 +185,17 @@
       this.timeout = getTimeoutCallback(timeoutMethodMetaData, getBeanClass());
    }
    
-   
+   /**
+    * {@inheritDoc}
+    */
+   @Override
    public void callTimeout(Timer timer) throws Exception
    {
+      // the method annotated with @Timeout or it's xml equivalent
       if (timeout == null) throw new EJBException("No method has been annotated with @Timeout");
-      Object[] args = {timer};
-      if(timeout.getParameterTypes().length == 0)
-         args = null;      
-      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
-      try
-      {
-         AllowedOperationsAssociation.pushInMethodFlag(AllowedOperationsFlags.IN_EJB_TIMEOUT);
-         try
-         {
-            MethodInfo info = super.getMethodInfo(timeout);
-            EJBContainerInvocation nextInvocation = new SessionContainerInvocation(null, info);
-            nextInvocation.setAdvisor(getAdvisor());
-            nextInvocation.setArguments(args);
-            nextInvocation.invokeNext();
-         }
-         catch (Throwable throwable)
-         {
-            if (throwable instanceof Exception) throw (Exception) throwable;
-            throw new RuntimeException(throwable);
-         }
-         finally
-         {
-            AllowedOperationsAssociation.popInMethodFlag();
-         }
-      }
-      finally
-      {
-         Thread.currentThread().setContextClassLoader(oldLoader);
-      }
+      
+      // call the timeout method
+      this.callTimeout(timer, timeout);
    }
 
    /**
@@ -661,6 +640,95 @@
       return this;
    }
    
+   /**
+    * {@inheritDoc}
+    * 
+    * @throws IllegalArgumentException If the passed <code>timeoutMethodName</code> or <code>timer</code> is null
+    */
+   @Override
+   public void callTimeout(Timer timer, String timeoutMethodName, String[] timeoutMethodParams) throws Exception
+   {
+      if (timer == null)
+      {
+         throw new IllegalArgumentException("Timer instance is null on callTimeout");
+      }
+      if (timeoutMethodName == null)
+      {
+         throw new IllegalArgumentException("Timeout method name is null on callTimeout");
+      }
+      // load the method param classes
+      Class<?>[] methodParams = null;
+      if (timeoutMethodParams != null)
+      {
+         methodParams = new Class<?>[timeoutMethodParams.length];
+         int i = 0;
+         for (String param : timeoutMethodParams)
+         {
+            Class<?> methodParam = this.classloader.loadClass(param);
+            methodParams[i++] = methodParam;
+         }
+      }
+      Method autoTimeoutMethod = null;
+      try
+      {
+         // NOTE: We do *not* do any semantic validations on the timeout method. 
+         // Any relevant validations should be done outside the container during metadata
+         // creation stage.
+         autoTimeoutMethod = this.getBeanClass().getMethod(timeoutMethodName, methodParams);
+      }
+      catch (NoSuchMethodException nsme)
+      {
+         log.error("Timeout method not found for bean " + this.getEjbName() + " for timer " + timer);
+         throw nsme;
+      }
+      // call the timeout method
+      this.callTimeout(timer, autoTimeoutMethod);
+      
+   }
+   
+   /**
+    * Invokes the passed timeout method for the passed {@link Timer}, on a bean instance.
+    * 
+    * @param timer The {@link Timer} for which the timeout has occurred 
+    * @param tMethod The timeout method
+    * @throws Exception If any exception occurs during invocation of timeout method on the target bean
+    * @throws {@link NullPointerException} If the passed <code>tMethod</code> is null
+    */
+   private void callTimeout(Timer timer, Method tMethod) throws Exception
+   {
+      Object[] args =
+      {timer};
+      if (tMethod.getParameterTypes().length == 0)
+         args = null;
+      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+      try
+      {
+         AllowedOperationsAssociation.pushInMethodFlag(AllowedOperationsFlags.IN_EJB_TIMEOUT);
+         try
+         {
+            MethodInfo info = super.getMethodInfo(tMethod);
+            EJBContainerInvocation nextInvocation = new SessionContainerInvocation(null, info);
+            nextInvocation.setAdvisor(getAdvisor());
+            nextInvocation.setArguments(args);
+            nextInvocation.invokeNext();
+         }
+         catch (Throwable throwable)
+         {
+            if (throwable instanceof Exception)
+               throw (Exception) throwable;
+            throw new RuntimeException(throwable);
+         }
+         finally
+         {
+            AllowedOperationsAssociation.popInMethodFlag();
+         }
+      }
+      finally
+      {
+         Thread.currentThread().setContextClassLoader(oldLoader);
+      }
+   }   
+   
    static class WSCallbackImpl implements BeanContextLifecycleCallback
    {
       private ExtensibleWebServiceContext jaxwsContext;



More information about the jboss-cvs-commits mailing list