[jboss-cvs] JBossAS SVN: r75112 - trunk/system/src/main/org/jboss/system/server/profile/basic.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 26 07:50:43 EDT 2008


Author: alesj
Date: 2008-06-26 07:50:43 -0400 (Thu, 26 Jun 2008)
New Revision: 75112

Modified:
   trunk/system/src/main/org/jboss/system/server/profile/basic/MetaDataAwareProfile.java
   trunk/system/src/main/org/jboss/system/server/profile/basic/ProfileImpl.java
Log:
Fix hasBeenModified check.

Modified: trunk/system/src/main/org/jboss/system/server/profile/basic/MetaDataAwareProfile.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profile/basic/MetaDataAwareProfile.java	2008-06-26 11:39:38 UTC (rev 75111)
+++ trunk/system/src/main/org/jboss/system/server/profile/basic/MetaDataAwareProfile.java	2008-06-26 11:50:43 UTC (rev 75112)
@@ -24,10 +24,14 @@
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.jboss.deployers.structure.spi.DeploymentContext;
 import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
 import org.jboss.profileservice.spi.ProfileKey;
 import org.jboss.virtual.VFSUtils;
@@ -36,15 +40,21 @@
 /**
  * Profile monitoring metadata changes.
  *
+ * We need to cache files's last modifed timestamps,
+ * since file.getChildren re-caches handlers,
+ * hence hasBeenModified is useless.
+ *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
 public class MetaDataAwareProfile extends ProfileImpl
 {
    private MainDeployerStructure mainDeployer;
+   private Map<String, Long> lastModifiedCache;
 
    public MetaDataAwareProfile(String profileRoot, ProfileKey key)
    {
       super(profileRoot, key);
+      lastModifiedCache = new ConcurrentHashMap<String, Long>();
    }
 
    /**
@@ -96,19 +106,16 @@
       {
          for(VirtualFile metadataLocation : metadataLocations)
          {
-            if (metadataLocation.isLeaf() && metadataLocation.hasBeenModified())
-            {
-               if (log.isTraceEnabled())
-                  log.trace("Metadata location modified: " + metadataLocation);
-               return true;
-            }
-
             List<VirtualFile> children = metadataLocation.getChildren();
             if (children != null && children.isEmpty() == false)
             {
                for(VirtualFile child : children)
                {
-                  if (child.hasBeenModified())
+                  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);
@@ -133,6 +140,23 @@
       return false;
    }
 
+   // expecting all deployments from same context root
+   // so path name should group them per deployment unit
+   protected void postRemove(VFSDeployment deployment) throws Exception
+   {
+      VirtualFile root = deployment.getRoot();
+      String pathName = root.getPathName();
+      if (log.isTraceEnabled())
+         log.debug("Removing last modified cache info for: " + pathName);
+
+      Iterator<String> iter = lastModifiedCache.keySet().iterator();
+      while (iter.hasNext())
+      {
+         if (iter.next().startsWith(pathName))
+            iter.remove();
+      }
+   }
+
    /**
     * Get deployment context.
     *

Modified: trunk/system/src/main/org/jboss/system/server/profile/basic/ProfileImpl.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profile/basic/ProfileImpl.java	2008-06-26 11:39:38 UTC (rev 75111)
+++ trunk/system/src/main/org/jboss/system/server/profile/basic/ProfileImpl.java	2008-06-26 11:50:43 UTC (rev 75112)
@@ -311,6 +311,7 @@
                iter.remove();
                if( trace )
                   log.trace(root.getPathName() + " was removed");
+               postRemove(d);
             }
             // Check for modification
             else if(hasBeenModified(root))
@@ -358,6 +359,17 @@
    }
 
    /**
+    * Apply post remove operation.
+    *
+    * @param deployment the vfs deployment
+    * @throws Exception for any error
+    */
+   protected void postRemove(VFSDeployment deployment) throws Exception
+   {
+      // noop here
+   }
+
+   /**
     * Noop as basic profile does not support hot deployment currently
     */
    public void enableModifiedDeploymentChecks(boolean flag)
@@ -420,8 +432,7 @@
 
    protected VFSDeployment getBootstrap(String name)
    {
-      VFSDeployment deployment = bootstraps.get(name);
-      return deployment;
+      return bootstraps.get(name);
    }
 
    protected Collection<VFSDeployment> getBootstraps()
@@ -441,8 +452,7 @@
 
    protected VFSDeployment getDeployer(String name)
    {
-      VFSDeployment deployment = deployers.get(name);
-      return deployment;
+      return deployers.get(name);
    }
 
    protected Collection<VFSDeployment> getDeployers()
@@ -462,8 +472,7 @@
 
    protected VFSDeployment getApplication(String name)
    {
-      VFSDeployment deployment = applications.get(name);
-      return deployment;
+      return applications.get(name);
    }
 
    protected Collection<VFSDeployment> getApplications()




More information about the jboss-cvs-commits mailing list