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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Oct 30 08:27:19 EDT 2008


Author: alesj
Date: 2008-10-30 08:27:19 -0400 (Thu, 30 Oct 2008)
New Revision: 80240

Added:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/AbstractVFSCache.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/CachePolicyVFSCache.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/LRUVFSCache.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/MapVFSCache.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/SoftRefVFSCache.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/TimedVFSCache.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/WeakRefVFSCache.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSCache.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSCacheFactory.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/LRUCacheTestCase.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/SoftRefCacheTestCase.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/TimedCacheTestCase.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/WeakRefCacheTestCase.java
Modified:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVFSTest.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
Log:
[JBVFS-61]; simple vfs cache.

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java	2008-10-30 12:24:05 UTC (rev 80239)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -32,6 +32,7 @@
 import org.jboss.virtual.spi.VFSContextFactory;
 import org.jboss.virtual.spi.VFSContextFactoryLocator;
 import org.jboss.virtual.spi.VirtualFileHandler;
+import org.jboss.virtual.spi.VFSCacheFactory;
 import org.jboss.util.file.ArchiveBrowser;
 
 /**
@@ -39,6 +40,7 @@
  * 
  * @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> 
  * @version $Revision: 1.1 $
  */
 public class VFS
@@ -87,6 +89,7 @@
       if (factory == null)
          throw new IOException("No context factory for " + rootURI);
       VFSContext context = factory.getVFS(rootURI);
+      VFSCacheFactory.getInstance().putContext(context);
       return context.getVFS();
    }
 
@@ -133,6 +136,7 @@
       if (factory == null)
          throw new IOException("No context factory for " + rootURL);
       VFSContext context = factory.getVFS(rootURL);
+      VFSCacheFactory.getInstance().putContext(context);
       return context.getVFS();
    }
 

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java	2008-10-30 12:24:05 UTC (rev 80239)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -50,6 +50,7 @@
 import org.jboss.virtual.spi.LinkInfo;
 import org.jboss.virtual.spi.VFSContext;
 import org.jboss.virtual.spi.VirtualFileHandler;
+import org.jboss.virtual.spi.VFSCacheFactory;
 
 /**
  * VFS Utilities
@@ -106,6 +107,19 @@
    public static final String OPTIMIZE_FOR_MEMORY_KEY = "jboss.vfs.optimizeForMemory";
 
    /**
+    * Key used to determine VFS Cache impl
+    */
+   public static final String VFS_CACHE_KEY = "jboss.vfs.cache";
+
+   /**
+    * Stop cache.
+    */
+   public static void stopCache()
+   {
+      VFSCacheFactory.getInstance().stop();   
+   }
+
+   /**
     * Get the paths string for a collection of virtual files
     *
     * @param paths the paths

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/AbstractVFSCache.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/AbstractVFSCache.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/AbstractVFSCache.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -0,0 +1,216 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.virtual.plugins.cache;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.jboss.logging.Logger;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.vfs.helpers.PathTokenizer;
+import org.jboss.virtual.spi.VFSCache;
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * Abstract vfs cache.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractVFSCache implements VFSCache
+{
+   protected Logger log = Logger.getLogger(getClass());
+   
+   protected ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+
+   public VirtualFile getFile(URI uri) throws IOException
+   {
+      lock.readLock().lock();
+      VFSContext context;
+      try
+      {
+         context = findContext(uri);
+      }
+      finally
+      {
+         lock.readLock().unlock();
+      }
+      if (context != null)
+      {
+         VirtualFileHandler root = context.getRoot();
+         String relativePath = getRelativePath(context, uri);
+         VirtualFileHandler child = root.getChild(relativePath);
+         return child.getVirtualFile();
+      }
+      return VFS.getRoot(uri);
+   }
+
+   /**
+    * Get relative path.
+    *
+    * @param context the vfs context
+    * @param uri the uri
+    * @return uri's relative path to context's root
+    */
+   protected String getRelativePath(VFSContext context, URI uri)
+   {
+      String uriPath = stripProtocol(uri);
+      String contextKey = getKey(context);
+      return uriPath.substring(contextKey.length());
+   }
+
+   public VirtualFile getFile(URL url) throws IOException
+   {
+      try
+      {
+         return getFile(VFSUtils.toURI(url));
+      }
+      catch (URISyntaxException e)
+      {
+         IOException ioe = new IOException();
+         ioe.initCause(e);
+         throw ioe;
+      }
+   }
+
+   /**
+    * Strip protocol from url string.
+    *
+    * @param uri the uri
+    * @return uri's path string
+    */
+   protected static String stripProtocol(URI uri)
+   {
+      String path = uri.getPath();
+      if (path != null && path.length() > 0)
+      {
+         StringBuilder sb = new StringBuilder(path);
+
+         if (sb.charAt(0) != '/')
+            sb.insert(0, '/');
+         if (sb.charAt(sb.length() - 1) != '/')
+            sb.append('/');
+
+         path = sb.toString();
+      }
+      else
+      {
+         path = "/";
+      }
+
+      return path;
+   }
+
+   /**
+    * Get the cached context.
+    * @param path the path to match
+    * @return cached context or null if not found
+    */
+   protected abstract VFSContext getContext(String path);
+
+   /**
+    * Find cached context.
+    *
+    * @param uri the uri to match
+    * @return found context or null
+    */
+   protected VFSContext findContext(URI uri)
+   {
+      String uriString = stripProtocol(uri);
+      List<String> tokens = PathTokenizer.getTokens(uriString);
+      StringBuilder sb = new StringBuilder("/");
+      for (String token : tokens)
+      {
+         sb.append(token).append("/");
+         VFSContext context = getContext(sb.toString());
+         if (context != null)
+            return context;
+      }
+      return null;
+   }
+
+   /**
+    * Get path key.
+    *
+    * @param context the vfs context
+    * @return contex's root path w/o protocol
+    */
+   protected static String getKey(VFSContext context)
+   {
+      URI uri = context.getRootURI();
+      return stripProtocol(uri);
+   }
+
+   public void putContext(VFSContext context)
+   {
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+
+      lock.writeLock().lock();
+      try
+      {
+         putContext(getKey(context), context);
+      }
+      finally
+      {
+         lock.writeLock().unlock();
+      }
+   }
+
+   /**
+    * Put vfs context and its path key into cache.
+    *
+    * @param path the context's path
+    * @param context the vfs context
+    */
+   protected abstract void putContext(String path, VFSContext context);
+
+   public void removeContext(VFSContext context)
+   {
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+
+      lock.writeLock().lock();
+      try
+      {
+         removeContext(getKey(context), context);
+      }
+      finally
+      {
+         lock.writeLock().unlock();
+      }
+   }
+
+   /**
+    * Remove vfs context and its path key from cache.
+    *
+    * @param path the context's path
+    * @param context the vfs context
+    */
+   protected abstract void removeContext(String path, VFSContext context);
+}

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/CachePolicyVFSCache.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/CachePolicyVFSCache.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/CachePolicyVFSCache.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -0,0 +1,118 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.virtual.plugins.cache;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.jboss.util.CachePolicy;
+import org.jboss.virtual.spi.VFSContext;
+
+/**
+ * Cache policy vfs cache.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class CachePolicyVFSCache extends AbstractVFSCache
+{
+   private CachePolicy policy;
+   private boolean started;
+
+   public void start() throws Exception
+   {
+      policy = createCachePolicy();
+
+      policy.create();
+      policy.start();
+
+      started = true;
+   }
+
+   public void stop()
+   {
+      if (started)
+      {
+         policy.stop();
+         policy.destroy();
+      }
+   }
+
+   protected VFSContext getContext(String path)
+   {
+      return VFSContext.class.cast(policy.get(path));
+   }
+
+   protected void putContext(String path, VFSContext context)
+   {
+      Object result = policy.peek(path);
+      if (result == null)
+         policy.insert(path, context);
+   }
+
+   public void removeContext(String key, VFSContext context)
+   {
+      policy.remove(key);
+   }
+
+   /**
+    * Create cache policy.
+    *
+    * @return the cache policy
+    */
+   protected abstract CachePolicy createCachePolicy();
+
+   /**
+    * Read system property.
+    *
+    * @param key the property key
+    * @param defaultValue the default value
+    * @return system property or default value
+    */
+   protected static String readSystemProperty(final String key, final String defaultValue)
+   {
+      SecurityManager sm = System.getSecurityManager();
+      if (sm == null)
+         return System.getProperty(key, defaultValue);
+      else
+         return AccessController.doPrivileged(new PrivilegedAction<String>()
+         {
+            public String run()
+            {
+               return System.getProperty(key, defaultValue);
+            }
+         });
+   }
+
+   /**
+    * Parse integer.
+    *
+    * @param value the string int value
+    * @return integer value of null
+    */
+   protected static Integer parseInteger(String value)
+   {
+      if (value == null)
+         return null;
+
+      return Integer.parseInt(value);
+   }
+}
\ No newline at end of file

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/LRUVFSCache.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/LRUVFSCache.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/LRUVFSCache.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -0,0 +1,82 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.virtual.plugins.cache;
+
+import org.jboss.util.CachePolicy;
+import org.jboss.util.LRUCachePolicy;
+import org.jboss.virtual.VFSUtils;
+
+/**
+ * LRU cache policy vfs cache.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class LRUVFSCache extends CachePolicyVFSCache
+{
+   private Integer min;
+   private Integer max;
+
+   public LRUVFSCache()
+   {
+   }
+
+   public LRUVFSCache(Integer min, Integer max)
+   {
+      this.min = min;
+      this.max = max;
+   }
+
+   protected CachePolicy createCachePolicy()
+   {
+      if (min == null)
+         min = parseInteger(readSystemProperty(VFSUtils.VFS_CACHE_KEY + ".LRUPolicyCaching.min", null));
+      if (max == null)
+         max = parseInteger(readSystemProperty(VFSUtils.VFS_CACHE_KEY + ".LRUPolicyCaching.max", null));
+
+      if (min == null || max == null)
+         throw new IllegalArgumentException("Missing min (" + min + ") or max (" + max + ").");
+
+      log.debug("Creating LRU cache policy, min: " + min + ", max: " + max);
+
+      return new LRUCachePolicy(min, max);
+   }
+
+   /**
+    * Set min.
+    *
+    * @param min the min
+    */
+   public void setMin(Integer min)
+   {
+      this.min = min;
+   }
+
+   /**
+    * set max.
+    *
+    * @param max the max
+    */
+   public void setMax(Integer max)
+   {
+      this.max = max;
+   }
+}
\ No newline at end of file

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/MapVFSCache.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/MapVFSCache.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/MapVFSCache.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -0,0 +1,69 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.virtual.plugins.cache;
+
+import java.util.Map;
+
+import org.jboss.virtual.spi.VFSContext;
+
+/**
+ * Map vfs cache.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class MapVFSCache extends AbstractVFSCache
+{
+   private Map<String, VFSContext> cache;
+
+   protected VFSContext getContext(String path)
+   {
+      return cache.get(path);
+   }
+
+   protected void putContext(String path, VFSContext context)
+   {
+      cache.put(path, context);
+   }
+
+   protected void removeContext(String path, VFSContext context)
+   {
+      cache.remove(path);
+   }
+
+   /**
+    * Create cache map.
+    *
+    * @return cache map
+    */
+   protected abstract Map<String, VFSContext> createMap();
+
+   public void start() throws Exception
+   {
+      cache = createMap();
+   }
+
+   public void stop()
+   {
+      if (cache != null)
+         cache.clear();
+   }
+}
\ No newline at end of file

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/SoftRefVFSCache.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/SoftRefVFSCache.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/SoftRefVFSCache.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.virtual.plugins.cache;
+
+import java.util.Map;
+
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.util.collection.SoftValueHashMap;
+
+/**
+ * SoftRef vfs cache.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class SoftRefVFSCache extends MapVFSCache
+{
+   @SuppressWarnings("unchecked")
+   protected Map<String, VFSContext> createMap()
+   {
+      return new SoftValueHashMap();
+   }
+}
\ No newline at end of file

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/TimedVFSCache.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/TimedVFSCache.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/TimedVFSCache.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -0,0 +1,103 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.virtual.plugins.cache;
+
+import org.jboss.util.CachePolicy;
+import org.jboss.util.TimedCachePolicy;
+import org.jboss.virtual.VFSUtils;
+
+/**
+ * Timed cache policy vfs cache.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TimedVFSCache extends CachePolicyVFSCache
+{
+   private Integer defaultLifetime;
+   private Boolean threadSafe;
+   private Integer resolution;
+
+   public TimedVFSCache()
+   {
+   }
+
+   public TimedVFSCache(Integer defaultLifetime)
+   {
+      this(defaultLifetime, null, null);
+   }
+
+   public TimedVFSCache(Integer defaultLifetime, Boolean threadSafe, Integer resolution)
+   {
+      this.defaultLifetime = defaultLifetime;
+      this.threadSafe = threadSafe;
+      this.resolution = resolution;
+   }
+
+   protected CachePolicy createCachePolicy()
+   {
+      if (defaultLifetime == null)
+         defaultLifetime = parseInteger(readSystemProperty(VFSUtils.VFS_CACHE_KEY + ".TimedPolicyCaching.lifetime", null));
+      if (threadSafe == null)
+         threadSafe = Boolean.valueOf(readSystemProperty(VFSUtils.VFS_CACHE_KEY + ".TimedPolicyCaching.threadSafe", Boolean.TRUE.toString()));
+      if (resolution == null)
+         resolution = parseInteger(readSystemProperty(VFSUtils.VFS_CACHE_KEY + ".TimedPolicyCaching.resolution", null));
+
+      log.debug("Creating timed cache policy, lifetime: " + defaultLifetime + ", threadSafe: " + threadSafe + ", resolution: " + resolution);
+
+      if (defaultLifetime == null)
+         return new TimedCachePolicy();
+      else if (resolution != null)
+         return new TimedCachePolicy(defaultLifetime, threadSafe, resolution);
+      else
+         return new TimedCachePolicy(defaultLifetime);
+   }
+
+   /**
+    * Set default lifetime.
+    *
+    * @param defaultLifetime the default lifetime
+    */
+   public void setDefaultLifetime(Integer defaultLifetime)
+   {
+      this.defaultLifetime = defaultLifetime;
+   }
+
+   /**
+    * Set threadsafe flag.
+    *
+    * @param threadSafe the threadsafe flag
+    */
+   public void setThreadSafe(Boolean threadSafe)
+   {
+      this.threadSafe = threadSafe;
+   }
+
+   /**
+    * The resollution.
+    *
+    * @param resolution the resolution
+    */
+   public void setResolution(Integer resolution)
+   {
+      this.resolution = resolution;
+   }
+}
\ No newline at end of file

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/WeakRefVFSCache.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/WeakRefVFSCache.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/WeakRefVFSCache.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.virtual.plugins.cache;
+
+import java.util.Map;
+
+import org.jboss.util.collection.WeakValueHashMap;
+import org.jboss.virtual.spi.VFSContext;
+
+/**
+ * WeakRef vfs cache.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class WeakRefVFSCache extends MapVFSCache
+{
+   @SuppressWarnings("unchecked")
+   protected Map<String, VFSContext> createMap()
+   {
+      return new WeakValueHashMap();
+   }
+}
\ No newline at end of file

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java	2008-10-30 12:24:05 UTC (rev 80239)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -25,12 +25,10 @@
 import java.io.InputStream;
 import java.net.URL;
 import java.net.URLConnection;
-import java.util.Collections;
-import java.util.Map;
 
-import org.jboss.util.collection.SoftValueHashMap;
-import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.spi.VFSCache;
+import org.jboss.virtual.spi.VFSCacheFactory;
 
 /**
  * Implements basic URLConnection for a VirtualFile
@@ -41,9 +39,6 @@
  */
 public class VirtualFileURLConnection extends URLConnection
 {
-   @SuppressWarnings("unchecked")
-   public static Map<URL, VFS> urlCache = Collections.<URL, VFS>synchronizedMap(new SoftValueHashMap());
-
    protected VirtualFile file;
    protected URL vfsurl;
    protected String relativePath;
@@ -102,31 +97,15 @@
    @SuppressWarnings("deprecation")
    protected static VirtualFile resolveCachedVirtualFile(URL vfsurl, String relativePath) throws IOException
    {
-      VFS vfs = urlCache.get(vfsurl);
-      if (vfs == null)
-      {
-         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().hasBeenModified())
-         {
-            vfs = VFS.getVFS(vfsurl);
-            urlCache.put(vfsurl, vfs);
-         }
-      }
-      return vfs.findChild(relativePath);
+      return resolveVirtualFile(vfsurl, relativePath);
    }
 
    @SuppressWarnings("deprecation")
    protected static VirtualFile resolveVirtualFile(URL vfsurl, String relativePath) throws IOException
    {
-      VFS vfs = VFS.getVFS(vfsurl);
-      return vfs.findChild(relativePath);
+      VFSCache cache = VFSCacheFactory.getInstance();
+      VirtualFile file = cache.getFile(vfsurl);
+      return file.findChild(relativePath);
    }
 
    /**
@@ -138,16 +117,8 @@
    protected synchronized VirtualFile getVirtualFile() throws IOException
    {
       if (file == null)
-      {
-         if (getUseCaches())
-         {
-            file = resolveCachedVirtualFile(vfsurl, relativePath);
-         }
-         else
-         {
-            file = resolveVirtualFile(vfsurl, relativePath);
-         }
-      }
+         file = resolveVirtualFile(vfsurl, relativePath);
+      
       return file;
    }
 }

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSCache.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSCache.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSCache.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -0,0 +1,80 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.virtual.spi;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Simple vfs cache interface.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface VFSCache
+{
+   /**
+    * Get the file.
+    *
+    * @param uri the file's uri
+    * @return virtual file instance
+    * @throws IOException for any error
+    */
+   VirtualFile getFile(URI uri) throws IOException;
+
+   /**
+    * Get the file.
+    *
+    * @param url the file's url
+    * @return virtual file instance
+    * @throws IOException for any error
+    */
+   VirtualFile getFile(URL url) throws IOException;
+
+   /**
+    * Put vfs context to cache.
+    *
+    * @param context the vfs context
+    */
+   void putContext(VFSContext context);
+
+   /**
+    * Remove vfs context from cache.
+    *
+    * @param context the vfs context
+    */
+   void removeContext(VFSContext context);
+
+   /**
+    * Start the cache.
+    *
+    * @throws Exception for any error
+    */
+   void start() throws Exception;
+
+   /**
+    * Stop the cache.
+    */
+   void stop();
+}

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSCacheFactory.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSCacheFactory.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSCacheFactory.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -0,0 +1,151 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.virtual.spi;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.jboss.logging.Logger;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Simple vfs cache factory.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class VFSCacheFactory
+{
+   private static final Object lock = new Object();
+   private static Logger log = Logger.getLogger(VFSCacheFactory.class);
+
+   private static VFSCache instance;
+
+   private VFSCacheFactory()
+   {
+   }
+
+   /**
+    * Get VFS cache instance.
+    *
+    * @return the vfs cache instance
+    */
+   public static VFSCache getInstance()
+   {
+      if (instance == null)
+      {
+         synchronized (lock)
+         {
+            instance = AccessController.doPrivileged(new VFSCacheCreatorAction());
+         }
+      }
+
+      return instance;
+   }
+
+   /**
+    * Set instance.
+    *
+    * This should be used with care.
+    * Better to leave it to getInstance method creation.
+    *
+    * @param cache cache instance to set
+    */
+   public static void setInstance(VFSCache cache)
+   {
+      if (cache != null && instance != null && instance instanceof NoopVFSCache == false)
+         throw new IllegalArgumentException("Instance already set!");
+
+      instance = cache;
+   }
+
+   private static class VFSCacheCreatorAction implements PrivilegedAction<VFSCache>
+   {
+      public VFSCache run()
+      {
+         try
+         {
+            String className = System.getProperty(VFSUtils.VFS_CACHE_KEY);
+            if (className != null)
+            {
+               ClassLoader cl = VFSCacheFactory.class.getClassLoader();
+               Class<?> clazz = cl.loadClass(className);
+               VFSCache cache = VFSCache.class.cast(clazz.newInstance());
+               cache.start(); // start here, so we fall back to default no-op in case start fails
+               return cache;
+            }
+         }
+         catch (Throwable t)
+         {
+            log.warn("Exception instantiating VFS cache: " + t);
+         }
+         return new NoopVFSCache();
+      }
+   }
+
+   /**
+    * Noop cache.
+    * Doesn't do any caching.
+    */
+   private static class NoopVFSCache implements VFSCache
+   {
+      public VirtualFile getFile(URI uri) throws IOException
+      {
+         return VFS.getRoot(uri);
+      }
+
+      public VirtualFile getFile(URL url) throws IOException
+      {
+         try
+         {
+            return getFile(VFSUtils.toURI(url));
+         }
+         catch (URISyntaxException e)
+         {
+            IOException ioe = new IOException();
+            ioe.initCause(e);
+            throw ioe;
+         }
+      }
+
+      public void putContext(VFSContext context)
+      {
+      }
+
+      public void removeContext(VFSContext context)
+      {
+      }
+
+      public void start() throws Exception
+      {
+      }
+
+      public void stop()
+      {
+      }
+   }
+}
\ No newline at end of file

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVFSTest.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVFSTest.java	2008-10-30 12:24:05 UTC (rev 80239)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVFSTest.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -69,6 +69,18 @@
    {
       super.setUp();
 
+/*
+      // LRU
+      System.setProperty(VFSUtils.VFS_CACHE_KEY, LRUVFSCache.class.getName());
+      System.setProperty(VFSUtils.VFS_CACHE_KEY + ".LRUPolicyCaching.min", "2");
+      System.setProperty(VFSUtils.VFS_CACHE_KEY + ".LRUPolicyCaching.max", "100");
+*/
+/*
+      // Timed
+      System.setProperty(VFSUtils.VFS_CACHE_KEY, TimedVFSCache.class.getName());
+      System.setProperty(VFSUtils.VFS_CACHE_KEY + ".TimedPolicyCaching.lifetime", "60");
+*/
+
       VFSContextFactoryLocator.registerFactory(fileFactory);
       VFSContextFactoryLocator.registerFactory(jarFactory);
 

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java	2008-10-30 12:24:05 UTC (rev 80239)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -1485,11 +1485,11 @@
       VFS vfs = VFS.getVFS(rootURL);
       URL[] cp = {vfs.getRoot().toURL()};
       URLClassLoader ucl = new URLClassLoader(cp);
-      // Search for a non-existent absolute resource
-      URL qp = ucl.findResource("/nosuch-quartz.props");
-      assertNull("findResource(/nosuch-quartz.props)", qp);
-      InputStream is = ucl.getResourceAsStream("/nosuch-quartz.props");
-      assertNull("getResourceAsStream(/nosuch-quartz.props)", is);
+      // Search for a non-existent resource
+      URL qp = ucl.findResource("nosuch-quartz.props");
+      assertNull("findResource(nosuch-quartz.props)", qp);
+      InputStream is = ucl.getResourceAsStream("nosuch-quartz.props");
+      assertNull("getResourceAsStream(nosuch-quartz.props)", is);
    }
 
    /**

Added: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/LRUCacheTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/LRUCacheTestCase.java	                        (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/LRUCacheTestCase.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -0,0 +1,49 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.virtual.test;
+
+import junit.framework.Test;
+import org.jboss.virtual.plugins.cache.LRUVFSCache;
+import org.jboss.virtual.spi.VFSCache;
+
+/**
+ * LRU VFSCache Test.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class LRUCacheTestCase extends VFSCacheTest
+{
+   public LRUCacheTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(LRUCacheTestCase.class);
+   }
+
+   protected VFSCache createCache()
+   {
+      return new LRUVFSCache(2, 10);
+   }
+}
\ No newline at end of file

Added: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/SoftRefCacheTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/SoftRefCacheTestCase.java	                        (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/SoftRefCacheTestCase.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -0,0 +1,49 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.virtual.test;
+
+import org.jboss.virtual.plugins.cache.SoftRefVFSCache;
+import org.jboss.virtual.spi.VFSCache;
+import junit.framework.Test;
+
+/**
+ * SoftRef VFSCache Test.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class SoftRefCacheTestCase extends VFSCacheTest
+{
+   public SoftRefCacheTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(SoftRefCacheTestCase.class);
+   }
+
+   protected VFSCache createCache()
+   {
+      return new SoftRefVFSCache();
+   }
+}
\ No newline at end of file

Added: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/TimedCacheTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/TimedCacheTestCase.java	                        (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/TimedCacheTestCase.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -0,0 +1,49 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.virtual.test;
+
+import org.jboss.virtual.plugins.cache.TimedVFSCache;
+import org.jboss.virtual.spi.VFSCache;
+import junit.framework.Test;
+
+/**
+ * Timed VFSCache Test.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TimedCacheTestCase extends VFSCacheTest
+{
+   public TimedCacheTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(TimedCacheTestCase.class);
+   }
+
+   protected VFSCache createCache()
+   {
+      return new TimedVFSCache(60);
+   }
+}
\ No newline at end of file

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java	2008-10-30 12:24:05 UTC (rev 80239)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -86,6 +86,11 @@
       // custom
       suite.addTest(CustomTestCase.suite());
       suite.addTest(VFSResourceTestCase.suite());
+      // cache
+      suite.addTest(LRUCacheTestCase.suite());
+      suite.addTest(TimedCacheTestCase.suite());
+      suite.addTest(SoftRefCacheTestCase.suite());
+      suite.addTest(WeakRefCacheTestCase.suite());
 
       return suite;
    }

Copied: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java (from rev 79734, projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVFSTest.java)
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java	                        (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -0,0 +1,116 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.virtual.test;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.spi.VFSCache;
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.VFSCacheFactory;
+
+/**
+ * VFSCache Test.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class VFSCacheTest extends AbstractVFSTest
+{
+   public VFSCacheTest(String name)
+   {
+      super(name);
+   }
+
+   protected abstract VFSCache createCache();
+
+   public void testCache() throws Exception
+   {
+      URL url = getResource("/vfs/test");
+
+      VFSCache cache = createCache();
+      cache.start();
+      try
+      {
+         VFSCacheFactory.setInstance(cache);
+         try
+         {
+            VirtualFile root = VFS.getRoot(url);
+            VirtualFile file = root.findChild("/nested/nested.jar/META-INF/empty.txt");
+            URL fileURL = file.toURL();
+
+            assertEquals(file, cache.getFile(fileURL));
+            VFSCacheFactory.setInstance(null);
+            VFSCache wrapper = new WrapperVFSCache(cache);
+            VFSCacheFactory.setInstance(wrapper);
+            assertEquals(file, wrapper.getFile(fileURL));
+         }
+         finally
+         {
+            VFSCacheFactory.setInstance(null);
+         }
+      }
+      finally
+      {
+         cache.stop();
+      }
+   }
+
+   private class WrapperVFSCache implements VFSCache
+   {
+      private VFSCache delegate;
+
+      private WrapperVFSCache(VFSCache delegate)
+      {
+         this.delegate = delegate;
+      }
+
+      public VirtualFile getFile(URI uri) throws IOException
+      {
+         return delegate.getFile(uri);
+      }
+
+      public VirtualFile getFile(URL url) throws IOException
+      {
+         return delegate.getFile(url);
+      }
+
+      public void putContext(VFSContext context)
+      {
+         throw new IllegalArgumentException("Context should already be there: " + context);
+      }
+
+      public void removeContext(VFSContext context)
+      {
+      }
+
+      public void start() throws Exception
+      {
+      }
+
+      public void stop()
+      {
+      }
+   }
+}
\ No newline at end of file

Added: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/WeakRefCacheTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/WeakRefCacheTestCase.java	                        (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/WeakRefCacheTestCase.java	2008-10-30 12:27:19 UTC (rev 80240)
@@ -0,0 +1,49 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.virtual.test;
+
+import org.jboss.virtual.plugins.cache.WeakRefVFSCache;
+import org.jboss.virtual.spi.VFSCache;
+import junit.framework.Test;
+
+/**
+ * SoftRef VFSCache Test.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class WeakRefCacheTestCase extends VFSCacheTest
+{
+   public WeakRefCacheTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(WeakRefCacheTestCase.class);
+   }
+
+   protected VFSCache createCache()
+   {
+      return new WeakRefVFSCache();
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list