[jboss-cvs] JBossAS SVN: r86778 - in branches/Branch_5_x/system/src/main/org/jboss/system: tools and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Apr 4 08:56:20 EDT 2009


Author: alesj
Date: 2009-04-04 08:56:19 -0400 (Sat, 04 Apr 2009)
New Revision: 86778

Modified:
   branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/AbstractVFSProfileSource.java
   branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java
   branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/HotDeploymentRepository.java
   branches/Branch_5_x/system/src/main/org/jboss/system/tools/ProfileServiceDeploymentRepositoryAdapter.java
Log:
[JBAS-6330]; undeploy apps on removeURL.

Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/AbstractVFSProfileSource.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/AbstractVFSProfileSource.java	2009-04-04 11:10:27 UTC (rev 86777)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/AbstractVFSProfileSource.java	2009-04-04 12:56:19 UTC (rev 86778)
@@ -235,10 +235,7 @@
    
    protected boolean acceptsDeployment(String name)
    {
-      if (applicationCtxs.containsKey(name) == true)
-         return false;
-      
-      return true;
+      return applicationCtxs.containsKey(name) == false;
    }
    
    protected List<String> findDeploymentContent(String name)

Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java	2009-04-04 11:10:27 UTC (rev 86777)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java	2009-04-04 12:56:19 UTC (rev 86778)
@@ -198,6 +198,19 @@
    
    public ProfileDeployment removeDeployment(String vfsPath) throws Exception
    {
+      return removeDeployment(vfsPath, true);
+   }
+
+   /**
+    * Remove deployment.
+    *
+    * @param vfsPath the vfs path
+    * @param deleteFile do we delete the file
+    * @return found profile deployment
+    * @throws Exception for any error
+    */
+   protected ProfileDeployment removeDeployment(String vfsPath, boolean deleteFile) throws Exception
+   {
       // Suspend hot deployment checking
       if( log.isTraceEnabled() )
          log.trace("Aquiring content write lock");
@@ -208,7 +221,7 @@
          ProfileDeployment deployment = getDeployment(vfsPath);
          VirtualFile root = deployment.getRoot();
          
-         if(root != null)
+         if(deleteFile && root != null)
          {
             // Delete the file
             if(root.delete() == false)

Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/HotDeploymentRepository.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/HotDeploymentRepository.java	2009-04-04 11:10:27 UTC (rev 86777)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/HotDeploymentRepository.java	2009-04-04 12:56:19 UTC (rev 86778)
@@ -25,13 +25,14 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
 
 import org.jboss.deployers.vfs.spi.structure.modified.StructureModificationChecker;
 import org.jboss.profileservice.spi.DeploymentContentFlags;
 import org.jboss.profileservice.spi.ModificationInfo;
+import org.jboss.profileservice.spi.ModificationInfo.ModifyStatus;
 import org.jboss.profileservice.spi.ProfileDeployment;
 import org.jboss.profileservice.spi.ProfileKey;
-import org.jboss.profileservice.spi.ModificationInfo.ModifyStatus;
 import org.jboss.virtual.VirtualFile;
 
 /**
@@ -80,7 +81,7 @@
    {
       boolean trace = log.isTraceEnabled();
       Collection<ProfileDeployment> apps = getDeployments();
-      ArrayList<ModificationInfo> modified = new ArrayList<ModificationInfo>();
+      List<ModificationInfo> modified = new ArrayList<ModificationInfo>();
       if (trace)
          log.trace("Checking applications for modifications");
       if (trace)
@@ -128,23 +129,7 @@
                }
             }
             // Now check for additions
-            for (URI applicationDir : getRepositoryURIs())
-            {
-               VirtualFile deployDir = getCachedVirtualFile(applicationDir);
-               ArrayList<VirtualFile> added = new ArrayList<VirtualFile>();
-               addedDeployments(added, deployDir);
-               for (VirtualFile vf : added)
-               {
-                  // Create deployment
-                  ProfileDeployment ctx = createDeployment(vf);
-                  // Create modification info
-                  ModificationInfo info = new ModificationInfo(ctx, vf.getLastModified(), ModifyStatus.ADDED);
-                  // Add
-                  modified.add(info);
-                  addDeployment(ctx.getName(), ctx);
-                  getChecker().addStructureRoot(vf);
-               }
-            }
+            checkForAdditions(modified);
          }
       }
       finally
@@ -158,7 +143,47 @@
          updateLastModfied();
       return modified;
    }
-   
+
+   /**
+    * Check for additions.
+    *
+    * @param modified the modified list
+    * @throws Exception for any error
+    */
+   protected void checkForAdditions(List<ModificationInfo> modified) throws Exception
+   {
+      for (URI applicationDir : getRepositoryURIs())
+      {
+         VirtualFile deployDir = getCachedVirtualFile(applicationDir);
+         List<VirtualFile> added = new ArrayList<VirtualFile>();
+         addedDeployments(added, deployDir);         
+         applyAddedDeployments(applicationDir, modified, added);
+      }
+   }
+
+   /**
+    * Apply added deployments.
+    *
+    * @param applicationDir the app dir
+    * @param modified the modifed list
+    * @param added the added deployments
+    * @throws Exception for any error
+    */
+   protected void applyAddedDeployments(URI applicationDir, List<ModificationInfo> modified, List<VirtualFile> added) throws Exception
+   {
+      for (VirtualFile vf : added)
+      {
+         // Create deployment
+         ProfileDeployment ctx = createDeployment(vf);
+         // Create modification info
+         ModificationInfo info = new ModificationInfo(ctx, vf.getLastModified(), ModifyStatus.ADDED);
+         // Add
+         modified.add(info);
+         addDeployment(ctx.getName(), ctx);
+         getChecker().addStructureRoot(vf);
+      }
+   }
+
    @Override
    protected void cleanUpRoot(VirtualFile vf)
    {

Modified: branches/Branch_5_x/system/src/main/org/jboss/system/tools/ProfileServiceDeploymentRepositoryAdapter.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/tools/ProfileServiceDeploymentRepositoryAdapter.java	2009-04-04 11:10:27 UTC (rev 86777)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/tools/ProfileServiceDeploymentRepositoryAdapter.java	2009-04-04 12:56:19 UTC (rev 86778)
@@ -28,7 +28,10 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
+import org.jboss.deployers.vfs.spi.structure.modified.StructureModificationChecker;
 import org.jboss.logging.Logger;
 import org.jboss.profileservice.spi.ModificationInfo;
 import org.jboss.profileservice.spi.MutableProfile;
@@ -40,7 +43,6 @@
 import org.jboss.system.server.profileservice.hotdeploy.Scanner;
 import org.jboss.system.server.profileservice.repository.HotDeploymentRepository;
 import org.jboss.virtual.VirtualFile;
-import org.jboss.deployers.vfs.spi.structure.modified.StructureModificationChecker;
 
 /**
  * Profile deployment repository adapter.
@@ -220,6 +222,8 @@
    public static class DeploymentScannerProfile extends HotDeploymentRepository implements MutableProfile
    {
       private volatile boolean enableHotDeployment;
+      private Map<URI, List<VirtualFile>> oldCache = new ConcurrentHashMap<URI, List<VirtualFile>>();
+      private Map<URI, List<VirtualFile>> newCache = new ConcurrentHashMap<URI, List<VirtualFile>>();
 
       public DeploymentScannerProfile(StructureModificationChecker checker)
       {
@@ -256,6 +260,60 @@
          return super.getModifiedDeployments();
       }
 
+      @Override
+      protected void checkForAdditions(List<ModificationInfo> modified) throws Exception
+      {
+         // clear new cache
+         newCache.clear();
+         // do real check
+         super.checkForAdditions(modified);
+         // remove the old stuff - what's left of it
+         long lastModified = System.currentTimeMillis();
+         for (List<VirtualFile> files : oldCache.values())
+         {
+            for (VirtualFile file : files)
+            {
+               // the key is URI
+               String name = file.toURI().toString();
+               // it still exists - remove it
+               if (acceptsDeployment(name) == false)
+               {
+                  unlockRead();
+                  ProfileDeployment previous;
+                  try
+                  {
+                     // the actual removal, but we don't delete the file
+                     previous = removeDeployment(name, false);
+                  }
+                  finally
+                  {
+                     lockRead();
+                  }
+                  ModificationInfo removed = new ModificationInfo(previous, lastModified, ModificationInfo.ModifyStatus.REMOVED);
+                  modified.add(removed);
+               }
+            }
+         }
+         // switch new --> old
+         oldCache.clear();
+         oldCache.putAll(newCache);
+      }
+
+      @Override
+      protected void applyAddedDeployments(URI applicationDir, List<ModificationInfo> modified, List<VirtualFile> added) throws Exception
+      {
+         // remove from old cache - it exists
+         List<VirtualFile> files = oldCache.remove(applicationDir);
+         // do real apply
+         super.applyAddedDeployments(applicationDir, modified, added);
+         // add to old + put to new
+         if (files == null)
+            files = new ArrayList<VirtualFile>(added);
+         else
+            files.addAll(added);
+         newCache.put(applicationDir, files);
+      }
+
       public ProfileKey getKey()
       {
          return profileName;




More information about the jboss-cvs-commits mailing list