[jboss-cvs] JBossAS SVN: r69356 - trunk/system/src/main/org/jboss/system/server/profileservice.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jan 25 14:01:16 EST 2008


Author: adrian at jboss.org
Date: 2008-01-25 14:01:16 -0500 (Fri, 25 Jan 2008)
New Revision: 69356

Modified:
   trunk/system/src/main/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java
Log:
[JBAS-5175] - Unload the profile in reverse phase order. Also set the context classloader during undeploy otherwise there is no visibility into anything other than the bootstrap-beans.xml classloader

Modified: trunk/system/src/main/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java	2008-01-25 18:32:28 UTC (rev 69355)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java	2008-01-25 19:01:16 UTC (rev 69356)
@@ -146,6 +146,7 @@
 
    public void shutdown(Server server)
    {
+      unloadProfile(profileName);
       try
       {
          mainDeployer.shutdown();
@@ -250,4 +251,112 @@
          thread.setContextClassLoader(old);
       }
    }
+
+   /**
+    * Unload the deployments associated with the named profile and undeploy them
+    * using the MainDeployer in reverse phase order.
+    * 
+    * @param name the profile name
+    * @throws NullPointerException if either the MainDeployer or ProfileService
+    * have not been injected.
+    */
+   protected void unloadProfile(String name)
+   {
+      MainDeployer deployer = getMainDeployer();
+      if (deployer == null)
+      {
+         log.warn("MainDeployer has not been set");
+         return;
+      }
+      ProfileService ps = getProfileService();
+      if (ps == null)
+      {
+         log.warn("ProfileService has not been set");
+         return;
+      }
+
+      try
+      {
+         // Load the named profile
+         ProfileKey key = new ProfileKey(name);
+         Profile profile = ps.getProfile(key);
+
+         // HACK
+         VFSDeployment first = null;
+         
+         // Deploy the bootstrap
+         Collection<VFSDeployment> boostraps = profile.getDeployments(DeploymentPhase.BOOTSTRAP);
+         for (VFSDeployment d : boostraps)
+         {
+            if (first == null)
+            {
+               first = d;
+               break;
+            }
+         }
+
+         Thread thread = Thread.currentThread();
+         ClassLoader old = thread.getContextClassLoader();
+         // FIXME remove this hack
+         MainDeployerImpl hack = (MainDeployerImpl) deployer;
+         ClassLoader cl = null;
+         if (first != null)
+         {
+            try
+            {
+               DeploymentContext ctx = hack.getDeploymentContext(first.getName());
+               if (ctx != null)
+                  cl = ctx.getClassLoader();
+            }
+            catch (Exception e)
+            {
+               log.debug("Unable to get first deployment", e);
+            }
+         }
+         if (cl != null)
+            thread.setContextClassLoader(cl);
+         try
+         {
+            // Undeploy the applications
+            unload(deployer, profile.getDeployments(DeploymentPhase.APPLICATION));
+            // Undeploy the deployers
+            unload(deployer, profile.getDeployments(DeploymentPhase.DEPLOYER));
+            // Undeploy the bootstrap
+            unload(deployer, profile.getDeployments(DeploymentPhase.BOOTSTRAP));
+         }
+         finally
+         {
+            thread.setContextClassLoader(old);
+         }
+      }
+      catch (Throwable t)
+      {
+         log.warn("Error unloading profile", t);
+      }
+   }
+
+   /**
+    * Unload a set of deployments
+    * 
+    * @param deployer the main deployer
+    * @param deployments the deployments
+    */
+   protected void unload(MainDeployer deployer, Collection<VFSDeployment> deployments)
+   {
+      if (deployments == null || deployments.isEmpty())
+         return;
+      
+      for (VFSDeployment d : deployments)
+      {
+         try
+         {
+            deployer.removeDeployment(d);
+         }
+         catch (Exception e)
+         {
+            log.warn("Unable to remove deployment: " + d);
+         }
+      }
+      deployer.process();
+   }
 }




More information about the jboss-cvs-commits mailing list