[jboss-cvs] JBossAS SVN: r59083 - in projects/microcontainer/trunk/container/src/main/org/jboss/virtual: . plugins/context plugins/context/file plugins/context/jar plugins/vfs protocol/vfsfile spi

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Dec 18 11:03:15 EST 2006


Author: bill.burke at jboss.com
Date: 2006-12-18 11:03:12 -0500 (Mon, 18 Dec 2006)
New Revision: 59083

Modified:
   projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VirtualFile.java
   projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractURLHandler.java
   projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
   projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileHandler.java
   projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java
   projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java
   projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/vfsfile/Handler.java
   projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VirtualFileHandler.java
Log:
add a hasBeenModified() method to VF and VFH.  

VirtualFileURLConnection's VFS cache is purged if the VFS Root has been modified since the last cache lookup.  This is to make sure we don't cache stale JAR files as they may have been redeployed since last lookup.

FileHandler's child cache is purged when child's hasBeenModified returns true for same reasons as above.

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VirtualFile.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VirtualFile.java	2006-12-18 15:52:35 UTC (rev 59082)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VirtualFile.java	2006-12-18 16:03:12 UTC (rev 59083)
@@ -146,6 +146,18 @@
    }
 
    /**
+    * Returns true if the file has been modified since this method was last called
+    * Last modified time is initialized at handler instantiation.
+    *
+    * @return
+    * @throws IOException
+    */
+   public boolean hasBeenModified() throws IOException
+   {
+      return getHandler().hasBeenModified();
+   }
+
+   /**
     * Get the size
     *
     * @return the size

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractURLHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractURLHandler.java	2006-12-18 15:52:35 UTC (rev 59082)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractURLHandler.java	2006-12-18 16:03:12 UTC (rev 59083)
@@ -63,6 +63,18 @@
          throw new IllegalArgumentException("Null url");
       this.url = url;
    }
+
+   protected void initCacheLastModified()
+   {
+      try
+      {
+         this.cachedLastModified = url.openConnection().getLastModified();
+      }
+      catch (IOException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
    
    /**
     * Get the url

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java	2006-12-18 15:52:35 UTC (rev 59082)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java	2006-12-18 16:03:12 UTC (rev 59083)
@@ -87,6 +87,8 @@
    /** The reference count */
    private transient AtomicInteger references = new AtomicInteger(0);
 
+   protected transient long cachedLastModified;
+
    /**
     * Create a new handler
     * 
@@ -106,6 +108,18 @@
       this.name = VFSUtils.fixName(name);
    }
 
+   public boolean hasBeenModified() throws IOException
+   {
+      long last = getLastModified();
+      if (cachedLastModified != last)
+      {
+         cachedLastModified = last;
+         return true;
+      }
+      return false;
+   }
+
+
    public String getName()
    {
       return name;

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileHandler.java	2006-12-18 15:52:35 UTC (rev 59082)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileHandler.java	2006-12-18 16:03:12 UTC (rev 59083)
@@ -152,13 +152,17 @@
       List<VirtualFileHandler> result = new ArrayList<VirtualFileHandler>();
       Map<String, VirtualFileHandler> newCache = Collections.synchronizedMap(new HashMap<String, VirtualFileHandler>());
       Map<String, VirtualFileHandler> oldCache = childCache;
+      // fill up a new cache with old entries
+      // old entries no longer existing in directory are purged by not being added to new cache
+      // we cache handlers so that things like JARs are recreated (optimization)
       for (File file : files)
       {
          try
          {
             VirtualFileHandler handler = null;
             handler = oldCache.get(file.getName());
-            if (handler != null && file.lastModified() != handler.getLastModified())
+            // if underlying file has been modified then create a new handler instead of using the cached one
+            if (handler != null && handler.hasBeenModified())
             {
                handler = null;
             }
@@ -193,9 +197,11 @@
       File parentFile = getFile();
       File child = new File(parentFile, name);
       VirtualFileHandler handler = childCache.get(name);
-      if (handler != null)
+      // if a child has already been created use that
+      // if the child has been modified on disk then create a new handler
+      if (handler != null && handler.hasBeenModified())
       {
-         if (handler.getLastModified() != child.lastModified()) handler = null;
+         handler = null;
       }
       if (handler == null)
       {

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java	2006-12-18 15:52:35 UTC (rev 59082)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java	2006-12-18 16:03:12 UTC (rev 59083)
@@ -99,6 +99,19 @@
       this.entry = entry;
    }
 
+
+   @Override
+   protected void initCacheLastModified()
+   {
+      // complete
+   }
+
+   @Override
+   public boolean hasBeenModified() throws IOException
+   {
+      return false; // right now, jar entries should always 
+   }
+
    /**
     * Add a child to an entry
     * @param child

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java	2006-12-18 15:52:35 UTC (rev 59082)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java	2006-12-18 16:03:12 UTC (rev 59083)
@@ -38,7 +38,7 @@
  * @author <a href="bill at jboss.com">Bill Burke</a>
  * @version $Revision: 1.1 $
  */
-public class   VirtualFileURLConnection extends URLConnection
+public class VirtualFileURLConnection extends URLConnection
 {
    public static Map<URL, VFS> urlCache = Collections.synchronizedMap(new HashMap<URL, VFS>());
 
@@ -66,6 +66,17 @@
          vfs = VFS.getVFS(vfsurl);
          urlCache.put(vfsurl, vfs);
       }
+      else
+      {
+         // if the root of VFS has changed on disk, lets purge it
+         // this is important for Jar files as we don't want stale jars as the
+         // root of the VFS (i.e., on redeployment)
+         if (vfs.getRoot().getHandler().hasBeenModified())
+         {
+            vfs = VFS.getVFS(vfsurl);
+            urlCache.put(vfsurl, vfs);
+         }
+      }
       return vfs.findChild(relativePath);
 
    }

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/vfsfile/Handler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/vfsfile/Handler.java	2006-12-18 15:52:35 UTC (rev 59082)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/vfsfile/Handler.java	2006-12-18 16:03:12 UTC (rev 59083)
@@ -21,20 +21,24 @@
 */
 package org.jboss.virtual.protocol.vfsfile;
 
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.plugins.vfs.VirtualFileURLConnection;
+
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
-import java.net.URLClassLoader;
 import java.net.URLConnection;
 import java.net.URLStreamHandler;
-import java.util.Enumeration;
-import java.util.HashSet;
+import java.net.URLClassLoader;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
+import java.util.HashSet;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.Collections;
+import java.util.HashMap;
 
-import org.jboss.virtual.plugins.vfs.VirtualFileURLConnection;
-
 /**
  * URLStreamHandler for VFS
  *

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VirtualFileHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VirtualFileHandler.java	2006-12-18 15:52:35 UTC (rev 59082)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VirtualFileHandler.java	2006-12-18 16:03:12 UTC (rev 59083)
@@ -90,6 +90,15 @@
     * @throws IllegalStateException if closed
     */
    long getLastModified() throws IOException;
+
+   /**
+    * Returns true if the file has been modified since this method was last called
+    * Last modified time is initialized at handler instantiation.
+    *
+    * @return
+    * @throws IOException
+    */
+   boolean hasBeenModified() throws IOException;
    
    /**
     * Get the size




More information about the jboss-cvs-commits mailing list