[jboss-cvs] JBossAS SVN: r80639 - in projects/vfs/branches/Branch_2_0/src: main/java/org/jboss/virtual/plugins/vfs/helpers and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Nov 7 06:33:17 EST 2008
Author: alesj
Date: 2008-11-07 06:33:16 -0500 (Fri, 07 Nov 2008)
New Revision: 80639
Modified:
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/cache/CachePolicyVFSCache.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/cache/LRUVFSCache.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/cache/TimedVFSCache.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/spi/cache/VFSCacheFactory.java
projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/LRUCacheTestCase.java
projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/MapVFSCacheTest.java
projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/PathTokensTestCase.java
projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/TimedCacheTestCase.java
projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java
Log:
Port JBVFS 68, 69 to branch.
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/cache/CachePolicyVFSCache.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/cache/CachePolicyVFSCache.java 2008-11-07 11:23:01 UTC (rev 80638)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/cache/CachePolicyVFSCache.java 2008-11-07 11:33:16 UTC (rev 80639)
@@ -24,6 +24,7 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collections;
+import java.util.Map;
import org.jboss.util.CachePolicy;
import org.jboss.virtual.spi.VFSContext;
@@ -36,7 +37,17 @@
public abstract class CachePolicyVFSCache extends PathMatchingVFSCache
{
private CachePolicy policy;
+ private Map<Object, Object> properties;
+ protected CachePolicyVFSCache()
+ {
+ }
+
+ protected CachePolicyVFSCache(Map<Object, Object> properties)
+ {
+ this.properties = properties;
+ }
+
public Iterable<VFSContext> getCachedContexts()
{
// cannot pull all cache entries from policy
@@ -134,6 +145,34 @@
protected abstract CachePolicy createCachePolicy();
/**
+ * Read instance properties.
+ *
+ * @param key the property key
+ * @param defaultValue the default value
+ * @param useSystemProperties do we fallback to system properties
+ * @return property or default value
+ */
+ protected Object readInstanceProperties(final String key, final Object defaultValue, final boolean useSystemProperties)
+ {
+ Object result = null;
+ if (properties != null && properties.isEmpty() == false)
+ {
+ result = properties.get(key);
+ }
+ if (result == null)
+ {
+ if (useSystemProperties)
+ {
+ String stringDefaultValue = defaultValue != null ? defaultValue.toString() : null;
+ result = readSystemProperty(key, stringDefaultValue);
+ }
+ else
+ result = defaultValue;
+ }
+ return result;
+ }
+
+ /**
* Read system property.
*
* @param key the property key
@@ -159,7 +198,7 @@
* Parse integer.
*
* @param value the string int value
- * @return integer value of null
+ * @return integer value or null
*/
protected static Integer parseInteger(String value)
{
@@ -168,4 +207,20 @@
return Integer.parseInt(value);
}
+
+ /**
+ * Get integer from value.
+ *
+ * @param value the value
+ * @return integer value or null
+ */
+ protected static Integer getInteger(Object value)
+ {
+ if (value == null)
+ return null;
+ else if (value instanceof Number)
+ return Number.class.cast(value).intValue();
+ else
+ return Integer.parseInt(value.toString());
+ }
}
\ No newline at end of file
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/cache/LRUVFSCache.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/cache/LRUVFSCache.java 2008-11-07 11:23:01 UTC (rev 80638)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/cache/LRUVFSCache.java 2008-11-07 11:33:16 UTC (rev 80639)
@@ -21,6 +21,8 @@
*/
package org.jboss.virtual.plugins.cache;
+import java.util.Map;
+
import org.jboss.util.CachePolicy;
import org.jboss.util.LRUCachePolicy;
import org.jboss.virtual.VFSUtils;
@@ -45,12 +47,17 @@
this.max = max;
}
+ public LRUVFSCache(Map<Object, Object> properties)
+ {
+ super(properties);
+ }
+
protected CachePolicy createCachePolicy()
{
if (min == null)
- min = parseInteger(readSystemProperty(VFSUtils.VFS_CACHE_KEY + ".LRUPolicyCaching.min", null));
+ min = getInteger(readInstanceProperties(VFSUtils.VFS_CACHE_KEY + ".LRUPolicyCaching.min", null, true));
if (max == null)
- max = parseInteger(readSystemProperty(VFSUtils.VFS_CACHE_KEY + ".LRUPolicyCaching.max", null));
+ max = getInteger(readInstanceProperties(VFSUtils.VFS_CACHE_KEY + ".LRUPolicyCaching.max", null, true));
if (min == null || max == null)
throw new IllegalArgumentException("Missing min (" + min + ") or max (" + max + ").");
@@ -79,4 +86,9 @@
{
this.max = max;
}
+
+ public String toString()
+ {
+ return "LRUVFSCache{min=" + min + ", max=" + max + "}";
+ }
}
\ No newline at end of file
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/cache/TimedVFSCache.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/cache/TimedVFSCache.java 2008-11-07 11:23:01 UTC (rev 80638)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/cache/TimedVFSCache.java 2008-11-07 11:33:16 UTC (rev 80639)
@@ -21,6 +21,8 @@
*/
package org.jboss.virtual.plugins.cache;
+import java.util.Map;
+
import org.jboss.util.CachePolicy;
import org.jboss.util.TimedCachePolicy;
import org.jboss.virtual.VFSUtils;
@@ -36,6 +38,8 @@
private Boolean threadSafe;
private Integer resolution;
+ private String info;
+
public TimedVFSCache()
{
}
@@ -52,23 +56,33 @@
this.resolution = resolution;
}
+ public TimedVFSCache(Map<Object, Object> properties)
+ {
+ super(properties);
+ }
+
protected CachePolicy createCachePolicy()
{
if (defaultLifetime == null)
- defaultLifetime = parseInteger(readSystemProperty(VFSUtils.VFS_CACHE_KEY + ".TimedPolicyCaching.lifetime", null));
+ defaultLifetime = getInteger(readInstanceProperties(VFSUtils.VFS_CACHE_KEY + ".TimedPolicyCaching.lifetime", null, true));
if (threadSafe == null)
- threadSafe = Boolean.valueOf(readSystemProperty(VFSUtils.VFS_CACHE_KEY + ".TimedPolicyCaching.threadSafe", Boolean.TRUE.toString()));
+ threadSafe = Boolean.valueOf(readInstanceProperties(VFSUtils.VFS_CACHE_KEY + ".TimedPolicyCaching.threadSafe", Boolean.TRUE, true).toString());
if (resolution == null)
- resolution = parseInteger(readSystemProperty(VFSUtils.VFS_CACHE_KEY + ".TimedPolicyCaching.resolution", null));
+ resolution = getInteger(readInstanceProperties(VFSUtils.VFS_CACHE_KEY + ".TimedPolicyCaching.resolution", null, true));
log.debug("Creating timed cache policy, lifetime: " + defaultLifetime + ", threadSafe: " + threadSafe + ", resolution: " + resolution);
+ TimedCachePolicy tcp;
if (defaultLifetime == null)
- return new TimedCachePolicy();
+ tcp = new TimedCachePolicy();
else if (resolution != null)
- return new TimedCachePolicy(defaultLifetime, threadSafe, resolution);
+ tcp = new TimedCachePolicy(defaultLifetime, threadSafe, resolution);
else
- return new TimedCachePolicy(defaultLifetime);
+ tcp = new TimedCachePolicy(defaultLifetime);
+
+ info = "TimedVFSCache{lifetime=" + tcp.getDefaultLifetime() + ", resolution=" + tcp.getResolution() + "}";
+
+ return tcp;
}
/**
@@ -100,4 +114,9 @@
{
this.resolution = resolution;
}
+
+ public String toString()
+ {
+ return info;
+ }
}
\ No newline at end of file
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java 2008-11-07 11:23:01 UTC (rev 80638)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java 2008-11-07 11:33:16 UTC (rev 80639)
@@ -117,12 +117,14 @@
}
else if (ch == '.')
{
- if (specialToken == null && buffer.length() == 0)
+ int bufferLength = buffer.length();
+
+ if (specialToken == null && bufferLength == 0)
specialToken = CURRENT_PATH;
- else if (specialToken == CURRENT_PATH && buffer.length() == 0)
+ else if (specialToken == CURRENT_PATH && bufferLength == 0)
specialToken = REVERSE_PATH;
- else if (specialToken != null && buffer.length() == 0)
- throw new IllegalArgumentException("Illegal token in path: " + path);
+ else if (specialToken == REVERSE_PATH && bufferLength == 0)
+ throw new IllegalArgumentException("Illegal token (" + specialToken + ch + ") in path: " + path);
else
buffer.append(ch);
}
@@ -130,8 +132,15 @@
{
// token starts with '.' or '..', but also has some path after that
if (specialToken != null)
- throw new IllegalArgumentException("Illegal token in path: " + path);
+ {
+ // we don't allow tokens after '..'
+ if (specialToken == REVERSE_PATH)
+ throw new IllegalArgumentException("Illegal token (" + specialToken + ch + ") in path: " + path);
+ // after '.' more path is legal == unix hidden directories
+ buffer.append(specialToken);
+ specialToken = null;
+ }
buffer.append(ch);
}
}
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/spi/cache/VFSCacheFactory.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/spi/cache/VFSCacheFactory.java 2008-11-07 11:23:01 UTC (rev 80638)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/spi/cache/VFSCacheFactory.java 2008-11-07 11:33:16 UTC (rev 80639)
@@ -21,8 +21,10 @@
*/
package org.jboss.virtual.spi.cache;
+import java.lang.reflect.Constructor;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.Map;
import org.jboss.logging.Logger;
import org.jboss.virtual.VFSUtils;
@@ -33,7 +35,7 @@
*
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
* @author Scott.Stark at jboss.org
- * @version $Revision$
+ * @version $Revision: 80615 $
*/
public class VFSCacheFactory
{
@@ -53,8 +55,9 @@
*/
public static VFSCache getInstance()
{
- return getInstance(null);
+ return getInstance(null, null);
}
+
/**
*
* Get VFS cache instance.
@@ -62,17 +65,33 @@
* @param defaultCacheImpl - the possibly null name of the VFSCache
* implementation to use. If null, the {@linkplain VFSUtils.VFS_CACHE_KEY}
* system property will be used.
- *
+ *
* @return the vfs cache instance
*/
public static VFSCache getInstance(String defaultCacheImpl)
{
+ return getInstance(defaultCacheImpl, null);
+ }
+
+ /**
+ *
+ * Get VFS cache instance.
+ *
+ * @param defaultCacheImpl - the possibly null name of the VFSCache
+ * implementation to use. If null, the {@linkplain VFSUtils.VFS_CACHE_KEY}
+ * system property will be used.
+ * @param properties the possible vfs cache impl properties
+ *
+ * @return the vfs cache instance
+ */
+ public static VFSCache getInstance(String defaultCacheImpl, Map<Object, Object> properties)
+ {
if (instance == null)
{
synchronized (lock)
{
if (instance == null)
- instance = AccessController.doPrivileged(new VFSCacheCreatorAction(defaultCacheImpl));
+ instance = AccessController.doPrivileged(new VFSCacheCreatorAction(defaultCacheImpl, properties));
}
}
return instance;
@@ -97,9 +116,12 @@
private static class VFSCacheCreatorAction implements PrivilegedAction<VFSCache>
{
private String defaultCacheImpl;
- VFSCacheCreatorAction(String defaultCacheImpl)
+ private Map<Object, Object> properties;
+
+ VFSCacheCreatorAction(String defaultCacheImpl, Map<Object, Object> properties)
{
this.defaultCacheImpl = defaultCacheImpl;
+ this.properties = properties;
}
public VFSCache run()
@@ -115,12 +137,22 @@
}
if (className != null)
{
- log.info("Initializing VFSCache [" + className + "] ...");
+ log.info("Initializing VFSCache [" + className + "]");
ClassLoader cl = VFSCacheFactory.class.getClassLoader();
Class<?> clazz = cl.loadClass(className);
- VFSCache cache = VFSCache.class.cast(clazz.newInstance());
+ Object result;
+ if (properties != null)
+ {
+ Constructor<?> constructor = clazz.getConstructor(Map.class);
+ result = constructor.newInstance(properties);
+ }
+ else
+ {
+ result = clazz.newInstance();
+ }
+ VFSCache cache = VFSCache.class.cast(result);
cache.start(); // start here, so we fall back to default no-op in case start fails
- log.info("Using VFSCache [" + cache + "] ...");
+ log.info("Using VFSCache [" + cache + "]");
return cache;
}
}
@@ -128,7 +160,7 @@
{
log.warn("Exception instantiating VFS cache: ", t);
}
- log.info("Using VFSCache [NoopVFSCache] ...");
+ log.info("Using VFSCache [NoopVFSCache]");
return new NoopVFSCache();
}
}
Property changes on: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/spi/cache/VFSCacheFactory.java
___________________________________________________________________
Name: svn:keywords
- Id Revision
Modified: projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/LRUCacheTestCase.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/LRUCacheTestCase.java 2008-11-07 11:23:01 UTC (rev 80638)
+++ projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/LRUCacheTestCase.java 2008-11-07 11:33:16 UTC (rev 80639)
@@ -21,7 +21,12 @@
*/
package org.jboss.test.virtual.test;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
import junit.framework.Test;
+import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.plugins.cache.LRUVFSCache;
import org.jboss.virtual.spi.cache.VFSCache;
@@ -46,4 +51,19 @@
{
return new LRUVFSCache(2, 10);
}
+
+ protected Iterable<String> populateRequiredSystemProperties()
+ {
+ System.setProperty(VFSUtils.VFS_CACHE_KEY + ".LRUPolicyCaching.min", "2");
+ System.setProperty(VFSUtils.VFS_CACHE_KEY + ".LRUPolicyCaching.max", "10");
+ return Arrays.asList(VFSUtils.VFS_CACHE_KEY + ".LRUPolicyCaching.min", VFSUtils.VFS_CACHE_KEY + ".LRUPolicyCaching.max");
+ }
+
+ protected Map<Object, Object> getMap()
+ {
+ Map<Object, Object> map = new HashMap<Object, Object>();
+ map.put(VFSUtils.VFS_CACHE_KEY + ".LRUPolicyCaching.min", 2);
+ map.put(VFSUtils.VFS_CACHE_KEY + ".LRUPolicyCaching.max", 10);
+ return map;
+ }
}
\ No newline at end of file
Modified: projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/MapVFSCacheTest.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/MapVFSCacheTest.java 2008-11-07 11:23:01 UTC (rev 80638)
+++ projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/MapVFSCacheTest.java 2008-11-07 11:33:16 UTC (rev 80639)
@@ -21,6 +21,8 @@
*/
package org.jboss.test.virtual.test;
+import java.util.Map;
+
import org.jboss.virtual.spi.VFSContext;
/**
@@ -35,6 +37,11 @@
super(name);
}
+ protected Map<Object, Object> getMap()
+ {
+ return null;
+ }
+
protected void testCachedContexts(Iterable<VFSContext> iter)
{
VFSContext context = iter.iterator().next();
Modified: projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/PathTokensTestCase.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/PathTokensTestCase.java 2008-11-07 11:23:01 UTC (rev 80638)
+++ projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/PathTokensTestCase.java 2008-11-07 11:33:16 UTC (rev 80639)
@@ -23,10 +23,13 @@
import java.io.IOException;
import java.net.URL;
+import java.util.List;
+import java.util.Arrays;
import junit.framework.Test;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.vfs.helpers.PathTokenizer;
/**
* Test path tokens.
@@ -103,4 +106,13 @@
testValidPath("//context///jar//");
testValidPath("//context///jar///");
}
+
+ public void testHiddenUnixPath() throws Throwable
+ {
+ // the trick is the .hudson bit
+ String path = "/home/hudson/.hudson/";
+ List<String> tokens = PathTokenizer.getTokens(path);
+ List<String> expected = Arrays.asList("home", "hudson", ".hudson");
+ assertEquals(expected, tokens);
+ }
}
\ No newline at end of file
Modified: projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/TimedCacheTestCase.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/TimedCacheTestCase.java 2008-11-07 11:23:01 UTC (rev 80638)
+++ projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/TimedCacheTestCase.java 2008-11-07 11:33:16 UTC (rev 80639)
@@ -21,8 +21,12 @@
*/
package org.jboss.test.virtual.test;
+import java.util.Map;
+import java.util.HashMap;
+
import org.jboss.virtual.plugins.cache.TimedVFSCache;
import org.jboss.virtual.spi.cache.VFSCache;
+import org.jboss.virtual.VFSUtils;
import junit.framework.Test;
/**
@@ -44,6 +48,13 @@
protected VFSCache createCache()
{
- return new TimedVFSCache(60);
+ return new TimedVFSCache(5);
}
+
+ protected Map<Object, Object> getMap()
+ {
+ Map<Object, Object> map = new HashMap<Object, Object>();
+ map.put(VFSUtils.VFS_CACHE_KEY + ".TimedPolicyCaching.lifetime", 5);
+ return map;
+ }
}
\ No newline at end of file
Modified: projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java 2008-11-07 11:23:01 UTC (rev 80638)
+++ projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java 2008-11-07 11:33:16 UTC (rev 80639)
@@ -24,13 +24,16 @@
import java.io.IOException;
import java.net.URI;
import java.net.URL;
+import java.util.Collections;
+import java.util.Map;
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.VFSCacheFactory;
-import org.jboss.virtual.spi.cache.CacheStatistics;
-import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.cache.helpers.NoopVFSCache;
/**
* VFSCache Test.
@@ -123,6 +126,57 @@
}
}
+ protected Class<? extends VFSCache> getCacheClass()
+ {
+ VFSCache cache = createCache();
+ return cache.getClass();
+ }
+
+ protected Iterable<String> populateRequiredSystemProperties()
+ {
+ return Collections.emptySet();
+ }
+
+ protected abstract Map<Object, Object> getMap();
+
+ public void testCacheFactory() throws Exception
+ {
+ VFSCache cache;
+ String cacheClassName = getCacheClass().getName();
+
+ VFSCacheFactory.setInstance(null);
+ try
+ {
+ Iterable<String> keys = populateRequiredSystemProperties();
+ try
+ {
+ cache = VFSCacheFactory.getInstance(cacheClassName);
+ assertNotNull(cache);
+ assertTrue(cache instanceof NoopVFSCache == false);
+ cache.flush();
+ }
+ finally
+ {
+ for (String key : keys)
+ System.clearProperty(key);
+ }
+
+ VFSCacheFactory.setInstance(null);
+
+ VFSCache mapParamCache = VFSCacheFactory.getInstance(cacheClassName, getMap());
+ // need new instance, so we know we're really testing map parameter
+ assertNotSame(cache, mapParamCache);
+ cache = mapParamCache;
+ assertNotNull(cache);
+ assertTrue(cache instanceof NoopVFSCache == false);
+ cache.flush();
+ }
+ finally
+ {
+ VFSCacheFactory.setInstance(null);
+ }
+ }
+
private class WrapperVFSCache implements VFSCache
{
private VFSCache delegate;
More information about the jboss-cvs-commits
mailing list