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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Jan 25 08:14:29 EST 2009


Author: emuckenhuber
Date: 2009-01-25 08:14:28 -0500 (Sun, 25 Jan 2009)
New Revision: 83403

Modified:
   trunk/system/src/main/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java
Log:
remember loaded profiles and deactivate them first when shutting down the server.

Modified: trunk/system/src/main/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java	2009-01-25 12:55:29 UTC (rev 83402)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java	2009-01-25 13:14:28 UTC (rev 83403)
@@ -22,10 +22,12 @@
 package org.jboss.system.server.profileservice;
 
 import java.lang.annotation.Annotation;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -87,10 +89,14 @@
    private static final Logger log = Logger.getLogger(ProfileServiceBootstrap.class);
    
    /** The name of the profile that is being booted */
-   protected String profileName = "default";
+   protected String profileName;
    
+   /** The root profile key. */
    protected ProfileKey profileKey;
 
+   /** The loaded profiles. */
+   private List<ProfileKey> bootstrapProfiles = new ArrayList<ProfileKey>();
+   
    /** The server MainDeployer */
    protected MainDeployer mainDeployer;
 
@@ -213,13 +219,18 @@
       initBootstrapMDs(server);
 
       // Load the profile
-      profileName = server.getConfig().getServerName();
+      if(profileName == null)
+         profileName = server.getConfig().getServerName();
       this.profileKey = new ProfileKey(profileName);
       
+      // Register the profiles
       Collection<Profile> bootstrapProfiles = profileFactory.createProfiles(profileKey, null);
       for(Profile profile : bootstrapProfiles)
       {
          profileService.registerProfile(profile);
+         // Add to loaded profiles
+         if(this.profileKey.equals(profile.getKey()) == false)
+            this.bootstrapProfiles.add(0, profile.getKey());
       }
       
       // Activate the root profile
@@ -253,6 +264,7 @@
 
    public void shutdown(Server server)
    {
+      // Deactivate the root profile
       try
       {
          // Release 
@@ -273,25 +285,18 @@
          log.warn("Error unloading profile: " + this.profileKey, t);         
       }
       
-      // FIXME we should release other active profiles in the correct order
-      for(ProfileKey key : profileService.getActiveProfileKeys())
+      // Deactivate all profiles we registered
+      deactivateProfiles(this.bootstrapProfiles);
+      
+      // Deactivate all still active profiles
+      deactivateProfiles(this.profileService.getActiveProfileKeys());
+      
+      // Unregister all profiles at once
+      for(ProfileKey key : profileService.getProfileKeys())
       {
          try
          {
-            // Release
-            profileService.deactivateProfile(key);
-         }
-         catch(NoSuchProfileException e)
-         {
-            // ignore
-         }
-         catch(Throwable t)
-         {
-            log.warn("Error unloading profile: " + this.profileKey, t);
-         }
-         try
-         {
-            // Unregister
+            // TODO update to unregister(ProfileKey);
             Profile profile = profileService.getProfile(key);
             profileService.unregisterProfile(profile);
          }
@@ -310,6 +315,28 @@
          log.warn("Error shutting down the main deployer", t);
       }
    }
+   
+   protected void deactivateProfiles(Collection<ProfileKey> profiles)
+   {
+      if(profiles != null && profiles.isEmpty() == false)
+      {
+         for(ProfileKey key : profiles)
+         {
+            try
+            {
+               profileService.deactivateProfile(key);
+            }
+            catch(NoSuchProfileException e)
+            {
+               // ignore
+            }
+            catch(Throwable t)
+            {
+               log.warn("Error unloading profile: " + this.profileKey, t);
+            }
+         }
+      }
+   }
 
    /**
     * Create ManagedDeployments for the MCServer KernelDeployments. This allows




More information about the jboss-cvs-commits mailing list