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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue May 5 11:04:31 EDT 2009


Author: alesj
Date: 2009-05-05 11:04:30 -0400 (Tue, 05 May 2009)
New Revision: 88221

Added:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContextConstraints.java
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/file/FileSystemContext.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/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/test/MemoryTestCase.java
Log:
[JBVFS-109]; add vfs constraints for context caching purpose.

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-05-05 14:52:00 UTC (rev 88220)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java	2009-05-05 15:04:30 UTC (rev 88221)
@@ -30,6 +30,8 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.Collections;
 import java.util.Map.Entry;
 
 import org.jboss.logging.Logger;
@@ -46,6 +48,7 @@
 import org.jboss.virtual.spi.VFSContext;
 import org.jboss.virtual.spi.VirtualFileHandler;
 import org.jboss.virtual.spi.VirtualFileHandlerVisitor;
+import org.jboss.virtual.spi.VFSContextConstraints;
 
 /**
  * AbstractVFSContext.
@@ -104,6 +107,11 @@
       this(rootURL.toURI());
    }
 
+   public Set<VFSContextConstraints> getConstraints()
+   {
+      return Collections.emptySet();
+   }
+
    /**
     * Create options.
     *

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-05-05 14:52:00 UTC (rev 88220)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java	2009-05-05 15:04:30 UTC (rev 88221)
@@ -29,8 +29,10 @@
 import java.net.URL;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
+import java.util.Set;
 
 import org.jboss.logging.Logger;
 import org.jboss.virtual.VFSUtils;
@@ -40,6 +42,7 @@
 import org.jboss.virtual.plugins.context.jar.JarUtils;
 import org.jboss.virtual.plugins.context.zip.ZipEntryContext;
 import org.jboss.virtual.spi.LinkInfo;
+import org.jboss.virtual.spi.VFSContextConstraints;
 import org.jboss.virtual.spi.VirtualFileHandler;
 
 /**
@@ -85,6 +88,9 @@
          staticLog.debug("VFS forced case sensitivity is enabled.");
    }
 
+   /** The constraints set */
+   private static final Set<VFSContextConstraints> CONSTRAINTS = Collections.singleton(VFSContextConstraints.CACHEABLE);
+
    /** The temp file */
    private transient volatile File file;
 
@@ -195,6 +201,11 @@
       this.file = file;
    }
 
+   public Set<VFSContextConstraints> getConstraints()
+   {
+      return CONSTRAINTS;
+   }
+
    public String getName()
    {
       return (root != null) ? root.getName() : file.getName();

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-05-05 14:52:00 UTC (rev 88220)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java	2009-05-05 15:04:30 UTC (rev 88221)
@@ -47,6 +47,7 @@
 import java.util.Map;
 import java.util.TreeMap;
 import java.util.UUID;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
@@ -64,6 +65,7 @@
 import org.jboss.virtual.spi.TempInfo;
 import org.jboss.virtual.spi.VFSContext;
 import org.jboss.virtual.spi.VirtualFileHandler;
+import org.jboss.virtual.spi.VFSContextConstraints;
 
 /**
  * <tt>ZipEntryContext</tt> implements a {@link org.jboss.virtual.spi.VFSContext}
@@ -118,6 +120,9 @@
    /** The empty bytes const */
    private static final byte[] NO_BYTES = new byte[0];
 
+   /** The constraints set */
+   private static final Set<VFSContextConstraints> CONSTRAINTS = Collections.singleton(VFSContextConstraints.CACHEABLE);
+
    /** Abstracted access to zip archive - either ZipFileWrapper or ZipStreamWrapper */
    private volatile ZipWrapper zipSource;
 
@@ -440,6 +445,11 @@
       throw new IllegalArgumentException("No such entry: " + is + ", " + relative);
    }
 
+   public Set<VFSContextConstraints> getConstraints()
+   {
+      return CONSTRAINTS;
+   }
+
    /**
     * Returns archive file name - if this is a top-level ZipEntryContext.
     * Otherwise it returns the last component of URL.

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-05-05 14:52:00 UTC (rev 88220)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/registry/DefaultVFSRegistry.java	2009-05-05 15:04:30 UTC (rev 88221)
@@ -32,6 +32,7 @@
 import org.jboss.virtual.spi.VFSContext;
 import org.jboss.virtual.spi.VirtualFileHandler;
 import org.jboss.virtual.spi.TempInfo;
+import org.jboss.virtual.spi.VFSContextConstraints;
 import org.jboss.virtual.spi.cache.VFSCache;
 import org.jboss.virtual.spi.cache.VFSCacheFactory;
 import org.jboss.virtual.spi.registry.VFSRegistry;
@@ -55,12 +56,18 @@
 
    public void addContext(VFSContext context)
    {
-      getCache().putContext(context);
+      if (context.getConstraints().contains(VFSContextConstraints.CACHEABLE))
+      {
+         getCache().putContext(context);
+      }
    }
 
    public void removeContext(VFSContext context)
    {
-      getCache().removeContext(context);
+      if (context.getConstraints().contains(VFSContextConstraints.CACHEABLE))
+      {
+         getCache().removeContext(context);
+      }
    }
 
    public VirtualFile getFile(URI uri) throws IOException

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-05-05 14:52:00 UTC (rev 88220)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java	2009-05-05 15:04:30 UTC (rev 88221)
@@ -24,6 +24,7 @@
 import java.io.IOException;
 import java.net.URI;
 import java.util.List;
+import java.util.Set;
 
 import org.jboss.virtual.VFS;
 
@@ -38,6 +39,13 @@
 public interface VFSContext
 {
    /**
+    * Get context's constraints.
+    *
+    * @return the constraints
+    */
+   Set<VFSContextConstraints> getConstraints();
+
+   /**
     * Get the name.
     *
     * @return the name

Copied: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContextConstraints.java (from rev 87764, projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java)
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContextConstraints.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContextConstraints.java	2009-05-05 15:04:30 UTC (rev 88221)
@@ -0,0 +1,34 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, 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;
+
+/**
+ * A virtual file context constraints enum.
+ * It describes the context's constraints.
+ * e.g. can we cache it
+ *
+ * @author ales.justin at jboss.org
+ */
+public enum VFSContextConstraints
+{
+   CACHEABLE
+}
\ No newline at end of file

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/MemoryTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/MemoryTestCase.java	2009-05-05 14:52:00 UTC (rev 88220)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/MemoryTestCase.java	2009-05-05 15:04:30 UTC (rev 88221)
@@ -394,6 +394,15 @@
          VirtualFile file = VFS.getRoot(url);
          assertNotNull(file);
       }
+
+      // duplicate resources call, after contexts have been populated
+      urls = cl.getResources("");
+      while (urls.hasMoreElements())
+      {
+         URL url = urls.nextElement();
+         VirtualFile file = VFS.getRoot(url);
+         assertNotNull(file);
+      }
    }
 
    protected void setUp() throws Exception




More information about the jboss-cvs-commits mailing list