[jboss-cvs] JBossAS SVN: r101132 - in projects/vfs/branches/Branch_2_2/src: main/java/org/jboss/virtual/plugins/cache and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 18 16:29:46 EST 2010


Author: alesj
Date: 2010-02-18 16:29:45 -0500 (Thu, 18 Feb 2010)
New Revision: 101132

Modified:
   projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/VFS.java
   projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/CombinedVFSCache.java
   projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/CustomLRUCachePolicy.java
   projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/TimedVFSCache.java
   projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java
   projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/registry/DefaultVFSRegistry.java
   projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/spi/VFSContext.java
   projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/spi/registry/VFSRegistry.java
   projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/support/MockVFSContextFactory.java
   projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/test/CombinedVFSCacheTestCase.java
Log:
[JBVFS-135]; fix VFS get -- use existing.

Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/VFS.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/VFS.java	2010-02-18 20:40:36 UTC (rev 101131)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/VFS.java	2010-02-18 21:29:45 UTC (rev 101132)
@@ -23,6 +23,7 @@
 
 import java.io.IOException;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.List;
 
@@ -180,11 +181,36 @@
     */
    public static VFS getVFS(URI rootURI) throws IOException
    {
+      return getVFS(rootURI, false);
+   }
+
+   /**
+    * Get the virtual file system for a root uri
+    *
+    * @param rootURI the root URI
+    * @param createNew do we create a new context
+    * @return the virtual file system
+    * @throws IOException if there is a problem accessing the VFS
+    * @throws IllegalArgumentException if the rootURL is null
+    */
+   private static VFS getVFS(URI rootURI, boolean createNew) throws IOException
+   {
+      VFSRegistry registry = VFSRegistry.getInstance();
+      VFSContext context = registry.getContext(rootURI);
+      if (context != null && createNew == false)
+         return context.getVFS();
+
       VFSContextFactory factory = VFSContextFactoryLocator.getFactory(rootURI);
       if (factory == null)
          throw new IOException("No context factory for " + rootURI);
 
-      VFSContext context = factory.getVFS(rootURI);
+      if (context != null)
+      {
+         registry.removeContext(context);
+         context.cleanup();
+      }
+
+      context = factory.getVFS(rootURI); // create new
       VFSRegistry.getInstance().addContext(context);
       return context.getVFS();
    }
@@ -199,7 +225,7 @@
     */
    public static VirtualFile createNewRoot(URI rootURI) throws IOException
    {
-      VFS vfs = getVFS(rootURI);
+      VFS vfs = getVFS(rootURI, true);
       return vfs.getRoot();
    }
 
@@ -234,6 +260,20 @@
       return root.findChild(name);
    }
 
+   private static URI toURI(URL url) throws IOException
+   {
+      try
+      {
+         return VFSUtils.toURI(url);
+      }
+      catch (URISyntaxException e)
+      {
+         IOException ioe = new IOException();
+         ioe.initCause(e);
+         throw ioe;
+      }
+   }
+
    /**
     * Get the virtual file system for a root url
     * 
@@ -244,13 +284,7 @@
     */
    public static VFS getVFS(URL rootURL) throws IOException
    {
-      VFSContextFactory factory = VFSContextFactoryLocator.getFactory(rootURL);
-      if (factory == null)
-         throw new IOException("No context factory for " + rootURL);
-
-      VFSContext context = factory.getVFS(rootURL);
-      VFSRegistry.getInstance().addContext(context);
-      return context.getVFS();
+      return getVFS(toURI(rootURL));
    }
 
    /**
@@ -263,8 +297,7 @@
     */
    public static VirtualFile createNewRoot(URL rootURL) throws IOException
    {
-      VFS vfs = getVFS(rootURL);
-      return vfs.getRoot();
+      return createNewRoot(toURI(rootURL));
    }
 
    /**
@@ -277,9 +310,7 @@
     */
    public static VirtualFile getRoot(URL rootURL) throws IOException
    {
-      VFSRegistry registry = VFSRegistry.getInstance();
-      VirtualFile file = registry.getFile(rootURL);
-      return (file != null) ? file : createNewRoot(rootURL);
+      return getRoot(toURI(rootURL));
    }
 
    /**
@@ -294,8 +325,7 @@
    @SuppressWarnings("deprecation")
    public static VirtualFile getVirtualFile(URL rootURL, String name) throws IOException
    {
-      VirtualFile root = getRoot(rootURL);
-      return root.findChild(name);
+      return getVirtualFile(toURI(rootURL), name);
    }
 
    /**

Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/CombinedVFSCache.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/CombinedVFSCache.java	2010-02-18 20:40:36 UTC (rev 101131)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/CombinedVFSCache.java	2010-02-18 21:29:45 UTC (rev 101132)
@@ -113,7 +113,7 @@
       if (context != null)
          return context;
 
-      return realCache.findContext(uri);
+      return (realCache != null) ? realCache.findContext(uri) : null;
    }
 
    public VFSContext findContext(URL url)

Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/CustomLRUCachePolicy.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/CustomLRUCachePolicy.java	2010-02-18 20:40:36 UTC (rev 101131)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/CustomLRUCachePolicy.java	2010-02-18 21:29:45 UTC (rev 101132)
@@ -49,7 +49,7 @@
       try
       {
          VFSContext context = (VFSContext) entry.m_object;
-         context.cleanupTempInfo(""); // cleanup from root
+         context.cleanup();
       }
       catch (Exception e)
       {

Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/TimedVFSCache.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/TimedVFSCache.java	2010-02-18 20:40:36 UTC (rev 101131)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/TimedVFSCache.java	2010-02-18 21:29:45 UTC (rev 101132)
@@ -190,7 +190,7 @@
       {
          try
          {
-            context.cleanupTempInfo(""); // cleanup from root
+            context.cleanup();
          }
          catch (Exception e)
          {

Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java	2010-02-18 20:40:36 UTC (rev 101131)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java	2010-02-18 21:29:45 UTC (rev 101132)
@@ -557,6 +557,14 @@
       return getOption(TempStore.class);
    }
 
+   public void cleanup()
+   {
+      cleanupTempInfo(""); // clear from root
+      TempStore store = getTempStore();
+      if (store != null)
+         store.clear();
+   }
+
    @Override
    public String toString()
    {

Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/registry/DefaultVFSRegistry.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/registry/DefaultVFSRegistry.java	2010-02-18 20:40:36 UTC (rev 101131)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/registry/DefaultVFSRegistry.java	2010-02-18 21:29:45 UTC (rev 101132)
@@ -83,6 +83,18 @@
       }
    }
 
+   public VFSContext getContext(URI uri) throws IOException
+   {
+      VFSContext context = getCache().findContext(uri);
+      if (context != null)
+      {
+         String relativePath = VFSUtils.getRelativePath(context, uri);
+         if (relativePath.length() == 0)
+            return context;
+      }
+      return null;
+   }
+
    public VirtualFile getFile(URI uri) throws IOException
    {
       if (uri == null)
@@ -129,21 +141,4 @@
       }
       return child;
    }
-
-   public VirtualFile getFile(URL url) throws IOException
-   {
-      if (url == null)
-         throw new IllegalArgumentException("Null url");
-
-      try
-      {
-         return getFile(VFSUtils.toURI(url));
-      }
-      catch (URISyntaxException e)
-      {
-         IOException ioe = new IOException();
-         ioe.initCause(e);
-         throw ioe;
-      }
-   }
 }

Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/spi/VFSContext.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/spi/VFSContext.java	2010-02-18 20:40:36 UTC (rev 101131)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/spi/VFSContext.java	2010-02-18 21:29:45 UTC (rev 101132)
@@ -189,4 +189,9 @@
     * @return the temp store
     */
    TempStore getTempStore();
+
+   /**
+    * Cleanup on cache eviction.
+    */
+   void cleanup();
 }

Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/spi/registry/VFSRegistry.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/spi/registry/VFSRegistry.java	2010-02-18 20:40:36 UTC (rev 101131)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/spi/registry/VFSRegistry.java	2010-02-18 21:29:45 UTC (rev 101132)
@@ -23,8 +23,10 @@
 
 import java.io.IOException;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 
+import org.jboss.virtual.VFSUtils;
 import org.jboss.virtual.VirtualFile;
 import org.jboss.virtual.spi.VFSContext;
 
@@ -60,6 +62,39 @@
    public abstract void removeContext(VFSContext context);
 
    /**
+    * Get the context.
+    *
+    * @param uri the uri to match
+    * @return matching context or null
+    * @throws IOException for any IO error
+    */
+   public abstract VFSContext getContext(URI uri) throws IOException;
+
+   /**
+    * Get the context.
+    *
+    * @param url the url to match
+    * @return matching context or null
+    * @throws IOException for any IO error
+    */
+   public VFSContext getContext(URL url) throws IOException
+   {
+      if (url == null)
+         throw new IllegalArgumentException("Null url");
+
+      try
+      {
+         return getContext(VFSUtils.toURI(url));
+      }
+      catch (URISyntaxException e)
+      {
+         IOException ioe = new IOException();
+         ioe.initCause(e);
+         throw ioe;
+      }
+   }
+
+   /**
     * Get the file.
     * Check the cache for cached entry,
     * return null if no matching entry exists.
@@ -79,5 +114,20 @@
     * @return virtual file instance or null if it doesn't exist in cache
     * @throws IOException for any error
     */
-   public abstract VirtualFile getFile(URL url) throws IOException;
+   public VirtualFile getFile(URL url) throws IOException
+   {
+      if (url == null)
+         throw new IllegalArgumentException("Null url");
+
+      try
+      {
+         return getFile(VFSUtils.toURI(url));
+      }
+      catch (URISyntaxException e)
+      {
+         IOException ioe = new IOException();
+         ioe.initCause(e);
+         throw ioe;
+      }
+   }
 }

Modified: projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/support/MockVFSContextFactory.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/support/MockVFSContextFactory.java	2010-02-18 20:40:36 UTC (rev 101131)
+++ projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/support/MockVFSContextFactory.java	2010-02-18 21:29:45 UTC (rev 101132)
@@ -78,6 +78,7 @@
    public VFSContext getVFS(URI rootURI) throws IOException
    {
       throwIOException("getVFSURI");
+      throwIOException("getVFSURL"); // simplify / no_duplicate in VFS
       VFSContext context = contexts.get(rootURI);
       if (context == null)
          throw new IOException("No such context " + rootURI);

Modified: projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/test/CombinedVFSCacheTestCase.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/test/CombinedVFSCacheTestCase.java	2010-02-18 20:40:36 UTC (rev 101131)
+++ projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/test/CombinedVFSCacheTestCase.java	2010-02-18 21:29:45 UTC (rev 101132)
@@ -76,7 +76,8 @@
          if (cache instanceof CombinedWrapperVFSCache)
          {
             CombinedWrapperVFSCache cwvc = (CombinedWrapperVFSCache)cache;
-            cwvc.getTemp().stop();
+            VFSCache temp = cwvc.getTemp();
+            temp.stop();
          }
          cache.stop();
       }




More information about the jboss-cvs-commits mailing list