[jboss-cvs] JBossAS SVN: r80335 - projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Nov 2 04:34:46 EST 2008


Author: alesj
Date: 2008-11-02 04:34:46 -0500 (Sun, 02 Nov 2008)
New Revision: 80335

Added:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/IterableVFSCache.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/PathMatchingVFSCache.java
Modified:
   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/MapVFSCache.java
Log:
Change how we find VFSContext in diff cache impls.

Modified: 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	2008-11-02 09:10:55 UTC (rev 80334)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/AbstractVFSCache.java	2008-11-02 09:34:46 UTC (rev 80335)
@@ -25,18 +25,16 @@
 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.cache.VFSCache;
-import org.jboss.virtual.spi.cache.CacheStatistics;
 import org.jboss.virtual.spi.VFSContext;
 import org.jboss.virtual.spi.VirtualFileHandler;
+import org.jboss.virtual.spi.cache.CacheStatistics;
+import org.jboss.virtual.spi.cache.VFSCache;
 
 /**
  * Abstract vfs cache.
@@ -47,7 +45,7 @@
 {
    protected Logger log = Logger.getLogger(getClass());
    
-   protected ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+   private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
    private long timestamp;
 
    public long lastInsert()
@@ -143,32 +141,12 @@
 
    /**
     * Find cached context.
+    * This method must take read lock.
     *
     * @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("/");
-      lock.readLock().lock();
-      try
-      {
-         for (String token : tokens)
-         {
-            sb.append(token).append("/");
-            VFSContext context = getContext(sb.toString());
-            if (context != null)
-               return context;
-         }
-      }
-      finally
-      {
-         lock.readLock().unlock();
-      }
-      return null;
-   }
+   protected abstract VFSContext findContext(URI uri);
 
    /**
     * Get path key.
@@ -190,7 +168,7 @@
       check();
 
       String path = getKey(context);
-      lock.writeLock().lock();
+      writeLock();
       try
       {
          putContext(path, context);
@@ -198,7 +176,7 @@
       }
       finally
       {
-         lock.writeLock().unlock();
+         writeUnlock();
       }
    }
 
@@ -218,14 +196,14 @@
       check();
 
       String path = getKey(context);
-      lock.writeLock().lock();
+      writeLock();
       try
       {
          removeContext(path, context);
       }
       finally
       {
-         lock.writeLock().unlock();
+         writeUnlock();
       }
    }
 
@@ -236,4 +214,36 @@
     * @param context the vfs context
     */
    protected abstract void removeContext(String path, VFSContext context);
+
+   /**
+    * Read lock.
+    */
+   protected void readLock()
+   {
+      lock.readLock().lock();
+   }
+
+   /**
+    * Read unlock.
+    */
+   protected void readUnlock()
+   {
+      lock.readLock().unlock();
+   }
+
+   /**
+    * Write lock.
+    */
+   protected void writeLock()
+   {
+      lock.writeLock().lock();
+   }
+
+   /**
+    * Write unlock.
+    */
+   protected void writeUnlock()
+   {
+      lock.writeLock().unlock();
+   }
 }

Modified: 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	2008-11-02 09:10:55 UTC (rev 80334)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/CachePolicyVFSCache.java	2008-11-02 09:34:46 UTC (rev 80335)
@@ -33,7 +33,7 @@
  *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
-public abstract class CachePolicyVFSCache extends AbstractVFSCache
+public abstract class CachePolicyVFSCache extends PathMatchingVFSCache
 {
    private CachePolicy policy;
    private boolean started;

Copied: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/IterableVFSCache.java (from rev 80257, projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/AbstractVFSCache.java)
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/IterableVFSCache.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/IterableVFSCache.java	2008-11-02 09:34:46 UTC (rev 80335)
@@ -0,0 +1,64 @@
+/*
+* 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.net.URI;
+
+import org.jboss.virtual.spi.VFSContext;
+
+/**
+ * Iterable vfs cache.
+ *
+ * Knows how to iterate over cache keys,
+ * matching them to uri's path.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class IterableVFSCache extends AbstractVFSCache
+{
+   /**
+    * Get cache keys.
+    *
+    * @return the cache keys
+    */
+   protected abstract Iterable<String> getKeys();
+
+   protected VFSContext findContext(URI uri)
+   {
+      String uriString = stripProtocol(uri);
+      Iterable<String> keys = getKeys();
+      readLock();
+      try
+      {
+         for (String key : keys)
+         {
+            if (uriString.startsWith(key))
+               return getContext(key);
+         }
+      }
+      finally
+      {
+         readUnlock();
+      }
+      return null;
+   }
+}
\ No newline at end of file

Modified: 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	2008-11-02 09:10:55 UTC (rev 80334)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/MapVFSCache.java	2008-11-02 09:34:46 UTC (rev 80335)
@@ -31,7 +31,7 @@
  *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
-public abstract class MapVFSCache extends AbstractVFSCache
+public abstract class MapVFSCache extends IterableVFSCache
 {
    private Map<String, VFSContext> cache;
 
@@ -54,6 +54,11 @@
          throw new IllegalArgumentException("Cache needs to be started first.");
    }
 
+   protected Iterable<String> getKeys()
+   {
+      return cache.keySet();
+   }
+
    protected VFSContext getContext(String path)
    {
       return cache.get(path);

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/PathMatchingVFSCache.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/PathMatchingVFSCache.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/PathMatchingVFSCache.java	2008-11-02 09:34:46 UTC (rev 80335)
@@ -0,0 +1,65 @@
+/*
+* 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.net.URI;
+import java.util.List;
+
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.plugins.vfs.helpers.PathTokenizer;
+
+/**
+ * Iterable vfs cache.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class PathMatchingVFSCache extends AbstractVFSCache
+{
+   /**
+    * Match the uri's path with cached contexts path.
+    *
+    * @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("/");
+      readLock();
+      try
+      {
+         for (String token : tokens)
+         {
+            sb.append(token).append("/");
+            VFSContext context = getContext(sb.toString());
+            if (context != null)
+               return context;
+         }
+      }
+      finally
+      {
+         readUnlock();
+      }
+      return null;
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list