[jboss-cvs] JBossAS SVN: r101121 - in projects/vfs/branches/Branch_2_2/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 Feb 18 11:37:18 EST 2010
Author: alesj
Date: 2010-02-18 11:37:18 -0500 (Thu, 18 Feb 2010)
New Revision: 101121
Added:
projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/CustomLRUCachePolicy.java
Modified:
projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/CachePolicyVFSCache.java
projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/LRUVFSCache.java
projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/TimedVFSCache.java
projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/test/MemoryTestCase.java
Log:
[JBVFS-134]; invalidate cache better.
Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/CachePolicyVFSCache.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/CachePolicyVFSCache.java 2010-02-18 16:16:53 UTC (rev 101120)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/CachePolicyVFSCache.java 2010-02-18 16:37:18 UTC (rev 101121)
@@ -140,11 +140,22 @@
protected void putContext(String path, VFSContext context)
{
- Object result = policy.peek(path);
+ Object result = policy.get(path);
if (result == null)
- policy.insert(path, context);
+ policy.insert(path, wrapContext(context));
}
+ /**
+ * Wrap the context value.
+ *
+ * @param context the context to wrap
+ * @return possibly wrapped context
+ */
+ protected Object wrapContext(VFSContext context)
+ {
+ return context;
+ }
+
public void removeContext(String key, VFSContext context)
{
policy.remove(key);
Copied: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/CustomLRUCachePolicy.java (from rev 101114, projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/LRUVFSCache.java)
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/CustomLRUCachePolicy.java (rev 0)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/CustomLRUCachePolicy.java 2010-02-18 16:37:18 UTC (rev 101121)
@@ -0,0 +1,76 @@
+/*
+* 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.logging.Logger;
+import org.jboss.util.LRUCachePolicy;
+import org.jboss.virtual.spi.VFSContext;
+
+/**
+ * LRU cache policy vfs cache.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+class CustomLRUCachePolicy extends LRUCachePolicy
+{
+ private static Logger log = Logger.getLogger(CustomLRUCachePolicy.class);
+
+ CustomLRUCachePolicy()
+ {
+ }
+
+ CustomLRUCachePolicy(int min, int max)
+ {
+ super(min, max);
+ }
+
+ @Override
+ protected void ageOut(LRUCacheEntry entry)
+ {
+ VFSContext context = (VFSContext) entry.m_object;
+ super.ageOut(entry); // remove entry
+
+ try
+ {
+ context.cleanupTempInfo(""); // cleanup from root
+ }
+ catch (Exception e)
+ {
+ log.debug("Error cleaning up: " + e);
+ }
+ }
+
+ @Override
+ protected LRUList createList()
+ {
+ return new CustomLRUList();
+ }
+
+ private class CustomLRUList extends LRUList
+ {
+ @Override
+ protected void entryRemoved(LRUCachePolicy.LRUCacheEntry entry)
+ {
+ ageOut(entry);
+ }
+ }
+}
Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/LRUVFSCache.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/LRUVFSCache.java 2010-02-18 16:16:53 UTC (rev 101120)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/LRUVFSCache.java 2010-02-18 16:37:18 UTC (rev 101121)
@@ -24,7 +24,9 @@
import java.util.Map;
import org.jboss.util.LRUCachePolicy;
+import org.jboss.virtual.VFS;
import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.spi.VFSContext;
/**
* LRU cache policy vfs cache.
@@ -63,7 +65,7 @@
log.debug("Creating LRU cache policy, min: " + min + ", max: " + max);
- return new LRUCachePolicy(min, max);
+ return new CustomLRUCachePolicy(min, max);
}
/**
Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/TimedVFSCache.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/TimedVFSCache.java 2010-02-18 16:16:53 UTC (rev 101120)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/cache/TimedVFSCache.java 2010-02-18 16:37:18 UTC (rev 101121)
@@ -21,15 +21,15 @@
*/
package org.jboss.virtual.plugins.cache;
+import org.jboss.util.TimedCachePolicy;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.spi.VFSContext;
+
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-import org.jboss.util.TimedCachePolicy;
-import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.spi.VFSContext;
-
/**
* Timed cache policy vfs cache.
*
@@ -74,7 +74,7 @@
{
Map<Object, VFSContext> contexts = new TreeMap<Object, VFSContext>();
for (Object key : keys)
- contexts.put(key, (VFSContext)tcp.peek(key));
+ contexts.put(key, (VFSContext)tcp.peek(key)); // value should match valid key
return contexts.values();
}
@@ -149,4 +149,54 @@
{
return info;
}
+
+ @Override
+ protected Object wrapContext(VFSContext context)
+ {
+ return new VFSContextWrapper(getPolicy().getDefaultLifetime(), context);
+ }
+
+ private class VFSContextWrapper implements TimedCachePolicy.TimedEntry
+ {
+ private long expirationTime;
+ private VFSContext context;
+
+ VFSContextWrapper(long lifetime, VFSContext value)
+ {
+ this.expirationTime = 1000 * lifetime;
+ this.context = value;
+ }
+
+ public void init(long now)
+ {
+ expirationTime += now;
+ }
+
+ public boolean isCurrent(long now)
+ {
+ return expirationTime > now;
+ }
+
+ public boolean refresh()
+ {
+ return false;
+ }
+
+ public void destroy()
+ {
+ try
+ {
+ context.cleanupTempInfo(""); // cleanup from root
+ }
+ catch (Exception e)
+ {
+ log.debug("Error cleaning up: " + e);
+ }
+ }
+
+ public Object getValue()
+ {
+ return context;
+ }
+ }
}
\ No newline at end of file
Modified: projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/test/MemoryTestCase.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/test/MemoryTestCase.java 2010-02-18 16:16:53 UTC (rev 101120)
+++ projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/test/MemoryTestCase.java 2010-02-18 16:37:18 UTC (rev 101121)
@@ -359,7 +359,7 @@
final VirtualFile nested = VFS.createNewRoot(root);
// flush - so we only get in-memory contexts (if they exist)
- VFSCacheFactory.getInstance().flush();
+ // VFSCacheFactory.getInstance().flush(); // flush destroys cache entries
root = new URL("vfsmemory://aopdomain");
final VFS vfs = MemoryFileFactory.createRoot(root);
More information about the jboss-cvs-commits
mailing list