[jboss-cvs] JBossAS SVN: r106195 - in projects/ejb3/trunk/timerservice-deployer: src/main/java/org/jboss/ejb3/timerservice/deployer and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jun 21 08:12:05 EDT 2010


Author: jaikiran
Date: 2010-06-21 08:12:05 -0400 (Mon, 21 Jun 2010)
New Revision: 106195

Modified:
   projects/ejb3/trunk/timerservice-deployer/pom.xml
   projects/ejb3/trunk/timerservice-deployer/src/main/java/org/jboss/ejb3/timerservice/deployer/AutoTimerInitializer.java
   projects/ejb3/trunk/timerservice-deployer/src/main/java/org/jboss/ejb3/timerservice/deployer/TimerServiceDeployer.java
Log:
Upgrade to latest version jboss-ejb3-timerservice

Modified: projects/ejb3/trunk/timerservice-deployer/pom.xml
===================================================================
--- projects/ejb3/trunk/timerservice-deployer/pom.xml	2010-06-21 11:14:00 UTC (rev 106194)
+++ projects/ejb3/trunk/timerservice-deployer/pom.xml	2010-06-21 12:12:05 UTC (rev 106195)
@@ -4,13 +4,6 @@
     -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
-	<parent>
-		<groupId>org.jboss</groupId>
-		<artifactId>jboss-parent</artifactId>
-		<version>5</version>
-	</parent>
-    
-    
     <!-- Model Information -->
     <modelVersion>4.0.0</modelVersion>
 
@@ -29,14 +22,29 @@
 		<developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/ejb3/trunk/timerservice-deployer</developerConnection>
 		<url>http://anonsvn.jboss.org/repos/jbossas/projects/ejb3/trunk/timerservice-deployer</url>
 	</scm>
+
+	<distributionManagement>
+			<repository>
+			  <id>jboss-releases-repository</id>
+			  <name>JBoss Releases Repository</name>
+			  <url>https://repository.jboss.org/nexus/service/local/staging/deploy/maven2/</url>
+			</repository>
+
+			<snapshotRepository>
+				<id>jboss-snapshots-repository</id>
+				<name>JBoss Snapshots Repository</name>
+				<url>https://repository.jboss.org/nexus/content/repositories/snapshots/</url>
+			</snapshotRepository>			
+	</distributionManagement>  
+
     
     
     <properties>
         <version.org.jboss.deployers>2.2.0.Alpha5</version.org.jboss.deployers>
         <version.org.jboss.kernel>2.2.0.Alpha10</version.org.jboss.kernel>
-        <version.org.jboss.ejb3.core>1.4.1</version.org.jboss.ejb3.core>
+        <version.org.jboss.ejb3.core>1.4.2</version.org.jboss.ejb3.core>
         <version.org.jboss.ejb.metadata>2.0.0-alpha-16</version.org.jboss.ejb.metadata>
-        <version.org.jboss.ejb3.timerservice_timerservice-extension>1.0.0-alpha-1</version.org.jboss.ejb3.timerservice_timerservice-extension>
+        <version.org.jboss.ejb3.timerservice_timerservice-extension>1.0.0-alpha-2</version.org.jboss.ejb3.timerservice_timerservice-extension>
         <version.junit>4.7</version.junit>
     </properties>
     

Modified: projects/ejb3/trunk/timerservice-deployer/src/main/java/org/jboss/ejb3/timerservice/deployer/AutoTimerInitializer.java
===================================================================
--- projects/ejb3/trunk/timerservice-deployer/src/main/java/org/jboss/ejb3/timerservice/deployer/AutoTimerInitializer.java	2010-06-21 11:14:00 UTC (rev 106194)
+++ projects/ejb3/trunk/timerservice-deployer/src/main/java/org/jboss/ejb3/timerservice/deployer/AutoTimerInitializer.java	2010-06-21 12:12:05 UTC (rev 106195)
@@ -21,6 +21,7 @@
  */
 package org.jboss.ejb3.timerservice.deployer;
 
+import java.lang.reflect.Method;
 import java.util.List;
 
 import javax.ejb.TimerConfig;
@@ -28,42 +29,73 @@
 
 import org.jboss.beans.metadata.api.annotations.Start;
 import org.jboss.ejb3.EJBContainer;
+import org.jboss.logging.Logger;
 import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
 import org.jboss.metadata.ejb.jboss.JBossMessageDrivenBean31MetaData;
 import org.jboss.metadata.ejb.jboss.JBossSessionBean31MetaData;
 import org.jboss.metadata.ejb.spec.MethodParametersMetaData;
+import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
 import org.jboss.metadata.ejb.spec.TimerMetaData;
 
 /**
- * TimerServiceBootstrap
+ * Responsible for creating any necessary auto timers for an EJB
  *
  * @author Jaikiran Pai
  * @version $Revision: $
  */
 public class AutoTimerInitializer
 {
+
+   /**
+    * Logger
+    */
+   private static Logger logger = Logger.getLogger(AutoTimerInitializer.class);
+
+   /**
+    * The EJB container
+    */
    private EJBContainer container;
 
+   /**
+    * 
+    */
    public AutoTimerInitializer()
    {
 
    }
 
+   /**
+    * Creates a {@link AutoTimerInitializer} for a {@link EJBContainer}
+    * @param container {@link EJBContainer}
+    */
    public AutoTimerInitializer(EJBContainer container)
    {
       this.container = container;
    }
 
+   /**
+    * Sets the {@link EJBContainer}
+    * @param container {@link EJBContainer}
+    */
    public void setContainer(EJBContainer container)
    {
       this.container = container;
    }
 
+   /**
+    * Returns the {@link EJBContainer} for which this {@link AutoTimerInitializer} is responsible
+    * for creating auto timers
+    * @return
+    */
    public EJBContainer getContainer()
    {
       return this.container;
    }
 
+   /**
+    * Creates any auto timers that are required for the {@link EJBContainer}, which this
+    * {@link AutoTimerInitializer} represents.
+    */
    @Start
    public void initializeAutoTimers()
    {
@@ -73,55 +105,130 @@
       }
 
       JBossEnterpriseBeanMetaData enterpriseBeanMetaData = this.container.getXml();
+      // Auto timers are only since EJB3.1
+      // TODO: This check will fail when EJB3.2 or any newer versions are introduced.
+      // A better check would be to look for any version greater than EJB3.1
       if (enterpriseBeanMetaData.getJBossMetaData().isEJB31() == false)
       {
          return;
       }
+
       List<TimerMetaData> autoTimersMetaData = null;
+
       if (enterpriseBeanMetaData.isSession())
       {
          JBossSessionBean31MetaData sessionBean = (JBossSessionBean31MetaData) enterpriseBeanMetaData;
+         // Stateful beans don't have timerservice/timers
          if (sessionBean.isStateful())
          {
             return;
          }
+         // Get hold of the auto timer metadata
          autoTimersMetaData = sessionBean.getTimers();
       }
       else if (enterpriseBeanMetaData.isMessageDriven())
       {
          JBossMessageDrivenBean31MetaData mdb = (JBossMessageDrivenBean31MetaData) enterpriseBeanMetaData;
+         // get hold of auto timer metadata
          autoTimersMetaData = mdb.getTimers();
       }
-
+      // If there's no auto timers, then there's nothing to do
       if (autoTimersMetaData == null)
       {
          return;
       }
+
+      // get hold of the timerservice since we need it to create the autotimers
       TimerService timerService = this.container.getTimerService();
 
       if (timerService instanceof org.jboss.ejb3.timerservice.extension.TimerService == false)
       {
          // can't do anything about this
+         logger.warn("Cannot create auto timers for EJB: " + enterpriseBeanMetaData.getEjbName()
+               + " since the timerservice isn't of type "
+               + org.jboss.ejb3.timerservice.extension.TimerService.class.getName());
          return;
       }
       org.jboss.ejb3.timerservice.extension.TimerService ejb31TimerService = (org.jboss.ejb3.timerservice.extension.TimerService) timerService;
+      // process each auto timer
       for (TimerMetaData autoTimerMetaData : autoTimersMetaData)
       {
+         // create a timer config
          TimerConfig timerConfig = new TimerConfig();
          timerConfig.setPersistent(autoTimerMetaData.isPersistent());
          timerConfig.setInfo(autoTimerMetaData.getInfo());
+         // get hold of the timeout method for this auto-timer
+         Method timeoutMethod = this.getTimeoutMethod(autoTimerMetaData.getTimeoutMethod(), this.container
+               .getBeanClass());
+         // finally create/get the auto timer
+         ejb31TimerService.getAutoTimer(autoTimerMetaData.getScheduleExpression(), timerConfig, timeoutMethod);
+      }
 
-         String timeoutMethodName = autoTimerMetaData.getTimeoutMethod().getMethodName();
-         MethodParametersMetaData methodParams = autoTimerMetaData.getTimeoutMethod().getMethodParams();
-         String[] timeoutMethodParams = null;
-         if (methodParams != null)
+   }
+
+   /**
+    * Returns the {@link Method}, represented by the {@link NamedMethodMetaData}, from the <code>beanClass</code>
+    * <p>
+    *   This method looks for private, protected, package and public methods on the <code>beanClass</code>
+    *   and its superclass(es). If no matching method is found, then this method returns null.
+    * </p>
+    * @param timeoutMethodMetaData The method metadata
+    * @param beanClass The class on which the method has to be looked for
+    * @return
+    * @throws NullPointerException If either of the passed parameters is null
+    */
+   private Method getTimeoutMethod(NamedMethodMetaData timeoutMethodMetaData, Class<?> beanClass)
+   {
+
+      String timeoutMethodName = timeoutMethodMetaData.getMethodName();
+      MethodParametersMetaData timeoutMethodParams = timeoutMethodMetaData.getMethodParams();
+      // load the method param classes
+      Class<?>[] timeoutMethodParamTypes = new Class<?>[]
+      {};
+      if (timeoutMethodParams != null)
+      {
+         timeoutMethodParamTypes = new Class<?>[timeoutMethodParams.size()];
+         int i = 0;
+         for (String paramClassName : timeoutMethodParams)
          {
-            timeoutMethodParams = methodParams.toArray(new String[methodParams.size()]);
+            Class<?> methodParamClass = null;
+            try
+            {
+               methodParamClass = Class.forName(paramClassName, false, beanClass.getClassLoader());
+            }
+            catch (ClassNotFoundException cnfe)
+            {
+               throw new RuntimeException("Could not load method param class: " + paramClassName + " of timeout method");
+            }
+            timeoutMethodParamTypes[i++] = methodParamClass;
          }
-         ejb31TimerService.getAutoTimer(autoTimerMetaData.getScheduleExpression(), timerConfig, timeoutMethodName,
-               timeoutMethodParams);
       }
-
+      // now start looking for the method
+      Method[] methods = beanClass.getMethods();
+      for (Method method : methods)
+      {
+         if (method.getName().equals(timeoutMethodName))
+         {
+            Class<?>[] methodParamTypes = method.getParameterTypes();
+            // param length doesn't match
+            if (timeoutMethodParamTypes.length != methodParamTypes.length)
+            {
+               continue;
+            }
+            for (int i = 0; i < methodParamTypes.length; i++)
+            {
+               // param type doesn't match
+               if (timeoutMethodParamTypes[i].equals(methodParamTypes[i]) == false)
+               {
+                  continue;
+               }
+            }
+            // match found
+            return method;
+         }
+      }
+      // no match found
+      return null;
    }
 
 }

Modified: projects/ejb3/trunk/timerservice-deployer/src/main/java/org/jboss/ejb3/timerservice/deployer/TimerServiceDeployer.java
===================================================================
--- projects/ejb3/trunk/timerservice-deployer/src/main/java/org/jboss/ejb3/timerservice/deployer/TimerServiceDeployer.java	2010-06-21 11:14:00 UTC (rev 106194)
+++ projects/ejb3/trunk/timerservice-deployer/src/main/java/org/jboss/ejb3/timerservice/deployer/TimerServiceDeployer.java	2010-06-21 12:12:05 UTC (rev 106195)
@@ -21,7 +21,6 @@
  */
 package org.jboss.ejb3.timerservice.deployer;
 
-
 import org.jboss.beans.metadata.plugins.AbstractInjectionValueMetaData;
 import org.jboss.beans.metadata.spi.BeanMetaData;
 import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
@@ -30,6 +29,7 @@
 import org.jboss.deployers.spi.deployer.DeploymentStages;
 import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.ejb3.EJBContainer;
 import org.jboss.ejb3.common.deployers.spi.AttachmentNames;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
@@ -38,7 +38,12 @@
 import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
 
 /**
- * TimerServiceDeployer
+ * A deployer which processing EJB3.1 bean metadata and creating {@link AutoTimerInitializer}
+ * for appropriate EJBs.
+ * <p>
+ *  Each such {@link AutoTimerInitializer} will be attached to the {@link DeploymentUnit} as a
+ *  {@link BeanMetaData} so that it's deployed as a MC bean.
+ * </p>
  *
  * @author Jaikiran Pai
  * @version $Revision: $
@@ -50,34 +55,44 @@
     * Logger
     */
    private Logger logger = Logger.getLogger(TimerServiceDeployer.class);
-   
-   private static final String MC_BEAN_PREFIX = "auto-timer-initializer:";
-   
+
+   /**
+    * MC bean name prefix
+    */
+   private static final String AUTO_TIMER_MC_BEAN_PREFIX = "auto-timer-initializer:";
+
+   /**
+    * Setup the deployer
+    */
    public TimerServiceDeployer()
    {
+      // run in REAL stage
       setStage(DeploymentStages.REAL);
+      // we need JBossMetaData
       setInput(JBossMetaData.class);
+      // ordering (i.e. this deployer should run after the deployer which attaches PROCESSED_METADATA to the unit) 
       addInput(AttachmentNames.PROCESSED_METADATA);
-      // we deploy MC beans
+      // we deploy MC bean(s)
       addOutput(BeanMetaData.class);
    }
 
+   /**
+    * For each EJB3.1 bean in this <code>unit</code>, this method creates a {@link AutoTimerInitializer} and attaches it
+    * as {@link BeanMetaData} to the <code>unit</code> 
+    */
    @Override
    public void deploy(DeploymentUnit unit) throws DeploymentException
    {
-      if (logger.isTraceEnabled())
-      {
-         logger.trace("Deploying unit " + unit.getName());
-      }
       // get processed metadata
       JBossMetaData metaData = unit.getAttachment(AttachmentNames.PROCESSED_METADATA, JBossMetaData.class);
       if (metaData == null)
       {
-         if (logger.isTraceEnabled())
-            logger.trace("No JBossMetadata for unit : " + unit.getName());
          return;
       }
-      if (metaData.isEJB3x() == false)
+      // Auto timers are only since EJB3.1
+      // TODO: This check will fail when EJB3.2 or any newer versions are introduced.
+      // A better check would be to look for any version greater than EJB3.1
+      if (metaData.isEJB31() == false)
       {
          return;
       }
@@ -88,37 +103,60 @@
          if (bean.isSession())
          {
             JBossSessionBeanMetaData sessionBean = (JBossSessionBeanMetaData) bean;
+            // stateful beans don't have timerservice/timers
             if (sessionBean.isStateful())
             {
                continue;
             }
          }
+         // ignore entity and (JBoss specific) @Service beans
          else if (bean.isEntity() || bean.isService())
          {
             continue;
          }
          // process
-         String mcBeanName = MC_BEAN_PREFIX + unit.getName() + "$" + bean.getEjbName();
+         String mcBeanName = AUTO_TIMER_MC_BEAN_PREFIX + unit.getName() + "$" + bean.getEjbName();
+         // create the BeanMetadata for the AutoTimerInitializer
          BeanMetaData bmd = this.createAutoTimerInitializer(mcBeanName, bean);
+         // add it as attachment
          unit.addAttachment(BeanMetaData.class + ":" + mcBeanName, bmd);
       }
    }
 
+   /**
+    * Returns {@link BeanMetaData} for a {@link AutoTimerInitializer} instance
+    * <p>
+    *   The MC bean for {@link AutoTimerInitializer} created by this method will be configured
+    *   to depend on the {@link ControllerState#INSTALLED} state of the MC bean corresponding
+    *   to the {@link EJBContainer}. The EJB container MC bean on which the {@link AutoTimerInitializer}
+    *   will depend, is obtained through {@link JBossEnterpriseBeanMetaData#getContainerName()}. 
+    * </p>  
+    * <p>
+    *   Furthermore, the MC bean for {@link AutoTimerInitializer} will be configured to inject
+    *   the {@link EJBContainer} into the {@link AutoTimerInitializer} instance
+    * </p>
+    * @param mcBeanName The name of the MC bean being created
+    * @param bean Bean metadata
+    * @return
+    */
    private BeanMetaData createAutoTimerInitializer(String mcBeanName, JBossEnterpriseBeanMetaData bean)
    {
       AutoTimerInitializer autoTimerInitializer = new AutoTimerInitializer();
-      
-      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(mcBeanName, autoTimerInitializer.getClass().getName());
+
+      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(mcBeanName, autoTimerInitializer.getClass()
+            .getName());
       builder.setConstructorValue(autoTimerInitializer);
 
-      // add dependency
+      // add dependency - the AutoTimerInitializer will depend on a INSTALLED state of EJBContainer
       AbstractInjectionValueMetaData injectMetaData = new AbstractInjectionValueMetaData(bean.getContainerName());
       injectMetaData.setDependentState(ControllerState.INSTALLED);
 
-      // Too bad we have to know the field name. Need to do more research on MC to see if we can
+      // TODO: Too bad we have to know the field name. Need to do more research on MC to see if we can
       // add property metadata based on type instead of field name.
+      // Add the injection point in AutoTimerInitializer to inject the EJBContainer
       builder.addPropertyMetaData("container", injectMetaData);
 
+      // return the BeanMetaData
       return builder.getBeanMetaData();
    }
 }



More information about the jboss-cvs-commits mailing list