[jboss-cvs] JBossAS SVN: r98964 - in projects/jboss-jca/trunk: fungal/src/main/java/org/jboss/jca/fungal/deployment and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Jan 2 11:17:56 EST 2010


Author: jesper.pedersen
Date: 2010-01-02 11:17:55 -0500 (Sat, 02 Jan 2010)
New Revision: 98964

Added:
   projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/InstallType.java
   projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/UninstallType.java
Modified:
   projects/jboss-jca/trunk/doc/developerguide/en/modules/fungal.xml
   projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/BeanType.java
   projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/Unmarshaller.java
   projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/BeanDeployment.java
   projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/DeploymentDeployer.java
   projects/jboss-jca/trunk/fungal/src/main/resources/deployment.xsd
Log:
[JBJCA-251] Support install/uninstall methods in deployment

Modified: projects/jboss-jca/trunk/doc/developerguide/en/modules/fungal.xml
===================================================================
--- projects/jboss-jca/trunk/doc/developerguide/en/modules/fungal.xml	2010-01-02 15:07:15 UTC (rev 98963)
+++ projects/jboss-jca/trunk/doc/developerguide/en/modules/fungal.xml	2010-01-02 16:17:55 UTC (rev 98964)
@@ -92,6 +92,14 @@
           <para>defines an explicit dependency to another bean.</para>
         </listitem>
         <listitem>
+          <code>&lt;install&gt;</code>
+          <para>defines an install method.</para>
+        </listitem>
+        <listitem>
+          <code>&lt;uninstall&gt;</code>
+          <para>defines an uninstall method.</para>
+        </listitem>
+        <listitem>
           <code>&lt;map&gt;</code>
           <para>defines a map data structure.</para>
         </listitem>
@@ -147,7 +155,7 @@
     <section id="fungal_lifecycle">
       <title>Lifecycle</title>
 
-      <para>There is basic support for lifecycle methods. These include</para>
+      <para>There is support for lifecycle methods. These include</para>
 
       <itemizedlist>
         <listitem>
@@ -167,6 +175,11 @@
           <para>Called after stop.</para>
         </listitem>
       </itemizedlist>
+
+      <para>Furthermore all <code>install</code> methods defined for the bean are called after the <code>start</code>
+        method. All <code>uninstall</code> methods defined for the bean are called before the <code>stop</code>
+        method.</para>
+
     </section>
 
     <section id="fungal_logging">

Modified: projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/BeanType.java
===================================================================
--- projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/BeanType.java	2010-01-02 15:07:15 UTC (rev 98963)
+++ projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/BeanType.java	2010-01-02 16:17:55 UTC (rev 98964)
@@ -33,6 +33,8 @@
    private ConstructorType constructor;
    private List<PropertyType> property;
    private List<DependsType> depends;
+   private List<InstallType> install;
+   private List<UninstallType> uninstall;
    private String name;
    private String interfaze;
    private String clazz;
@@ -93,6 +95,30 @@
    }
 
    /**
+    * Get the install values
+    * @return The value
+    */
+   public List<InstallType> getInstall()
+   {
+      if (install == null)
+         install = new ArrayList<InstallType>(1);
+
+      return install;
+   }
+
+   /**
+    * Get the uninstall values
+    * @return The value
+    */
+   public List<UninstallType> getUninstall()
+   {
+      if (uninstall == null)
+         uninstall = new ArrayList<UninstallType>(1);
+
+      return uninstall;
+   }
+
+   /**
     * Get the name
     * @return The value
     */

Added: projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/InstallType.java
===================================================================
--- projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/InstallType.java	                        (rev 0)
+++ projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/InstallType.java	2010-01-02 16:17:55 UTC (rev 98964)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jca.fungal.deployment;
+
+/**
+ * Represents an install element
+ */
+public class InstallType
+{
+   private String method;
+
+   /**
+    * Constructor
+    */
+   public InstallType()
+   {
+      method = null;
+   }
+
+   /**
+    * Get the method
+    * @return The value
+    */
+   public String getMethod()
+   {
+      return method;
+   }
+
+   /**
+    * Set the method
+    * @param value The value
+    */
+   public void setMethod(String value)
+   {
+      method = value;
+   }
+}

Added: projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/UninstallType.java
===================================================================
--- projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/UninstallType.java	                        (rev 0)
+++ projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/UninstallType.java	2010-01-02 16:17:55 UTC (rev 98964)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jca.fungal.deployment;
+
+/**
+ * Represents an uninstall element
+ */
+public class UninstallType
+{
+   private String method;
+
+   /**
+    * Constructor
+    */
+   public UninstallType()
+   {
+      method = null;
+   }
+
+   /**
+    * Get the method
+    * @return The value
+    */
+   public String getMethod()
+   {
+      return method;
+   }
+
+   /**
+    * Set the method
+    * @param value The value
+    */
+   public void setMethod(String value)
+   {
+      method = value;
+   }
+}

Modified: projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/Unmarshaller.java
===================================================================
--- projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/Unmarshaller.java	2010-01-02 15:07:15 UTC (rev 98963)
+++ projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/Unmarshaller.java	2010-01-02 16:17:55 UTC (rev 98964)
@@ -177,6 +177,14 @@
                {
                   result.getDepends().add(readDepends(xmlStreamReader));
                }
+               else if ("install".equals(name))
+               {
+                  result.getInstall().add(readInstall(xmlStreamReader));
+               }
+               else if ("uninstall".equals(name))
+               {
+                  result.getUninstall().add(readUninstall(xmlStreamReader));
+               }
 
                break;
             default :
@@ -422,6 +430,70 @@
    }
 
    /**
+    * Read: <install>
+    * @param xmlStreamReader The XML stream
+    * @return The install
+    * @exception XMLStreamException Thrown if an exception occurs
+    */
+   private InstallType readInstall(XMLStreamReader xmlStreamReader) throws XMLStreamException
+   {
+      InstallType result = new InstallType();
+
+      for (int i = 0; i < xmlStreamReader.getAttributeCount(); i++)
+      {
+         String name = xmlStreamReader.getAttributeLocalName(i);
+         if ("method".equals(name))
+         {
+            result.setMethod(xmlStreamReader.getAttributeValue(i));
+         }
+      }
+
+      int eventCode = xmlStreamReader.next();
+
+      while (eventCode != XMLStreamReader.END_ELEMENT)
+      {
+         eventCode = xmlStreamReader.next();
+      }
+
+      if (!"install".equals(xmlStreamReader.getLocalName()))
+         throw new XMLStreamException("install tag not completed");
+
+      return result;
+   }
+
+   /**
+    * Read: <uninstall>
+    * @param xmlStreamReader The XML stream
+    * @return The install
+    * @exception XMLStreamException Thrown if an exception occurs
+    */
+   private UninstallType readUninstall(XMLStreamReader xmlStreamReader) throws XMLStreamException
+   {
+      UninstallType result = new UninstallType();
+
+      for (int i = 0; i < xmlStreamReader.getAttributeCount(); i++)
+      {
+         String name = xmlStreamReader.getAttributeLocalName(i);
+         if ("method".equals(name))
+         {
+            result.setMethod(xmlStreamReader.getAttributeValue(i));
+         }
+      }
+
+      int eventCode = xmlStreamReader.next();
+
+      while (eventCode != XMLStreamReader.END_ELEMENT)
+      {
+         eventCode = xmlStreamReader.next();
+      }
+
+      if (!"uninstall".equals(xmlStreamReader.getLocalName()))
+         throw new XMLStreamException("uninstall tag not completed");
+
+      return result;
+   }
+
+   /**
     * Read: <map>
     * @param xmlStreamReader The XML stream
     * @return The map

Modified: projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/BeanDeployment.java
===================================================================
--- projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/BeanDeployment.java	2010-01-02 15:07:15 UTC (rev 98963)
+++ projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/BeanDeployment.java	2010-01-02 16:17:55 UTC (rev 98964)
@@ -31,6 +31,7 @@
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 /**
@@ -45,6 +46,9 @@
    /** The bean names */
    private List<String> beans;
 
+   /** Uninstall methods */
+   private Map<String, List<Method>> uninstall;
+
    /** The kernel */
    private KernelImpl kernel;
 
@@ -52,12 +56,29 @@
     * Constructor
     * @param deployment The deployment
     * @param beans The list of bean names for the deployment
+    * @param uninstall Uninstall methods for beans
     * @param kernel The kernel
     */
-   public BeanDeployment(URL deployment, List<String> beans, KernelImpl kernel)
+   public BeanDeployment(URL deployment, 
+                         List<String> beans, 
+                         Map<String, List<Method>> uninstall,
+                         KernelImpl kernel)
    {
+      if (deployment == null)
+         throw new IllegalArgumentException("Deployment is null");
+
+      if (beans == null)
+         throw new IllegalArgumentException("Beans is null");
+
+      if (uninstall == null)
+         throw new IllegalArgumentException("Uninstall is null");
+
+      if (kernel == null)
+         throw new IllegalArgumentException("Kernel is null");
+
       this.deployment = deployment;
       this.beans = beans;
+      this.uninstall = uninstall;
       this.kernel = kernel;
    }
 
@@ -122,6 +143,22 @@
 
          Object bean = kernel.getBean(name);
 
+         List<Method> l = uninstall.get(name);
+         if (l != null)
+         {
+            for (Method m : l)
+            {
+               try
+               {
+                  m.invoke(bean, (Object[])null);
+               }
+               catch (InvocationTargetException ite)
+               {
+                  throw ite.getTargetException();
+               }
+            }
+         }
+
          try
          {
             Method stopMethod = bean.getClass().getMethod("stop", (Class[])null);

Modified: projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/DeploymentDeployer.java
===================================================================
--- projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/DeploymentDeployer.java	2010-01-02 15:07:15 UTC (rev 98963)
+++ projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/DeploymentDeployer.java	2010-01-02 16:17:55 UTC (rev 98964)
@@ -31,6 +31,7 @@
 import org.jboss.jca.fungal.deployment.DependsType;
 import org.jboss.jca.fungal.deployment.EntryType;
 import org.jboss.jca.fungal.deployment.InjectType;
+import org.jboss.jca.fungal.deployment.InstallType;
 import org.jboss.jca.fungal.deployment.KeyType;
 import org.jboss.jca.fungal.deployment.ListType;
 import org.jboss.jca.fungal.deployment.MapType;
@@ -38,6 +39,7 @@
 import org.jboss.jca.fungal.deployment.PropertyType;
 import org.jboss.jca.fungal.deployment.SetType;
 import org.jboss.jca.fungal.deployment.ThisType;
+import org.jboss.jca.fungal.deployment.UninstallType;
 import org.jboss.jca.fungal.deployment.Unmarshaller;
 import org.jboss.jca.fungal.deployment.ValueType;
 
@@ -54,6 +56,7 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Future;
 
@@ -114,12 +117,14 @@
 
             List<BeanDeployer> deployers = new ArrayList<BeanDeployer>(deployment.getBean().size());
             List<String> beans = Collections.synchronizedList(new ArrayList<String>(deployment.getBean().size()));
+            Map<String, List<Method>> uninstall = 
+               new ConcurrentHashMap<String, List<Method>>(deployment.getBean().size());
 
             final CountDownLatch beansLatch = new CountDownLatch(deployment.getBean().size());
 
             for (BeanType bt : deployment.getBean())
             {
-               BeanDeployer deployer = new BeanDeployer(bt, beans, kernel, beansLatch, parent);
+               BeanDeployer deployer = new BeanDeployer(bt, beans, uninstall, kernel, beansLatch, parent);
                deployers.add(deployer);
 
                Future<?> result = kernel.getExecutorService().submit(deployer);
@@ -136,7 +141,7 @@
             }
 
             if (deployException == null)
-               return new BeanDeployment(url, beans, kernel);
+               return new BeanDeployment(url, beans, uninstall, kernel);
          }
       }
       catch (Throwable t)
@@ -162,6 +167,9 @@
       /** The bean names */
       private List<String> beans;
 
+      /** Uninstall methods */
+      private Map<String, List<Method>> uninstall;
+
       /** The kernel */
       private KernelImpl kernel;
 
@@ -178,18 +186,21 @@
        * Constructor
        * @param bt The bean
        * @param beans The list of bean names
+       * @param uninstall Uninstall methods for beans
        * @param kernel The kernel
        * @param beansLatch The beans latch
        * @param classLoader The class loader
        */
       public BeanDeployer(BeanType bt, 
                           List<String> beans,
+                          Map<String, List<Method>> uninstall,
                           KernelImpl kernel,
                           CountDownLatch beansLatch,
                           ClassLoader classLoader)
       {
          this.bt = bt;
          this.beans = beans;
+         this.uninstall = uninstall;
          this.kernel = kernel;
          this.beansLatch = beansLatch;
          this.classLoader = classLoader;
@@ -473,6 +484,42 @@
             throw ite.getTargetException();
          }
 
+         // Invoke install methods
+         if (bt.getInstall() != null && bt.getInstall().size() > 0)
+         {
+            for (InstallType it : bt.getInstall())
+            {
+               try
+               {
+                  Method method = clz.getMethod(it.getMethod(), (Class[])null);
+                  method.invoke(instance, (Object[])null);
+               }
+               catch (InvocationTargetException ite)
+               {
+                  throw ite.getTargetException();
+               }
+            }
+         }
+
+         // Register uninstall methods
+         if (bt.getUninstall() != null && bt.getUninstall().size() > 0)
+         {
+            List<Method> methods = new ArrayList<Method>(bt.getUninstall().size());
+            for (UninstallType ut : bt.getUninstall())
+            {
+               try
+               {
+                  Method method = clz.getMethod(ut.getMethod(), (Class[])null);
+                  methods.add(method);
+               }
+               catch (NoSuchMethodException nsme)
+               {
+                  throw new Exception("Unknown uninstall method:" + ut.getMethod());
+               }
+            }
+            uninstall.put(bt.getName(), methods);
+         }
+
          // Register deployer
          if (instance instanceof Deployer)
          {

Modified: projects/jboss-jca/trunk/fungal/src/main/resources/deployment.xsd
===================================================================
--- projects/jboss-jca/trunk/fungal/src/main/resources/deployment.xsd	2010-01-02 15:07:15 UTC (rev 98963)
+++ projects/jboss-jca/trunk/fungal/src/main/resources/deployment.xsd	2010-01-02 16:17:55 UTC (rev 98964)
@@ -9,6 +9,8 @@
        <xsd:element name="constructor" type="constructorType" maxOccurs="1" minOccurs="0"/>
        <xsd:element name="property" type="propertyType" maxOccurs="unbounded" minOccurs="0"/>
        <xsd:element name="depends" type="dependsType" maxOccurs="unbounded" minOccurs="0"/>
+       <xsd:element name="install" type="installType" maxOccurs="unbounded" minOccurs="0"/>
+       <xsd:element name="uninstall" type="uninstallType" maxOccurs="unbounded" minOccurs="0"/>
      </xsd:sequence>
      <xsd:attribute name="name" type="xsd:token" use="required"/>
      <xsd:attribute name="interface" type="xsd:token"/>
@@ -110,6 +112,14 @@
 
    <xsd:complexType name="nullType"/>
 
+   <xsd:complexType name="installType">
+     <xsd:attribute name="method" type="xsd:token"/>
+   </xsd:complexType>
+
+   <xsd:complexType name="uninstallType">
+     <xsd:attribute name="method" type="xsd:token"/>
+   </xsd:complexType>
+
    <xsd:element name="deployment">
      <xsd:complexType>
        <xsd:sequence>




More information about the jboss-cvs-commits mailing list