[jboss-cvs] JBossAS SVN: r84088 - in trunk: system/src/main/org/jboss/system/server/profileservice/repository and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 11 06:38:47 EST 2009


Author: alesj
Date: 2009-02-11 06:38:46 -0500 (Wed, 11 Feb 2009)
New Revision: 84088

Modified:
   trunk/server/src/etc/conf/default/bootstrap/profile-service.xml
   trunk/system/src/main/org/jboss/system/server/profileservice/repository/DefaultDeploymentRepositoryFactory.java
   trunk/system/src/main/org/jboss/system/server/profileservice/repository/MutableDeploymentRepository.java
Log:
[JBAS-6491]; change how we check for modified deployments.

Modified: trunk/server/src/etc/conf/default/bootstrap/profile-service.xml
===================================================================
--- trunk/server/src/etc/conf/default/bootstrap/profile-service.xml	2009-02-11 09:25:09 UTC (rev 84087)
+++ trunk/server/src/etc/conf/default/bootstrap/profile-service.xml	2009-02-11 11:38:46 UTC (rev 84088)
@@ -56,12 +56,25 @@
 		<uncallback method="removeRepositoryFactory" />
 	</bean>
 
+  <!-- The structure modification cache and checker -->
+
+  <bean name="StructureModCache" class="org.jboss.deployers.vfs.spi.structure.modified.DefaultStructureCache">
+    <destroy method="flush"/>
+  </bean>
+
+  <bean name="StructureModificationChecker" class="org.jboss.deployers.vfs.spi.structure.modified.MetaDataStructureModificationChecker">
+    <constructor>
+      <parameter><inject bean="MainDeployer" /></parameter>
+    </constructor>
+    <property name="cache"><inject bean="StructureModCache" /></property>
+    <property name="filter"><bean class="org.jboss.system.server.profile.basic.XmlIncludeVirtualFileFilter" /></property>
+  </bean>
+
 	<!-- The default deployment repository factory -->
 	<bean name="DefaultDeploymentRepositoryFactory" class="org.jboss.system.server.profileservice.repository.DefaultDeploymentRepositoryFactory">
 		<property name="attachmentStore"><inject bean="AttachmentStore" /></property>
-		<property name="mainDeployer"><inject bean="MainDeployer" /></property>
 		<property name="deploymentFilter"><inject bean="DeploymentFilter" /></property>
-		<property name="hotDeploymentFilter"><bean class="org.jboss.system.server.profile.basic.XmlIncludeVirtualFileFilter" /></property>
+		<property name="checker"><inject bean="StructureModificationChecker" /></property>
 	</bean>
 
 	<!-- The attachment store -->

Modified: trunk/system/src/main/org/jboss/system/server/profileservice/repository/DefaultDeploymentRepositoryFactory.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/DefaultDeploymentRepositoryFactory.java	2009-02-11 09:25:09 UTC (rev 84087)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/DefaultDeploymentRepositoryFactory.java	2009-02-11 11:38:46 UTC (rev 84088)
@@ -28,8 +28,7 @@
 import java.util.Collection;
 import java.util.List;
 
-import org.jboss.deployers.client.spi.main.MainDeployer;
-import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
+import org.jboss.deployers.vfs.spi.structure.modified.StructureModificationChecker;
 import org.jboss.profileservice.spi.AttachmentStore;
 import org.jboss.profileservice.spi.DeploymentRepository;
 import org.jboss.profileservice.spi.DeploymentRepositoryFactory;
@@ -46,8 +45,7 @@
  * @version $Revision$
  */
 public class DefaultDeploymentRepositoryFactory implements DeploymentRepositoryFactory
-{
-   
+{   
    /** The mutable type. */
    public final static String MUTABLE_TYPE = HotDeploymentProfileSourceMetaData.class.getName();
    
@@ -59,19 +57,16 @@
    
    /** The attachment store. */
    private AttachmentStore store;
-   
-   /** The main deployer. */
-   private MainDeployer mainDeployer;
-   
+
    /** The deployment filter. */
    private VirtualFileFilter deploymentFilter;
-   
-   /** The metadata include filter. */
-   private VirtualFileFilter hotDeploymentFilter;
-   
+
+   /** The structure modification checker */
+   private StructureModificationChecker checker;
+
    static
    {
-      types = Arrays.asList(new String[] { MUTABLE_TYPE, IMMUTABLE_TYPE } );
+      types = Arrays.asList(MUTABLE_TYPE, IMMUTABLE_TYPE);
    }
    
    public String[] getTypes()
@@ -98,27 +93,17 @@
    {
       this.deploymentFilter = deploymentFilter;
    }
-   
-   public VirtualFileFilter getHotDeploymentFilter()
+
+   public StructureModificationChecker getChecker()
    {
-      return hotDeploymentFilter;
+      return checker;
    }
-   
-   public void setHotDeploymentFilter(VirtualFileFilter hotDeploymentFilter)
+
+   public void setChecker(StructureModificationChecker checker)
    {
-      this.hotDeploymentFilter = hotDeploymentFilter;
+      this.checker = checker;
    }
-   
-   public MainDeployer getMainDeployer()
-   {
-      return mainDeployer;
-   }
-   
-   public void setMainDeployer(MainDeployer mainDeployer)
-   {
-      this.mainDeployer = mainDeployer;
-   }
-   
+
    public DeploymentRepository createDeploymentRepository(ProfileKey key, ProfileSourceMetaData metaData)
          throws Exception
    {
@@ -154,9 +139,8 @@
          // Manually inject beans :)
          repository.setAttachmentStore(store);
          repository.setDeploymentFilter(deploymentFilter);
-         repository.setHotDeploymentFilter(hotDeploymentFilter);
-         repository.setMainDeployer((MainDeployerStructure) mainDeployer);
-         
+         repository.setChecker(checker);
+
          return repository;
       }
       else
@@ -180,5 +164,4 @@
       }
       return uris.toArray(new URI[uris.size()]);
    }
-   
 }

Modified: trunk/system/src/main/org/jboss/system/server/profileservice/repository/MutableDeploymentRepository.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/MutableDeploymentRepository.java	2009-02-11 09:25:09 UTC (rev 84087)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/MutableDeploymentRepository.java	2009-02-11 11:38:46 UTC (rev 84088)
@@ -31,15 +31,10 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import java.util.zip.ZipInputStream;
 
-import org.jboss.deployers.structure.spi.DeploymentContext;
-import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
+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;
@@ -47,7 +42,6 @@
 import org.jboss.profileservice.spi.ProfileKey;
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.VirtualFileFilter;
 
 /**
  * A mutable deployment repository, with hot deployment capabilities.
@@ -60,16 +54,10 @@
 {
    /** Should an attempt to overwrite existing content fail in {@link #addDeploymentContent(String, ZipInputStream)}*/
    private boolean failIfAlreadyExists = false;
-   
-   /** The main deployer structure. */
-   private MainDeployerStructure mainDeployer;
-   
-   /** The metadata include filter. */
-   private VirtualFileFilter hotDeploymentFilter;
-   
-   /** The last modified cache. */
-   private Map<String, Long> lastModifiedCache = new ConcurrentHashMap<String, Long>();
-   
+
+   /** The structure modification checker */
+   private StructureModificationChecker checker;
+
    /** A lock for the hot deployment/{@link #getModifiedDeployments()} */
    private ReentrantReadWriteLock contentLock = new ReentrantReadWriteLock(true);
    
@@ -77,26 +65,29 @@
    {
       super(key, uris);
    }
-   
-   public VirtualFileFilter getHotDeploymentFilter()
+
+   /**
+    * Get the structure modified checker.
+    *
+    * @return the checker
+    */
+   protected StructureModificationChecker getChecker()
    {
-      return hotDeploymentFilter;
+      if (checker == null)
+         throw new IllegalArgumentException("Checker must be set");
+
+      return checker;
    }
-   
-   public void setHotDeploymentFilter(VirtualFileFilter hotDeploymentFilter)
+
+   /**
+    * Set the checker.
+    *
+    * @param checker the checker
+    */
+   public void setChecker(StructureModificationChecker checker)
    {
-      this.hotDeploymentFilter = hotDeploymentFilter;
+      this.checker = checker;
    }
-   
-   public MainDeployerStructure getMainDeployer()
-   {
-      return mainDeployer;
-   }
-   
-   public void setMainDeployer(MainDeployerStructure mainDeployer)
-   {
-      this.mainDeployer = mainDeployer;
-   }
 
    public void load() throws Exception
    {
@@ -108,13 +99,6 @@
       updateLastModfied();
    }
    
-   @Override
-   public void unload()
-   {
-      super.unload();
-      this.lastModifiedCache.clear();
-   }
-   
    public String addDeploymentContent(String vfsPath, InputStream contentIS) throws IOException
    {
       boolean trace = log.isTraceEnabled();
@@ -213,13 +197,12 @@
                   modified.add(info);
                   iter.remove();
                   // Remove last modified cache
-                  removeLastModifiedCache(pathName);
+                  getChecker().removeStructureRoot(root);
                   if (trace)
                      log.trace(pathName + " was removed");
                }
                // Check for modification
-               else if (hasBeenModified(root)
-                     || hasDeploymentContentFlags(pathName, DeploymentContentFlags.MODIFIED))
+               else if (getChecker().hasStructureBeenModified(root) || hasDeploymentContentFlags(pathName, DeploymentContentFlags.MODIFIED))
                {
                   long rootLastModified = root.getLastModified();
                   if (trace)
@@ -248,6 +231,7 @@
                   ModificationInfo info = new ModificationInfo(ctx, vf.getLastModified(), ModifyStatus.ADDED);
                   modified.add(info);
                   addDeployment(ctx.getName(), ctx);
+                  getChecker().addStructureRoot(vf);
                }
             }
          }
@@ -264,127 +248,6 @@
       return modified;
    }
 
-   /**
-    * Check if the deployment has been modified.
-    * Invalidate last modifed cache if modifed.
-    *
-    * @param root the virtual file root
-    * @return true if modifed
-    * @throws Exception for any error
-    */
-   protected boolean hasBeenModified(VirtualFile root) throws Exception
-   {
-      boolean result = isModified(root);
-      if (result)
-      {
-         removeLastModifiedCache(root.getPathName());
-      }
-      return result;
-   }
-
-   /**
-    * Check if the deployment has been modified.
-    * Note: it doesn't invalidate the last modified cache.
-    *
-    * @param root the virtual file root
-    * @return true if modifed
-    * @throws Exception for any error
-    */
-   private boolean isModified(VirtualFile root) throws Exception
-   {
-      // skip vfs deployment context lookup if archive or file
-      if (root.isArchive() || root.isLeaf())
-         return root.hasBeenModified();
-
-      // else check metadata
-      String name = root.toURI().toString();
-      VFSDeploymentContext deploymentContext = getDeploymentContext(name);
-      if (deploymentContext != null)
-         return hasBeenModified(deploymentContext, false);
-
-      log.trace("Falling back to root name: " + root);
-      deploymentContext = getDeploymentContext(root.getName());
-      if (deploymentContext != null)
-         return hasBeenModified(deploymentContext, false);
-
-      return false;
-   }
-   
-   /**
-    * Check for modifications.
-    * 
-    * @param deploymentContext the vfs deployment context
-    * @param checkRoot do we check the root
-    * @return true if modifed, false otherwise
-    * @throws IOException for any error
-    */
-   protected boolean hasBeenModified(VFSDeploymentContext deploymentContext, boolean checkRoot) throws IOException
-   {
-      if (checkRoot)
-      {
-         VirtualFile root = deploymentContext.getRoot();
-         // no need to check metadata locations if archive or root
-         if (root.isArchive() || root.isLeaf())
-            return root.hasBeenModified();
-      }
-
-      List<VirtualFile> metadataLocations = deploymentContext.getMetaDataLocations();
-      if (metadataLocations != null && metadataLocations.isEmpty() == false)
-      {
-         for(VirtualFile metadataLocation : metadataLocations)
-         {
-            List<VirtualFile> children = metadataLocation.getChildren(hotDeploymentFilter);
-            if (children != null && children.isEmpty() == false)
-            {
-               for(VirtualFile child : children)
-               {
-                  String pathName = child.getPathName();
-                  Long timestamp = lastModifiedCache.get(pathName);
-                  long lastModified = child.getLastModified();
-                  lastModifiedCache.put(pathName, lastModified);
-                  if (timestamp != null && timestamp < lastModified)
-                  {
-                     if (log.isTraceEnabled())
-                        log.trace("Metadata location modified: " + child);
-                     return true;
-                  }
-               }
-            }
-         }
-      }
-      List<DeploymentContext> childContexts = deploymentContext.getChildren();
-      if (childContexts != null && childContexts.isEmpty() == false)
-      {
-         for (DeploymentContext childContext : childContexts)
-         {
-            if (childContext instanceof VFSDeploymentContext)
-            {
-               if (hasBeenModified((VFSDeploymentContext)childContext, true))
-                  return true;
-            }
-         }
-      }
-      return false;
-   }
-
-   /**
-    * Cleanup last modified cache for path name.
-    *
-    * @param pathName the path name
-    */
-   protected void removeLastModifiedCache(String pathName)
-   {
-      if (log.isTraceEnabled())
-         log.trace("Removing last modified cache info for: " + pathName);
-
-      Iterator<String> iter = lastModifiedCache.keySet().iterator();
-      while (iter.hasNext())
-      {
-         if (iter.next().startsWith(pathName))
-            iter.remove();
-      }
-   }
-
    public ProfileDeployment removeDeployment(String vfsPath) throws Exception
    {
       ProfileDeployment vfsDeployment = getDeployment(vfsPath);
@@ -398,24 +261,4 @@
    {
       // FIXME remove
    }
-   
-   /**
-    * Get deployment context.
-    *
-    * @param name the deployment context name
-    * @return vfs deployment context or null if doesn't exist or not vfs based
-    */
-   @SuppressWarnings("deprecation")
-   protected VFSDeploymentContext getDeploymentContext(String name)
-   {
-      if (mainDeployer == null)
-         throw new IllegalStateException("Null main deployer.");
-
-      DeploymentContext deploymentContext = mainDeployer.getDeploymentContext(name);
-      if (deploymentContext == null || deploymentContext instanceof VFSDeploymentContext == false)
-         return null;
-
-      return (VFSDeploymentContext) deploymentContext;
-   }
-
 }




More information about the jboss-cvs-commits mailing list