[jboss-cvs] JBossAS SVN: r87658 - in projects/vfs/trunk: src/main/java/org/jboss/virtual/plugins/context and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 22 02:08:20 EDT 2009


Author: jason.greene at jboss.com
Date: 2009-04-22 02:08:20 -0400 (Wed, 22 Apr 2009)
New Revision: 87658

Modified:
   projects/vfs/trunk/pom.xml
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DefaultOptions.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/temp/BasicTempInfo.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledContext.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryTempInfo.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/registry/DefaultVFSRegistry.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/MockVFSContext.java
Log:
Fix JBVFS-108 TS Issues in tempinfo


Modified: projects/vfs/trunk/pom.xml
===================================================================
--- projects/vfs/trunk/pom.xml	2009-04-22 05:40:34 UTC (rev 87657)
+++ projects/vfs/trunk/pom.xml	2009-04-22 06:08:20 UTC (rev 87658)
@@ -29,7 +29,7 @@
   </organization>
 
   <properties>
-    <version.jboss.common.core>2.2.9.GA</version.jboss.common.core>
+    <version.jboss.common.core>2.2.13-SNAPSHOT</version.jboss.common.core>
     <version.jboss.logging>2.0.5.GA</version.jboss.logging>
     <version.jboss.test>1.1.0.GA</version.jboss.test>
     <version.junit>4.4</version.junit>

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java	2009-04-22 05:40:34 UTC (rev 87657)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java	2009-04-22 06:08:20 UTC (rev 87658)
@@ -31,13 +31,11 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.TreeMap;
-import java.util.HashMap;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.Map.Entry;
 
 import org.jboss.logging.Logger;
+import org.jboss.util.collection.ConcurrentNavigableMap;
+import org.jboss.util.collection.ConcurrentSkipListMap;
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VFSUtils;
 import org.jboss.virtual.VirtualFile;
@@ -52,35 +50,36 @@
 
 /**
  * AbstractVFSContext.
- * 
+ *
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @author Scott.Stark at jboss.org
  * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ * @author Jason T. Greene
  * @version $Revision: 1.1 $
  */
 public abstract class AbstractVFSContext implements VFSContext
 {
    /** The log */
    protected final Logger log = Logger.getLogger(getClass());
-   
+
    /** The VFS wrapper */
-   private VFS vfs;
-   
+   private final VFS vfs = new VFS(this);
+
    /** The root url */
    private final URI rootURI;
 
    /** Options associated with the root URL */
-   private Options options = createNewOptions();
+   private final Options options = createNewOptions();
 
    /** Root's peer within another context */
-   private VirtualFileHandler rootPeer;
+   private volatile VirtualFileHandler rootPeer;
 
    /** The temp handlers */
-   private final Map<String, List<TempInfo>> tempInfos = Collections.synchronizedMap(new HashMap<String, List<TempInfo>>());
+   private final ConcurrentNavigableMap<TempInfoKey, TempInfo> tempInfos = new ConcurrentSkipListMap<TempInfoKey, TempInfo>();
 
    /**
     * Create a new AbstractVFSContext.
-    * 
+    *
     * @param rootURI the root url
     * @throws IllegalArgumentException if rootURI is null
     */
@@ -96,7 +95,7 @@
 
    /**
     * Create a new AbstractVFSContext.
-    * 
+    *
     * @param rootURL the root url
     * @throws URISyntaxException for illegal URL
     * @throws IllegalArgumentException if rootURI is null
@@ -118,8 +117,6 @@
 
    public VFS getVFS()
    {
-      if (vfs == null)
-         vfs = new VFS(this);
       return vfs;
    }
 
@@ -204,7 +201,7 @@
          sb.append(ent.getKey()).append("=").append(ent.getValue());
          i++;
       }
-      
+
       return new URL(sb.toString());
    }
 
@@ -233,7 +230,7 @@
     * @throws IOException for any error
     */
    public URL getChildURL(VirtualFileHandler parent, String name) throws IOException
-   {      
+   {
       if(parent != null)
       {
          VFSContext parentCtx = parent.getVFSContext();
@@ -273,7 +270,7 @@
          if (urlStr.charAt( urlStr.length()-1) != '/')
             urlStr.append("/");
 
-         String pPathName = parent.getPathName();         
+         String pPathName = parent.getPathName();
          if(pPathName.length() != 0)
             urlStr.append(pPathName);
 
@@ -292,7 +289,7 @@
          throw new IllegalArgumentException("Null handler");
       if (visitor == null)
          throw new IllegalArgumentException("Null visitor");
-      
+
       VisitorAttributes attributes = visitor.getAttributes();
       boolean includeRoot = attributes.isIncludeRoot();
       boolean leavesOnly = attributes.isLeavesOnly();
@@ -305,7 +302,7 @@
    /**
     * Visit. the file system, recursive death checking is left to the visitor
     * or otherwise a stack overflow.
-    * 
+    *
     * @param handler the reference handler
     * @param visitor the visitor
     * @param includeRoot whether to visit the root
@@ -323,7 +320,7 @@
       // Visit the root when asked
       if (includeRoot)
          visitor.visit(handler);
-      
+
       // Visit the children
       boolean trace = log.isTraceEnabled();
       List<VirtualFileHandler> children;
@@ -339,7 +336,7 @@
             log.trace("Ignored: " + e);
          return;
       }
-      
+
       // Look through each child
       for (VirtualFileHandler child : children)
       {
@@ -350,7 +347,7 @@
                log.trace("Ignoring hidden file: "+child);
             continue;
          }
-         
+
          // Visit the leaf or non-leaves when asked
          boolean isLeaf = child.isLeaf();
          if (leavesOnly == false || isLeaf)
@@ -380,124 +377,159 @@
       }
    }
 
-   public void addTempInfo(TempInfo tempInfo)
+   private final static class TempInfoKey implements Comparable<TempInfoKey>
    {
-      String key = tempInfo.getPath();
-      List<TempInfo> list;
-      synchronized (tempInfos)
+      private static String LAST = "---@@@LAST@@@---";
+	   private final String originalPath;
+	   private final String tempPath;
+	   private int hashCode;
+
+	   static TempInfoKey last(String path)
+	   {
+	      return new TempInfoKey(path, LAST);
+	   }
+
+	   private TempInfoKey(TempInfo ti)
+	   {
+		   this(ti.getPath(), ti.getTempFile().getAbsolutePath());
+	   }
+
+	   private TempInfoKey(String path)
       {
-         list = tempInfos.get(key);
-         if (list == null)
-         {
-            list = new CopyOnWriteArrayList<TempInfo>();
-            tempInfos.put(key, list);
-         }
+         this(path, "");
       }
-      list.add(tempInfo);
+
+	   private TempInfoKey(String path, String tempPath)
+	   {
+	      if (path == null)
+	         throw new IllegalArgumentException("Path can not be null!");
+
+	      if (path == null)
+	         throw new IllegalArgumentException("Temp path can not be null!");
+
+
+	      this.originalPath = path;
+	      this.tempPath = tempPath;
+	   }
+
+      public int compareTo(TempInfoKey o)
+      {
+         int result = originalPath.compareTo(o.originalPath);
+         if (result == 0)
+            result = tempPath == LAST ? 1 : tempPath.compareTo(o.tempPath);
+
+         return result;
+      }
+
+      public boolean equals(Object o)
+      {
+         if (this == o)
+            return true;
+
+         if (!(o instanceof TempInfoKey))
+            return false;
+
+         TempInfoKey other = (TempInfoKey)o;
+
+         return originalPath.equals(other.originalPath) && tempPath.equals(other.tempPath);
+      }
+
+      public int hashCode()
+      {
+         // Safe race
+         if (hashCode != 0)
+            return hashCode;
+
+         return hashCode = originalPath.hashCode() ^ tempPath.hashCode();
+      }
    }
 
+   public void addTempInfo(TempInfo tempInfo)
+   {
+      TempInfoKey tempInfoKey = new TempInfoKey(tempInfo);
+      tempInfos.put(tempInfoKey, tempInfo);
+   }
+
    public TempInfo getTempInfo(String path)
    {
-      TempInfo result = null;
-      List<TempInfo> list = tempInfos.get(path);
-      if (list != null && list.isEmpty())
+      Iterator<Map.Entry<TempInfoKey, TempInfo>> iter = tempInfos.tailMap(new TempInfoKey(path)).entrySet().iterator();
+      while (iter.hasNext())
       {
-         Iterator<TempInfo> iter = list.iterator();
-         while(iter.hasNext())
-         {
-            TempInfo ti = iter.next();
-            if (ti.isValid() == false)
-            {
-               iter.remove();
-            }
-            else if (result == null)
-            {
-               result = ti;
-            }
-         }
+         Entry<TempInfoKey, TempInfo> entry = iter.next();
+         if (! entry.getKey().originalPath.equals(path))
+            return null;
+
+         TempInfo value = entry.getValue();
+         if (value.isValid())
+            return value;
+
+         // Not valid, eager clean
+         iter.remove();
       }
-      return result;
+
+      return null;
    }
 
-   public Iterable<TempInfo> getTempInfos()
+   public TempInfo getFurthestParentTemp(String path)
    {
-      Map<String, TempInfo> result = new TreeMap<String, TempInfo>();
-      Iterator<Map.Entry<String, List<TempInfo>>> iter = tempInfos.entrySet().iterator();
-      while(iter.hasNext())
+      // Start at the last possible matching entry, and scan upwards until the first matching
+      // entry is found. Alternatively, path could be broken up by the separation delimiter,
+      // and each lookup done from there.
+      Entry<TempInfoKey, TempInfo> floor = tempInfos.floorEntry(TempInfoKey.last(path));
+      TempInfo result = null;
+      while (floor != null && path.startsWith(floor.getKey().originalPath))
       {
-         Map.Entry<String, List<TempInfo>> entry = iter.next();
-         List<TempInfo> list = entry.getValue();
-         if (list != null && list.isEmpty() == false)
-         {
-            Set<TempInfo> invalidTempInfos = new HashSet<TempInfo>();
-            Iterator<TempInfo> listIter = list.iterator();
-            while(listIter.hasNext())
-            {
-               TempInfo ti = listIter.next();
-               if (ti.isValid())
-               {
-                  String path = ti.getPath();
-                  if (result.containsKey(path) == false)
-                  {
-                     result.put(path, ti);
-                  }
-               }
-               else
-               {
-                  invalidTempInfos.add(ti);
-               }
-            }
-            for (TempInfo ti : invalidTempInfos) {
-               list.remove(ti);
-            }
-         }
-         if (list == null || list.isEmpty())
-         {
-            iter.remove();
-         }
+         TempInfo value = floor.getValue();
+         if (value.isValid())
+            result = value;
+
+         floor = tempInfos.lowerEntry(floor.getKey());
       }
-      return result.values();
+
+      return result;
    }
 
    public void cleanupTempInfo(String path)
    {
       boolean trace = log.isTraceEnabled();
       List<String> info = null;
-
-      Iterator<Map.Entry<String, List<TempInfo>>> iter = tempInfos.entrySet().iterator();
+      ConcurrentNavigableMap<TempInfoKey, TempInfo> tailMap = tempInfos.tailMap(new TempInfoKey(path));
+      Iterator<Map.Entry<TempInfoKey, TempInfo>> iter = tailMap.entrySet().iterator();
       while (iter.hasNext())
       {
-         Map.Entry<String, List<TempInfo>> entry = iter.next();
-         if (entry.getKey().startsWith(path))
-         {
-            List<TempInfo> list = entry.getValue();
+         Entry<TempInfoKey, TempInfo> entry = iter.next();
 
-            if (trace)
-            {
-               if (info == null)
-                  info = new ArrayList<String>();
+         if (! entry.getKey().originalPath.startsWith(path))
+            break;
 
-               if (list != null && list.isEmpty() == false)
-                  info.add(list.toString());
-            }
+         TempInfo ti = entry.getValue();
+         if (trace)
+         {
+            if (info == null)
+               info = new ArrayList<String>();
 
-            for (TempInfo ti : list)
-            {
-               try
-               {
-                  ti.cleanup();                  
-               }
-               catch (Throwable ignored)
-               {
-               }
-            }
-            iter.remove();
+            info.add(ti.toString());
          }
+
+         try
+         {
+            ti.cleanup();
+         }
+         catch (Throwable ignored)
+         {
+         }
+         iter.remove();
       }
       if (trace)
          log.trace("Removing temp info for path: '" + path + "', temps: " + info);
+
    }
 
+   public Iterable<TempInfo> getTempInfos()
+   {
+      return Collections.unmodifiableCollection(new ArrayList<TempInfo>(tempInfos.values()));
+   }
+
    public ExceptionHandler getExceptionHandler()
    {
       return getOption(ExceptionHandler.class);
@@ -520,7 +552,7 @@
       buffer.append(']');
       return buffer.toString();
    }
-   
+
    @Override
    public int hashCode()
    {
@@ -537,4 +569,4 @@
       VFSContext other = (VFSContext) obj;
       return rootURI.equals(other.getRootURI());
    }
-}
+}
\ No newline at end of file

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DefaultOptions.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DefaultOptions.java	2009-04-22 05:40:34 UTC (rev 87657)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DefaultOptions.java	2009-04-22 06:08:20 UTC (rev 87658)
@@ -68,14 +68,17 @@
          throw new IllegalArgumentException("Null exact type");
 
       Map<String, T> result = new HashMap<String,T>();
-      if (options != null && options.isEmpty() == false)
+      synchronized (this)
       {
-         for (Map.Entry<String, Object> entry : options.entrySet())
+         if (options != null && options.isEmpty() == false)
          {
-            Object value = entry.getValue();
-            if (exactType.isInstance(value))
+            for (Map.Entry<String, Object> entry : options.entrySet())
             {
-               result.put(entry.getKey(), exactType.cast(value));
+               Object value = entry.getValue();
+               if (exactType.isInstance(value))
+               {
+                  result.put(entry.getKey(), exactType.cast(value));
+               }
             }
          }
       }
@@ -172,7 +175,7 @@
       Object result = getOption(name);
       if (result == null)
          return null;
-      return expectedType.cast(result);      
+      return expectedType.cast(result);
    }
 
    public boolean getBooleanOption(String name)

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java	2009-04-22 05:40:34 UTC (rev 87657)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java	2009-04-22 06:08:20 UTC (rev 87658)
@@ -56,7 +56,7 @@
  *
  * Case sesitivity can be turned on for all context URLs by setting system property
  * <em>jboss.vfs.forceCaseSensitive=true</em>.
- * 
+ *
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @author <a href="strukelj at parsek.net">Marko Strukelj</a>
@@ -86,18 +86,18 @@
    }
 
    /** The temp file */
-   private transient File file;
+   private transient volatile File file;
 
    /** The root file */
-   private VirtualFileHandler root;
+   private volatile VirtualFileHandler root;
 
    /**
     * Get the file for a url
-    * 
+    *
     * @param uri the url
     * @return the file
     * @throws IOException for any error accessing the file system
-    * @throws URISyntaxException if cannot create URI 
+    * @throws URISyntaxException if cannot create URI
     * @throws IllegalArgumentException for a null url
     */
    private static File getFile(URI uri) throws IOException, URISyntaxException
@@ -112,7 +112,7 @@
 
    /**
     * Get the url for a file
-    * 
+    *
     * @param file the file
     * @return the url
     * @throws IOException for any error accessing the file system
@@ -144,10 +144,10 @@
          throw new IllegalStateException("Failed to convert file.toURI", e);
       }
    }
-   
+
    /**
     * Create a new FileSystemContext.
-    * 
+    *
     * @param rootURL the root url
     * @throws IOException for an error accessing the file system
     * @throws URISyntaxException for an error parsing the uri
@@ -159,7 +159,7 @@
 
    /**
     * Create a new FileSystemContext.
-    * 
+    *
     * @param rootURI the root uri
     * @throws IOException for an error accessing the file system
     * @throws URISyntaxException if cannot create URI
@@ -168,10 +168,10 @@
    {
       this(rootURI, getFile(rootURI));
    }
-   
+
    /**
     * Create a new FileSystemContext.
-    * 
+    *
     * @param file the root file
     * @throws IOException for an error accessing the file system
     * @throws IllegalArgumentException for a null file
@@ -184,7 +184,7 @@
 
    /**
     * Create a new FileSystemContext.
-    * 
+    *
     * @param rootURI the root uri
     * @param file the file
     * @throws IOException for an error accessing the file system
@@ -216,7 +216,7 @@
 
    /**
     * Create a new virtual file handler
-    * 
+    *
     * @param parent the parent
     * @param file the file
     * @return the handler
@@ -227,7 +227,7 @@
    {
       if (file == null)
          throw new IllegalArgumentException("Null file");
-      
+
       String name = file.getName();
       if (file.isFile() && JarUtils.isArchive(name))
       {
@@ -290,7 +290,7 @@
 
    /**
     * Create a new virtual file handler
-    * 
+    *
     * @param parent the parent
     * @param file the file
     * @param uri the uri

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/temp/BasicTempInfo.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/temp/BasicTempInfo.java	2009-04-22 05:40:34 UTC (rev 87657)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/temp/BasicTempInfo.java	2009-04-22 06:08:20 UTC (rev 87658)
@@ -35,9 +35,9 @@
  */
 public class BasicTempInfo implements TempInfo
 {
-   private String path;
-   private File file;
-   private VirtualFileHandler handler;
+   private final String path;
+   private volatile File file;
+   private volatile VirtualFileHandler handler;
 
    public BasicTempInfo(String path, File file, VirtualFileHandler handler)
    {

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledContext.java	2009-04-22 05:40:34 UTC (rev 87657)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledContext.java	2009-04-22 06:08:20 UTC (rev 87658)
@@ -37,7 +37,7 @@
  */
 public class AssembledContext extends AbstractVFSContext
 {
-   private String name;
+   private final String name;
    /** The root file */
    private final AssembledDirectoryHandler root;
 

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java	2009-04-22 05:40:34 UTC (rev 87657)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java	2009-04-22 06:08:20 UTC (rev 87658)
@@ -119,25 +119,25 @@
    private static final byte[] NO_BYTES = new byte[0];
 
    /** Abstracted access to zip archive - either ZipFileWrapper or ZipStreamWrapper */
-   private ZipWrapper zipSource;
+   private volatile ZipWrapper zipSource;
 
    /** Entry path representing a context root - archive root is not necessarily a context root */
-   private String rootEntryPath = "";
+   private volatile String rootEntryPath = "";
 
    /** path to zip file - used for lazy ZipWrapper initialization */
-   private String filePath = null;
+   private volatile String filePath = null;
 
    /** AutoClean signals if zip archive should be deleted after closing the context - true for nested archives */
-   private boolean autoClean = false;
+   private final boolean autoClean;
 
    /** Registry of everything that zipSource contains */
-   private Map<String, EntryInfo> entries = new ConcurrentHashMap<String, EntryInfo>();
+   private final Map<String, EntryInfo> entries = new ConcurrentHashMap<String, EntryInfo>(16,.75f,4);
 
    /** Have zip entries been navigated yet */
-   private InitializationStatus initStatus = InitializationStatus.NOT_INITIALIZED;
+   private volatile InitializationStatus initStatus = InitializationStatus.NOT_INITIALIZED;
 
    /** RealURL of this context */
-   private URL realURL;
+   private volatile URL realURL;
 
    /**
     * Create a new ZipEntryContext
@@ -237,7 +237,7 @@
       {
          zipSource = zipWrapper;
       }
-      
+
       setRootPeer(peer);
       String name = getRootURI().getPath();
       int toPos = name.length();
@@ -249,7 +249,7 @@
       // name is last path component
       int namePos = name.lastIndexOf("/", toPos-1);
       name = name.substring(namePos+1, toPos);
-      
+
       // cut off any ending exclamation
       if(name.length() != 0 && name.charAt(name.length()-1) == '!')
          name = name.substring(0, name.length()-1);
@@ -594,7 +594,7 @@
       String thisString = VFSUtils.stripProtocol(getRootURI());
       return thisString.substring(peerString.length()) + entryName;
    }
-   
+
    /**
     * Perform initialization only if it hasn't been done yet
     */
@@ -632,7 +632,7 @@
       if (initStatus != InitializationStatus.NOT_INITIALIZED)
       {
          EntryInfo rootInfo = entries.get("");
-         entries = new ConcurrentHashMap<String, EntryInfo>();
+         entries.clear();
          entries.put("", rootInfo);
 
          initStatus = InitializationStatus.NOT_INITIALIZED;
@@ -765,7 +765,7 @@
       else if (initStatus == InitializationStatus.INITIALIZED && getZipSource().hasBeenModified())
       {
          EntryInfo rootInfo = entries.get("");
-         entries = new ConcurrentHashMap<String, EntryInfo>();
+         entries.clear();
          entries.put("", rootInfo);
 
          if (getZipSource().exists())
@@ -841,7 +841,7 @@
          {
             if (parentEntry.handler instanceof DelegatingHandler)
                return parentEntry.handler.getChildren(ignoreErrors);
-            
+
             return parentEntry.getChildren();
          }
       }
@@ -954,7 +954,7 @@
 
       if (getRoot().equals(handler) == false)
          checkIfModified();
-      
+
       EntryInfo ei = entries.get(handler.getLocalPathName());
       if (ei == null || ei.entry == null)
          return false;
@@ -1283,7 +1283,7 @@
    {
       if (pathName.startsWith("/"))
          pathName = pathName.substring(1);
-      
+
       if(pathName.length() == 0)
          return new String [] {null, pathName};
 
@@ -1348,7 +1348,7 @@
          File tmpDir = new File(getTempDir());
          File [] files = tmpDir.listFiles();
          if (files != null && files.length > 0)
-         {            
+         {
             for (File file : files)
             {
                if (file.isDirectory() == false && file.isHidden() == false)

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryTempInfo.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryTempInfo.java	2009-04-22 05:40:34 UTC (rev 87657)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryTempInfo.java	2009-04-22 06:08:20 UTC (rev 87658)
@@ -34,7 +34,7 @@
  */
 public class ZipEntryTempInfo extends BasicTempInfo
 {
-   private ZipEntryContext context;
+   private volatile ZipEntryContext context;
 
    public ZipEntryTempInfo(String path, File file, VirtualFileHandler handler, ZipEntryContext context)
    {

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/registry/DefaultVFSRegistry.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/registry/DefaultVFSRegistry.java	2009-04-22 05:40:34 UTC (rev 87657)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/registry/DefaultVFSRegistry.java	2009-04-22 06:08:20 UTC (rev 87658)
@@ -72,16 +72,15 @@
       if (context != null)
       {
          String relativePath = VFSUtils.getRelativePath(context, uri);
-         for (TempInfo ti : context.getTempInfos())
+
+         TempInfo ti = context.getFurthestParentTemp(relativePath);
+         if (ti != null)
          {
             String path = ti.getPath();
-            if (relativePath.startsWith(path))
-            {
-               String subpath = relativePath.substring(path.length());
-               VirtualFileHandler child = findHandler(ti.getHandler(), subpath, true);
-               if (child != null)
+            String subpath = relativePath.substring(path.length());
+            VirtualFileHandler child = findHandler(ti.getHandler(), subpath, true);
+            if (child != null)
                   return child.getVirtualFile();
-            }
          }
 
          VirtualFileHandler root = context.getRoot();

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java	2009-04-22 05:40:34 UTC (rev 87657)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java	2009-04-22 06:08:20 UTC (rev 87658)
@@ -27,9 +27,9 @@
 
 import org.jboss.virtual.VFS;
 
-/** 
+/**
  * A virtual file context
- * 
+ *
  * @author Scott.Stark at jboss.org
  * @author adrian at jboss.org
  * @author ales.justin at jboss.org
@@ -46,21 +46,21 @@
 
    /**
     * Get the root uri
-    * 
+    *
     * @return the root uri
     */
    URI getRootURI();
 
    /**
     * Get the VFS for this context
-    * 
+    *
     * @return the vfs
     */
    VFS getVFS();
-   
+
    /**
     * Return the root virtual file
-    * 
+    *
     * @return the root
     * @throws IOException for any problem accessing the VFS
     */
@@ -83,7 +83,7 @@
 
    /**
     * Get the children
-    * 
+    *
     * @param parent the parent
     * @param ignoreErrors whether to ignore errors
     * @return the children
@@ -91,7 +91,7 @@
     * @throws IllegalArgumentException for a null parent
     */
    List<VirtualFileHandler> getChildren(VirtualFileHandler parent, boolean ignoreErrors) throws IOException;
-   
+
    /**
     * Get a child
     *
@@ -105,7 +105,7 @@
 
    /**
     * Visit the virtual file system
-    * 
+    *
     * @param handler the reference handler
     * @param visitor the visitor
     * @throws IOException for any error
@@ -146,11 +146,21 @@
     * Iterate over all temp infos.
     * This should return lexicographically ordered temp infos.
     *
+    * @deprecated
     * @return ordered temp infos
     */
    Iterable<TempInfo> getTempInfos();
 
    /**
+    * Retrieve the furthest (outter most) temp which contains this path.
+    *
+    * Ex. if there is /a/b, /a/b/c, and /a/b/c/d, you get /a/b.
+    *
+    * @return the furthest parent
+    */
+   TempInfo getFurthestParentTemp(String path);
+
+   /**
     * Cleanup all temp infos under path param.
     *
     * @param path the path to cleanup

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/MockVFSContext.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/MockVFSContext.java	2009-04-22 05:40:34 UTC (rev 87657)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/MockVFSContext.java	2009-04-22 06:08:20 UTC (rev 87658)
@@ -34,24 +34,24 @@
 
 /**
  * MockVFSContext.
- * 
+ *
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @version $Revision: 1.1 $
  */
 public class MockVFSContext extends AbstractVFSContext
 {
    /** The root handler */
-   private VirtualFileHandler root;
-   
+   private volatile VirtualFileHandler root;
+
    /** The root virtual file */
-   private VirtualFile rootFile;
-   
+   private volatile VirtualFile rootFile;
+
    /** When to throw an IOException */
-   private String ioException = "";
-   
+   private volatile String ioException = "";
+
    /**
     * Create a root mock uri
-    * 
+    *
     * @param name the name
     * @return the uri
     */
@@ -66,10 +66,10 @@
          throw new UnexpectedThrowable("Unexpected", e);
       }
    }
-   
+
    /**
     * Create mock URL
-    * 
+    *
     * @param uri the uri
     * @return the url
     * @throws MalformedURLException for any error
@@ -78,10 +78,10 @@
    {
       return new URL(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getRawPath(), MockURLStreamHandler.INSTANCE);
    }
-   
+
    /**
     * Create a new MockVFSContext.
-    * 
+    *
     * @param name the name
     */
    public MockVFSContext(String name)
@@ -96,7 +96,7 @@
 
    /**
     * Set the ioException.
-    * 
+    *
     * @param ioException the ioException.
     */
    public void setIOException(String ioException)
@@ -106,7 +106,7 @@
 
    /**
     * Check whether we should throw an IOException
-    * 
+    *
     * @param when when to throw
     * @throws IOException when requested
     */
@@ -115,13 +115,13 @@
       if (ioException.equals(when))
          throw new IOException("Throwing IOException from " + when);
    }
-   
+
    public VirtualFileHandler getRoot() throws IOException
    {
       throwIOException("getRoot");
       return root;
    }
-   
+
    public AbstractMockVirtualFileHandler getMockRoot() throws IOException
    {
       return (AbstractMockVirtualFileHandler) root;
@@ -129,7 +129,7 @@
 
    /**
     * Set the root.
-    * 
+    *
     * @param root the root.
     */
    public void setRoot(VirtualFileHandler root)
@@ -138,7 +138,7 @@
       if (root != null)
          rootFile = root.getVirtualFile();
    }
-   
+
    @Override
    protected void finalize() throws Throwable
    {
@@ -146,10 +146,10 @@
          rootFile.close();
       super.finalize();
    }
-   
+
    /**
     * Get the root URL
-    * 
+    *
     * @return the url
     * @throws MalformedURLException for any error
     */




More information about the jboss-cvs-commits mailing list