[jboss-cvs] JBossAS SVN: r82697 - in projects/vfs/trunk/src: test/java/org/jboss/test/virtual/test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jan 8 09:10:46 EST 2009
Author: alesj
Date: 2009-01-08 09:10:46 -0500 (Thu, 08 Jan 2009)
New Revision: 82697
Added:
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/CombinedVFSCache.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/CombinedVFSCacheTestCase.java
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/VFSCacheTest.java
Log:
[JBVFS-84]; combined vfs cache.
Copied: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/CombinedVFSCache.java (from rev 81461, projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/AbstractVFSCache.java)
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/CombinedVFSCache.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/CombinedVFSCache.java 2009-01-08 14:10:46 UTC (rev 82697)
@@ -0,0 +1,207 @@
+/*
+* 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.URL;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.cache.CacheStatistics;
+import org.jboss.virtual.spi.cache.VFSCache;
+import org.jboss.virtual.spi.cache.helpers.NoopVFSCache;
+
+/**
+ * Combined vfs cache - permanent entries + real cache.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class CombinedVFSCache implements VFSCache, CacheStatistics
+{
+ private boolean initializing;
+
+ private MapVFSCache permanentCache = new PermanentVFSCache();
+ private VFSCache realCache;
+
+ /**
+ * Set permanent roots.
+ *
+ * @param permanentRootUrls the permanent roots urls
+ * @throws IOException for any error
+ */
+ public void setPermanentRoots(URL... permanentRootUrls) throws IOException
+ {
+ if (permanentRootUrls != null)
+ {
+ initializing = true;
+ for (URL url : permanentRootUrls)
+ {
+ VFS.getRoot(url);
+ }
+ initializing = false;
+ }
+ }
+
+ /**
+ * Set the real cache.
+ *
+ * @param realCache the real cache
+ */
+ public void setRealCache(VFSCache realCache)
+ {
+ this.realCache = realCache;
+ }
+
+ /**
+ * Check at create.
+ */
+ public void create()
+ {
+ check();
+ }
+
+ /**
+ * Check if real cache has been set.
+ */
+ public void check()
+ {
+ if (realCache == null)
+ realCache = new NoopVFSCache();
+ }
+
+ public long lastInsert()
+ {
+ if (realCache instanceof CacheStatistics)
+ {
+ return CacheStatistics.class.cast(realCache).lastInsert();
+ }
+ return -1l;
+ }
+
+ public VirtualFile getFile(URI uri) throws IOException
+ {
+ VirtualFile file = permanentCache.getFile(uri);
+ if (file != null)
+ return file;
+
+ check();
+ return realCache.getFile(uri);
+ }
+
+ public VirtualFile getFile(URL url) throws IOException
+ {
+ try
+ {
+ return getFile(url.toURI());
+ }
+ catch (URISyntaxException e)
+ {
+ IOException ioe = new IOException();
+ ioe.initCause(e);
+ throw ioe;
+ }
+ }
+
+ public void putContext(VFSContext context)
+ {
+ if (initializing)
+ {
+ permanentCache.putContext(context);
+ }
+ else
+ {
+ check();
+ realCache.putContext(context);
+ }
+ }
+
+ public void removeContext(VFSContext context)
+ {
+ check();
+ realCache.removeContext(context);
+ }
+
+ public void start() throws Exception
+ {
+ permanentCache.start();
+ }
+
+ public void stop()
+ {
+ permanentCache.stop();
+ }
+
+ public void flush()
+ {
+ permanentCache.flush();
+ check();
+ realCache.flush();
+ }
+
+ public Iterable<VFSContext> getCachedContexts()
+ {
+ List<VFSContext> contexts = new ArrayList<VFSContext>();
+
+ for (VFSContext context : permanentCache.getCachedContexts())
+ contexts.add(context);
+
+ if (realCache instanceof CacheStatistics)
+ {
+ CacheStatistics cs = CacheStatistics.class.cast(realCache);
+ for (VFSContext context : cs.getCachedContexts())
+ contexts.add(context);
+ }
+
+ return contexts;
+ }
+
+ public int size()
+ {
+ int size = permanentCache.size();
+ if (realCache instanceof CacheStatistics)
+ {
+ size += CacheStatistics.class.cast(realCache).size();
+ }
+ return size;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "CombinedVFSCache[real-cache: " + realCache + "]";
+ }
+
+ private class PermanentVFSCache extends MapVFSCache
+ {
+ protected Map<String, VFSContext> createMap()
+ {
+ return new TreeMap<String, VFSContext>();
+ }
+ }
+}
\ No newline at end of file
Property changes on: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/CombinedVFSCache.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/CombinedVFSCacheTestCase.java (from rev 81461, projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/MapVFSCacheTest.java)
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/CombinedVFSCacheTestCase.java (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/CombinedVFSCacheTestCase.java 2009-01-08 14:10:46 UTC (rev 82697)
@@ -0,0 +1,117 @@
+/*
+* 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.util.Map;
+
+import junit.framework.Test;
+import org.jboss.virtual.plugins.cache.CombinedVFSCache;
+import org.jboss.virtual.plugins.cache.IterableTimedVFSCache;
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.cache.VFSCache;
+
+/**
+ * Combined VFSCache Test.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class CombinedVFSCacheTestCase extends VFSCacheTest
+{
+ public CombinedVFSCacheTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(CombinedVFSCacheTestCase.class);
+ }
+
+ @Override
+ protected void stopCache(VFSCache cache)
+ {
+ if (cache != null)
+ {
+ if (cache instanceof CombinedWrapperVFSCache)
+ {
+ CombinedWrapperVFSCache cwvc = (CombinedWrapperVFSCache)cache;
+ cwvc.getTemp().stop();
+ }
+ cache.stop();
+ }
+ }
+
+ @Override
+ protected Class<? extends VFSCache> getCacheClass()
+ {
+ return CombinedVFSCache.class;
+ }
+
+ protected CombinedVFSCache createCache()
+ {
+ try
+ {
+ CombinedWrapperVFSCache cache = new CombinedWrapperVFSCache();
+ cache.setPermanentRoots(getResource("/vfs/test/nested"));
+
+ IterableTimedVFSCache realCache = new IterableTimedVFSCache(5);
+ realCache.start();
+ cache.setRealCache(realCache);
+
+ cache.create();
+
+ return cache;
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ protected Map<Object, Object> getMap()
+ {
+ return null;
+ }
+
+ protected void testCachedContexts(Iterable<VFSContext> iter)
+ {
+ VFSContext context = iter.iterator().next();
+ assertNotNull(context);
+ }
+
+ private class CombinedWrapperVFSCache extends CombinedVFSCache
+ {
+ private VFSCache temp;
+
+ @Override
+ public void setRealCache(VFSCache realCache)
+ {
+ super.setRealCache(realCache);
+ temp = realCache;
+ }
+
+ public VFSCache getTemp()
+ {
+ return temp;
+ }
+ }
+}
\ No newline at end of file
Property changes on: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/CombinedVFSCacheTestCase.java
___________________________________________________________________
Name: svn:mergeinfo
+
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 2009-01-08 14:04:14 UTC (rev 82696)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java 2009-01-08 14:10:46 UTC (rev 82697)
@@ -92,6 +92,7 @@
suite.addTest(IterableTimedCacheTestCase.suite());
suite.addTest(SoftRefCacheTestCase.suite());
suite.addTest(WeakRefCacheTestCase.suite());
+ suite.addTest(CombinedVFSCacheTestCase.suite());
// exception handler
suite.addTest(ExceptionHandlerTestCase.suite());
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java 2009-01-08 14:04:14 UTC (rev 82696)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java 2009-01-08 14:10:46 UTC (rev 82697)
@@ -49,6 +49,12 @@
protected abstract VFSCache createCache();
+ protected void stopCache(VFSCache cache)
+ {
+ if (cache != null)
+ cache.stop();
+ }
+
@SuppressWarnings("deprecation")
public void testCache() throws Exception
{
@@ -85,7 +91,7 @@
}
finally
{
- cache.stop();
+ stopCache(cache);
}
}
@@ -122,7 +128,7 @@
}
finally
{
- cache.stop();
+ stopCache(cache);
}
}
@@ -141,7 +147,7 @@
public void testCacheFactory() throws Exception
{
- VFSCache cache;
+ VFSCache cache = null;
String cacheClassName = getCacheClass().getName();
VFSCacheFactory.setInstance(null);
@@ -173,6 +179,7 @@
}
finally
{
+ stopCache(cache);
VFSCacheFactory.setInstance(null);
}
}
More information about the jboss-cvs-commits
mailing list