[jboss-cvs] JBossAS SVN: r63335 - in projects/microcontainer/trunk: aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jun 4 14:12:32 EDT 2007


Author: kabir.khan at jboss.com
Date: 2007-06-04 14:12:32 -0400 (Mon, 04 Jun 2007)
New Revision: 63335

Added:
   projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UnwindLifeCycleTestCaseNotAutomatic.xml
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/Error.java
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/ErrorLifecycleCallback.java
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/InstallUninstallLifecycleCallback.java
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/UnwindLifeCycleTestCase.java
Modified:
   projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AOPDependencyBuilder.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractLifecycleCallbackItem.java
Log:
Make sure that lifecycle callback aspects get unwound if one of them cause an error during install

Modified: projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AOPDependencyBuilder.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AOPDependencyBuilder.java	2007-06-04 17:47:47 UTC (rev 63334)
+++ projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AOPDependencyBuilder.java	2007-06-04 18:12:32 UTC (rev 63335)
@@ -25,6 +25,8 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -145,7 +147,7 @@
    {
       try
       {
-         HashSet<String> dependencies = new HashSet<String>();
+         HashSet<String> dependencies = new LinkedHashSet<String>();
          getClassAnnotationDependencies(classInfo, metaData, dependencies);
          getMethodAnnotationDependencies(classInfo, metaData, dependencies);
          return dependencies;
@@ -162,9 +164,9 @@
 
    private void getClassAnnotationDependencies(ClassInfo classInfo, MetaData metaData, HashSet<String> dependencies) throws Exception
    {
-      HashMap<String, ArrayList<String>> realMap = new HashMap<String, ArrayList<String>>();
+      HashMap<String, ArrayList<String>> realMap = new LinkedHashMap<String, ArrayList<String>>();
       getRealClassAnnotationDependencies(classInfo, realMap);
-      HashMap<String, ArrayList<String>> metaMap = new HashMap<String, ArrayList<String>>();
+      HashMap<String, ArrayList<String>> metaMap = new LinkedHashMap<String, ArrayList<String>>();
       getMetaDataClassAnnotationDependencies(metaData, metaMap);
       addAllDependenciesToSet(dependencies, realMap, metaMap);
    }
@@ -200,9 +202,9 @@
             MethodInfo method = (MethodInfo)it.next();
             if (Advisable.isAdvisableMethod(method.getModifiers(), method.getName()))
             {
-               HashMap<String, ArrayList<String>> classMap = new HashMap<String, ArrayList<String>>();
+               HashMap<String, ArrayList<String>> classMap = new LinkedHashMap<String, ArrayList<String>>();
                getRealMethodAnnotationDependencies(method, classMap);
-               HashMap<String, ArrayList<String>> overrideMap = new HashMap<String, ArrayList<String>>();
+               HashMap<String, ArrayList<String>> overrideMap = new LinkedHashMap<String, ArrayList<String>>();
                getMetaDataMethodAnnotationDependencies(method, metaData, overrideMap);
                addAllDependenciesToSet(dependencies, classMap, overrideMap);
             }

Added: projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UnwindLifeCycleTestCaseNotAutomatic.xml
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UnwindLifeCycleTestCaseNotAutomatic.xml	                        (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UnwindLifeCycleTestCaseNotAutomatic.xml	2007-06-04 18:12:32 UTC (rev 63335)
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <bean name="MBeanServer" class="java.lang.Object">
+      <constructor factoryClass="javax.management.MBeanServerFactory" factoryMethod="createMBeanServer"/>
+   </bean>
+
+   <bean name="Repository" class="org.jboss.metadata.plugins.repository.basic.BasicMetaDataRepository"/>
+
+   <bean name="AspectManager" class="org.jboss.aop.AspectManager">
+      <constructor factoryClass="org.jboss.aop.AspectManager" factoryMethod="instance"/>
+   </bean>
+
+   <aop:lifecycle-describe xmlns:aop="urn:jboss:aop-beans:1.0"
+               name="DescribeAdvice1"
+               class="org.jboss.test.microcontainer.support.InstallUninstallLifecycleCallback"
+               classes="@org.jboss.test.microcontainer.support.Describe">
+   </aop:lifecycle-describe>
+
+   <aop:lifecycle-describe xmlns:aop="urn:jboss:aop-beans:1.0"
+               name="DescribeAdvice2"
+               class="org.jboss.test.microcontainer.support.InstallUninstallLifecycleCallback"
+               classes="@org.jboss.test.microcontainer.support.Describe">
+   </aop:lifecycle-describe>
+
+   <aop:lifecycle-instantiate xmlns:aop="urn:jboss:aop-beans:1.0"
+               name="InstantiateAdvice1"
+               class="org.jboss.test.microcontainer.support.InstallUninstallLifecycleCallback"
+               classes="@org.jboss.test.microcontainer.support.Instantiate">
+   </aop:lifecycle-instantiate>
+
+   <aop:lifecycle-instantiate xmlns:aop="urn:jboss:aop-beans:1.0"
+               name="InstantiateAdvice2"
+               class="org.jboss.test.microcontainer.support.InstallUninstallLifecycleCallback"
+               classes="@org.jboss.test.microcontainer.support.Instantiate">
+   </aop:lifecycle-instantiate>
+
+   <aop:lifecycle-configure xmlns:aop="urn:jboss:aop-beans:1.0"
+               name="ConfigureAdvice1"
+               class="org.jboss.test.microcontainer.support.InstallUninstallLifecycleCallback"
+               classes="@org.jboss.test.microcontainer.support.Configure">
+   </aop:lifecycle-configure>
+
+   <aop:lifecycle-configure xmlns:aop="urn:jboss:aop-beans:1.0"
+               name="ConfigureAdvice2"
+               class="org.jboss.test.microcontainer.support.InstallUninstallLifecycleCallback"
+               classes="@org.jboss.test.microcontainer.support.Configure">
+   </aop:lifecycle-configure>
+
+   <aop:lifecycle-create xmlns:aop="urn:jboss:aop-beans:1.0"
+               name="CreateAdvice1"
+               class="org.jboss.test.microcontainer.support.InstallUninstallLifecycleCallback"
+               classes="@org.jboss.test.microcontainer.support.Create">
+   </aop:lifecycle-create>
+
+   <aop:lifecycle-create xmlns:aop="urn:jboss:aop-beans:1.0"
+               name="CreateAdvice2"
+               class="org.jboss.test.microcontainer.support.InstallUninstallLifecycleCallback"
+               classes="@org.jboss.test.microcontainer.support.Create">
+   </aop:lifecycle-create>
+
+   <aop:lifecycle-start xmlns:aop="urn:jboss:aop-beans:1.0"
+               name="StartAdvice1"
+               class="org.jboss.test.microcontainer.support.InstallUninstallLifecycleCallback"
+               classes="@org.jboss.test.microcontainer.support.Start">
+   </aop:lifecycle-start>
+
+   <aop:lifecycle-start xmlns:aop="urn:jboss:aop-beans:1.0"
+               name="StartAdvice2"
+               class="org.jboss.test.microcontainer.support.InstallUninstallLifecycleCallback"
+               classes="@org.jboss.test.microcontainer.support.Start">
+   </aop:lifecycle-start>
+
+   <aop:lifecycle-install xmlns:aop="urn:jboss:aop-beans:1.0"
+               name="InstallAdvice1"
+               class="org.jboss.test.microcontainer.support.InstallUninstallLifecycleCallback"
+               classes="@org.jboss.test.microcontainer.support.Install">
+   </aop:lifecycle-install>
+
+   <aop:lifecycle-install xmlns:aop="urn:jboss:aop-beans:1.0"
+               name="InstallAdvice2"
+               class="org.jboss.test.microcontainer.support.InstallUninstallLifecycleCallback"
+               classes="@org.jboss.test.microcontainer.support.Install">
+   </aop:lifecycle-install>
+
+   <aop:lifecycle-install xmlns:aop="urn:jboss:aop-beans:1.0"
+               name="ErrorAdvice"
+               class="org.jboss.test.microcontainer.support.ErrorLifecycleCallback"
+               classes="@org.jboss.test.microcontainer.support.Error">
+   </aop:lifecycle-install>
+
+   <aop:lifecycle-install xmlns:aop="urn:jboss:aop-beans:1.0"
+               name="InstallAdviceNotInvoked" 
+               class="org.jboss.test.microcontainer.support.InstallUninstallLifecycleCallback"
+               classes="@org.jboss.test.microcontainer.support.Install">
+   </aop:lifecycle-install>
+
+   <bean name="Bean" class="org.jboss.test.microcontainer.support.SimpleBeanImpl">
+      <annotation>@org.jboss.test.microcontainer.support.Configure</annotation>
+      <annotation>@org.jboss.test.microcontainer.support.Create</annotation>
+      <annotation>@org.jboss.test.microcontainer.support.Describe</annotation>
+      <annotation>@org.jboss.test.microcontainer.support.Install</annotation>
+      <annotation>@org.jboss.test.microcontainer.support.Instantiate</annotation>
+      <annotation>@org.jboss.test.microcontainer.support.Start</annotation>
+      <annotation>@org.jboss.test.microcontainer.support.Error</annotation>
+   </bean>
+</deployment>

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/Error.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/Error.java	                        (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/Error.java	2007-06-04 18:12:32 UTC (rev 63335)
@@ -0,0 +1,31 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.microcontainer.support;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public @interface Error {
+
+}

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/ErrorLifecycleCallback.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/ErrorLifecycleCallback.java	                        (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/ErrorLifecycleCallback.java	2007-06-04 18:12:32 UTC (rev 63335)
@@ -0,0 +1,63 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.microcontainer.support;
+
+import org.jboss.dependency.spi.ControllerContext;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ErrorLifecycleCallback
+{
+   boolean installedContext;
+   boolean uninstalledContext;
+   boolean error;
+   
+   public boolean isInstalledContext()
+   {
+      return installedContext;
+   }
+
+   public boolean isUninstalledContext()
+   {
+      return uninstalledContext;
+   }
+
+   public void install(ControllerContext context)
+   {
+      installedContext = true;
+      throw new RuntimeException("ErrorLifecycleCallback throwing exception!");
+   }
+   
+   public void uninstall(ControllerContext context) 
+   {
+      uninstalledContext = true;
+      throw new RuntimeException("ErrorLifecycleCallback throwing exception during uninstall phase!");
+   }
+   
+   public void setErrorOnInstall(boolean error)
+   {
+      this.error = error;
+   }
+}
\ No newline at end of file

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/InstallUninstallLifecycleCallback.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/InstallUninstallLifecycleCallback.java	                        (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/InstallUninstallLifecycleCallback.java	2007-06-04 18:12:32 UTC (rev 63335)
@@ -0,0 +1,57 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.microcontainer.support;
+
+import org.jboss.dependency.spi.ControllerContext;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class InstallUninstallLifecycleCallback
+{
+   boolean installedContext;
+   boolean uninstalledContext;
+   boolean error;
+   
+   public boolean isInstalledContext()
+   {
+      return installedContext;
+   }
+
+   public boolean isUninstalledContext()
+   {
+      return uninstalledContext;
+   }
+
+   public void install(ControllerContext context)
+   {
+      installedContext = true;
+   }
+   
+   public void uninstall(ControllerContext context) 
+   {
+      uninstalledContext = true;
+      throw new RuntimeException("InstallUninstallLifecycleCallback throwing exception during uninstall phase!");
+   }
+}

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/UnwindLifeCycleTestCase.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/UnwindLifeCycleTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/UnwindLifeCycleTestCase.java	2007-06-04 18:12:32 UTC (rev 63335)
@@ -0,0 +1,98 @@
+package org.jboss.test.microcontainer.test;
+
+
+import junit.framework.Test;
+
+import org.jboss.aop.microcontainer.junit.AOPMicrocontainerTest;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.test.microcontainer.support.ErrorLifecycleCallback;
+import org.jboss.test.microcontainer.support.InstallUninstallLifecycleCallback;
+
+public class UnwindLifeCycleTestCase extends AOPMicrocontainerTest
+{
+
+   public UnwindLifeCycleTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(UnwindLifeCycleTestCase.class);
+   }
+
+   /**
+    * Validate that the 
+    * @throws Exception
+    */
+   public void testUnwind() throws Exception
+   {
+      try
+      {
+         deploy("UnwindLifeCycleTestCaseNotAutomatic.xml");
+      }
+      catch(Exception e)
+      {
+         
+      }
+      
+      try
+      {
+         Object o = getBean("Bean");
+      }
+      catch (RuntimeException expected)
+      {
+      }
+      
+      getAssertInstalledLifecycleCallback("DescribeAdvice1");
+      getAssertInstalledLifecycleCallback("DescribeAdvice2");
+      getAssertInstalledLifecycleCallback("InstantiateAdvice1");
+      getAssertInstalledLifecycleCallback("InstantiateAdvice2");
+      getAssertInstalledLifecycleCallback("ConfigureAdvice1");
+      getAssertInstalledLifecycleCallback("ConfigureAdvice2");
+      getAssertInstalledLifecycleCallback("CreateAdvice1");
+      getAssertInstalledLifecycleCallback("CreateAdvice2");
+      getAssertInstalledLifecycleCallback("StartAdvice1");
+      getAssertInstalledLifecycleCallback("StartAdvice2");
+      getAssertInstalledLifecycleCallback("InstallAdvice1");
+      getAssertInstalledLifecycleCallback("InstallAdvice2");
+
+      //This is the bean causing the error during its install phase, make sure that both install
+      //AND uninstall have been called since install might have had partial success before the error
+      ErrorLifecycleCallback error = (ErrorLifecycleCallback)getBean("ErrorAdvice");
+      assertTrue(error.isInstalledContext());
+      assertTrue(error.isUninstalledContext());
+
+      //This comes after the error advice in the chain, and so should not have had install or uninstall called
+      InstallUninstallLifecycleCallback startNotInvoked = (InstallUninstallLifecycleCallback)getBean("InstallAdviceNotInvoked");
+      assertFalse(startNotInvoked.isInstalledContext());
+      assertFalse(startNotInvoked.isUninstalledContext());
+      
+      //Lifecycle callbacks from previous states should have had uninstall called
+      getAssertUninstalledLifecycleCallback("DescribeAdvice1");
+      getAssertUninstalledLifecycleCallback("DescribeAdvice2");
+      getAssertUninstalledLifecycleCallback("InstantiateAdvice1");
+      getAssertUninstalledLifecycleCallback("InstantiateAdvice2");
+      getAssertUninstalledLifecycleCallback("ConfigureAdvice1");
+      getAssertUninstalledLifecycleCallback("ConfigureAdvice2");
+      getAssertUninstalledLifecycleCallback("CreateAdvice1");
+      getAssertUninstalledLifecycleCallback("CreateAdvice2");
+      getAssertUninstalledLifecycleCallback("StartAdvice1");
+      getAssertUninstalledLifecycleCallback("StartAdvice2");
+      getAssertUninstalledLifecycleCallback("InstallAdvice1");
+      getAssertUninstalledLifecycleCallback("InstallAdvice2");
+   }
+   
+   private void getAssertInstalledLifecycleCallback(String callbackName)
+   {
+      InstallUninstallLifecycleCallback callback = (InstallUninstallLifecycleCallback)getBean(callbackName);
+      assertTrue(callback.isInstalledContext());
+   }
+   
+   private void getAssertUninstalledLifecycleCallback(String callbackName)
+   {
+      InstallUninstallLifecycleCallback callback = (InstallUninstallLifecycleCallback)getBean(callbackName);
+      assertTrue(callback.isUninstalledContext());
+   }
+}

Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java	2007-06-04 17:47:47 UTC (rev 63334)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java	2007-06-04 18:12:32 UTC (rev 63335)
@@ -21,6 +21,7 @@
 */
 package org.jboss.dependency.plugins;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
@@ -1043,6 +1044,7 @@
 
    protected void handleLifecycleCallbacks(ControllerContext context, ControllerState state, boolean install) throws Throwable
    {
+      List<LifecycleCallbackItem> installedCallbacks = null;
       DependencyInfo di = context.getDependencyInfo();
       List<LifecycleCallbackItem> callbacks = di.getLifecycleCallbacks();
       for (LifecycleCallbackItem callback : callbacks)
@@ -1050,13 +1052,29 @@
          if (callback.getWhenRequired().equals(state))
          {
             if (install)
-               callback.install(context);
+            {
+               try
+               {
+                  callback.install(context);
+                  if (installedCallbacks == null)
+                  {
+                     installedCallbacks = new ArrayList<LifecycleCallbackItem>();
+                  }
+                  installedCallbacks.add(callback);
+               }
+               catch(Throwable t)
+               {
+                  throw t;
+               }
+            }
             else
+            {
                callback.uninstall(context);
+            }
          }
       }
    }
-
+   
    /**
     * Can we use this context for autowiring.
     *

Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractLifecycleCallbackItem.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractLifecycleCallbackItem.java	2007-06-04 17:47:47 UTC (rev 63334)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractLifecycleCallbackItem.java	2007-06-04 18:12:32 UTC (rev 63335)
@@ -27,6 +27,7 @@
 import org.jboss.dependency.spi.LifecycleCallbackItem;
 import org.jboss.dependency.spi.dispatch.InvokeDispatchContext;
 import org.jboss.logging.Logger;
+import org.jboss.util.JBossStringBuilder;
 
 /**
  * 
@@ -42,6 +43,7 @@
    String installMethod;
    String uninstallMethod;
    String bean;
+   boolean installed;
    
    public AbstractLifecycleCallbackItem(
          String bean, 
@@ -69,6 +71,8 @@
 
    public void install(ControllerContext ctx) throws Exception
    {
+      log.trace("Invoking install callback '" + installMethod + "' on " + bean + " for target " + bean + " at " + whenRequired);
+      installed = true;
       Controller controller = ctx.getController();
       ControllerContext callbackContext = controller.getContext(bean, dependentState);
       if (callbackContext instanceof InvokeDispatchContext)
@@ -90,22 +94,36 @@
 
    public void uninstall(ControllerContext ctx)
    {
-      Controller controller = ctx.getController();
-      ControllerContext callbackContext = controller.getContext(bean, dependentState);
-      if (callbackContext instanceof InvokeDispatchContext)
+      if (installed)
       {
-         try
+         log.trace("Invoking uninstall callback '" + installMethod + "' on " + bean + " for target " + bean + " at " + whenRequired);
+         installed = false;
+         Controller controller = ctx.getController();
+         ControllerContext callbackContext = controller.getContext(bean, dependentState);
+         if (callbackContext instanceof InvokeDispatchContext)
          {
-            ((InvokeDispatchContext)callbackContext).invoke(uninstallMethod, new Object[]{ctx}, new String[]{ControllerContext.class.getName()});
+            try
+            {
+               ((InvokeDispatchContext)callbackContext).invoke(uninstallMethod, new Object[]{ctx}, new String[]{ControllerContext.class.getName()});
+            }
+            catch (Throwable ignored)
+            {
+               log.warn("Ignored error uninstalling context " + ctx.getName() + "; callback=" + bean, ignored);
+            }
          }
-         catch (Throwable ignored)
+         else
          {
-            log.warn("Ignored error uninstalling context " + ctx.getName() + "; callback=" + bean, ignored);
+            log.warn("Cannot uninstall " + ctx.getName() + ". Lifecycle callback context " + bean + " does not implement InvokeDispatchContext");
          }
       }
-      else
-      {
-         log.warn("Cannot uninstall " + ctx.getName() + ". Lifecycle callback context " + bean + " does not implement InvokeDispatchContext");
-      }
    }
+   
+   public String toString()
+   {
+      JBossStringBuilder sb = new JBossStringBuilder("LifecycleCallbackItem-");
+      sb.append(bean);
+      sb.append(":");
+      sb.append(whenRequired);
+      return sb.toString();
+   }
 }




More information about the jboss-cvs-commits mailing list