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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 24 06:56:24 EST 2010


Author: wolfc
Date: 2010-02-24 06:56:23 -0500 (Wed, 24 Feb 2010)
New Revision: 101386

Added:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/util/Service.java
Modified:
   projects/ejb3/trunk/core/pom.xml
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingContainer.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceContainer.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java
Log:
EJBTHREE-2017: integrate jboss-ejb3-timeout

Modified: projects/ejb3/trunk/core/pom.xml
===================================================================
--- projects/ejb3/trunk/core/pom.xml	2010-02-24 11:55:11 UTC (rev 101385)
+++ projects/ejb3/trunk/core/pom.xml	2010-02-24 11:56:23 UTC (rev 101386)
@@ -457,6 +457,19 @@
     </dependency>
 
     <dependency>
+      <groupId>org.jboss.ejb3.timeout</groupId>
+      <artifactId>jboss-ejb3-timeout-spi</artifactId>
+      <version>0.1.1</version>
+    </dependency>
+
+     <dependency>
+       <groupId>org.jboss.ejb3.timeout</groupId>
+       <artifactId>jboss-ejb3-timeout-3.0</artifactId>
+       <version>0.1.1</version>
+       <scope>test</scope>
+     </dependency>
+
+    <dependency>
       <groupId>org.jboss.embedded</groupId>
       <artifactId>jboss-embedded</artifactId>
       <version>beta3</version>

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java	2010-02-24 11:55:11 UTC (rev 101385)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java	2010-02-24 11:56:23 UTC (rev 101386)
@@ -21,44 +21,6 @@
  */
 package org.jboss.ejb3;
 
-import java.lang.annotation.Annotation;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.ejb.EJBContext;
-import javax.ejb.EJBException;
-import javax.ejb.Local;
-import javax.ejb.Remote;
-import javax.ejb.TimedObject;
-import javax.ejb.Timeout;
-import javax.ejb.Timer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.LinkRef;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-import javax.naming.Reference;
-import javax.naming.StringRefAddr;
-import javax.transaction.TransactionManager;
-
 import org.jboss.aop.Advisor;
 import org.jboss.aop.Domain;
 import org.jboss.aop.MethodInfo;
@@ -90,20 +52,10 @@
 import org.jboss.ejb3.proxy.factory.ProxyFactoryHelper;
 import org.jboss.ejb3.security.SecurityDomainManager;
 import org.jboss.ejb3.statistics.InvocationStatistics;
+import org.jboss.ejb3.timeout.spi.TimeoutMethodCallbackRequirements;
 import org.jboss.ejb3.tx.UserTransactionImpl;
-import org.jboss.injection.DependsHandler;
-import org.jboss.injection.EJBHandler;
-import org.jboss.injection.EJBInjectionContainer;
-import org.jboss.injection.EncInjector;
-import org.jboss.injection.ExtendedInjectionContainer;
-import org.jboss.injection.InjectionHandler;
-import org.jboss.injection.InjectionUtil;
-import org.jboss.injection.Injector;
-import org.jboss.injection.JndiInjectHandler;
-import org.jboss.injection.PersistenceContextHandler;
-import org.jboss.injection.PersistenceUnitHandler;
-import org.jboss.injection.ResourceHandler;
-import org.jboss.injection.WebServiceRefHandler;
+import org.jboss.ejb3.util.Service;
+import org.jboss.injection.*;
 import org.jboss.jca.spi.ComponentStack;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.ejb.jboss.JBossAssemblyDescriptorMetaData;
@@ -118,6 +70,27 @@
 import org.jboss.util.naming.Util;
 import org.jboss.virtual.VirtualFile;
 
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ejb.*;
+import javax.ejb.Timer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.naming.*;
+import javax.transaction.TransactionManager;
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.*;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+
 /**
  * Comment
  *
@@ -131,6 +104,8 @@
 {
    private static final Logger log = Logger.getLogger(EJBContainer.class);
 
+   private static TimeoutMethodCallbackRequirements timeoutMethodCallbackRequirements = Service.loadService(TimeoutMethodCallbackRequirements.class);
+
    private String name;
    
    private BeanContainer beanContainer;
@@ -1028,42 +1003,22 @@
    
    protected Method getTimeoutCallback(NamedMethodMetaData timeoutMethodMetaData, Class<?> beanClass)
    {
+      String methodName = null;
       JBossEnterpriseBeanMetaData metaData = xml;
       if(metaData != null)
       {
          if(timeoutMethodMetaData != null)
          {
-            String methodName = timeoutMethodMetaData.getMethodName();
-            try
-            {
-               return beanClass.getMethod(methodName, Timer.class);
-            }
-            catch (SecurityException e)
-            {
-               throw new RuntimeException(e);
-            }
-            catch (NoSuchMethodException e)
-            {
-               throw new RuntimeException("No method " + methodName + "(javax.ejb.Timer timer) found on bean " + ejbName, e);
-            }
+            methodName = timeoutMethodMetaData.getMethodName();
          }
       }
       
-      if(TimedObject.class.isAssignableFrom(beanClass))
-      {
-         try
-         {
-            return TimedObject.class.getMethod("ejbTimeout", Timer.class);
-         }
-         catch (SecurityException e)
-         {
-            throw new RuntimeException(e);
-         }
-         catch (NoSuchMethodException e)
-         {
-            throw new RuntimeException(e);
-         }
-      }
+      Method timeoutMethod = timeoutMethodCallbackRequirements.getTimeoutMethod(beanClass, methodName);
+      if(timeoutMethod != null)
+         return timeoutMethod;
+
+      // TODO: should not be needed
+      // TODO: ServiceContainer does not container correct metadata
       
       if(metaData != null)
       {  
@@ -1082,6 +1037,7 @@
                   method.getParameterTypes()[0].equals(Timer.class))
             {
                // TODO: check for multiples
+               log.warn("EJBTHREE-2017: found a timeout method using legacy annotation scan (bug in JBMETA)");
                return method;
             }
             else

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-02-24 11:55:11 UTC (rev 101385)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingContainer.java	2010-02-24 11:56:23 UTC (rev 101386)
@@ -21,31 +21,11 @@
  */
 package org.jboss.ejb3.mdb;
 
-import java.lang.reflect.Method;
-import java.util.Hashtable;
-import java.util.Map;
-
-import javax.ejb.ActivationConfigProperty;
-import javax.ejb.EJBException;
-import javax.ejb.Timer;
-import javax.ejb.TimerService;
-import javax.jms.Destination;
-import javax.jms.Queue;
-import javax.jms.Topic;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import javax.naming.Context;
-import javax.naming.NamingException;
-
 import org.jboss.aop.Domain;
 import org.jboss.aop.MethodInfo;
 import org.jboss.beans.metadata.api.annotations.Inject;
 import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.ejb3.BeanContext;
-import org.jboss.ejb3.EJBContainer;
-import org.jboss.ejb3.EJBContainerInvocation;
-import org.jboss.ejb3.Ejb3Deployment;
-import org.jboss.ejb3.Ejb3Module;
+import org.jboss.ejb3.*;
 import org.jboss.ejb3.annotation.ResourceAdapter;
 import org.jboss.ejb3.jms.JMSDestinationFactory;
 import org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory;
@@ -58,6 +38,21 @@
 import org.jboss.metadata.ejb.spec.ActivationConfigPropertyMetaData;
 import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
 
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.EJBException;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+import javax.jms.Destination;
+import javax.jms.Queue;
+import javax.jms.Topic;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import java.lang.reflect.Method;
+import java.util.Hashtable;
+import java.util.Map;
+
 /**
  * @version <tt>$Revision$</tt>
  * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
@@ -303,6 +298,8 @@
    {
       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);

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceContainer.java	2010-02-24 11:55:11 UTC (rev 101385)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceContainer.java	2010-02-24 11:56:23 UTC (rev 101386)
@@ -130,8 +130,9 @@
    {
       if (timeoutMethod == null)
          throw new EJBException("No method has been annotated with @Timeout");
-      Object[] args =
-      {timer};
+      Object[] args = { timer };
+      if(timeoutMethod.getParameterTypes().length == 0)
+         args = null;
       AllowedOperationsAssociation.pushInMethodFlag(AllowedOperationsFlags.IN_EJB_TIMEOUT);
       try
       {

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-02-24 11:55:11 UTC (rev 101385)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java	2010-02-24 11:56:23 UTC (rev 101386)
@@ -253,6 +253,8 @@
    {
       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
       {

Added: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/util/Service.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/util/Service.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/util/Service.java	2010-02-24 11:56:23 UTC (rev 101386)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.util;
+
+import javax.imageio.spi.ServiceRegistry;
+import java.util.Iterator;
+
+/**
+ * A wrapper around ServiceRegistry.
+ * 
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class Service
+{
+   public static <T> T loadService(Class<T> providerClass)
+   {
+      Iterator i = ServiceRegistry.lookupProviders(providerClass);
+      if(!i.hasNext())
+         throw new IllegalStateException("No service found for " + providerClass);
+      T service = providerClass.cast(i.next());
+      if(i.hasNext())
+         throw new IllegalStateException("More than 1 service found for " + providerClass);
+      return service;
+   }
+}


Property changes on: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/util/Service.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native




More information about the jboss-cvs-commits mailing list