incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From monte...@apache.org
Subject svn commit: r830481 - in /incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/util: CacheLinkedHashMap.java CachedRandomAccessFile.java
Date Wed, 28 Oct 2009 09:34:32 GMT
Author: monteith
Date: Wed Oct 28 09:34:31 2009
New Revision: 830481

URL: http://svn.apache.org/viewvc?rev=830481&view=rev
Log:
Move CacheLinkedHashMap into CachedRandomAccessFile.

Removed:
    incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/util/CacheLinkedHashMap.java
Modified:
    incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/util/CachedRandomAccessFile.java

Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/util/CachedRandomAccessFile.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/util/CachedRandomAccessFile.java?rev=830481&r1=830480&r2=830481&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/util/CachedRandomAccessFile.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/util/CachedRandomAccessFile.java
Wed Oct 28 09:34:31 2009
@@ -17,6 +17,8 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.RandomAccessFile;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
 public class CachedRandomAccessFile extends RandomAccessFile {
 	// The default block size, in bits. 4096 bytes.
@@ -267,5 +269,40 @@
 		throw new IOException("CachedRandomAccessFile is not writable");
 	}
 
-
+	/**
+	 * LinkedHashMap for our caching purposes.  
+	 * Ensures the cache uses access ordering.
+	 *	
+	 *
+	 * @param <K>
+	 * @param <V>
+	 */
+	private static class CacheLinkedHashMap<K,V> extends LinkedHashMap<K,V> {
+		private int maxCacheEntries;
+		
+		/**
+		 * 
+		 * 
+		 * 
+		 * @param initialCapacity
+		 * @param maxCacheEntries
+		 */
+		public CacheLinkedHashMap(int maxCacheEntries) {
+			super(maxCacheEntries, 0.75f, true);
+			this.maxCacheEntries = maxCacheEntries;
+		}
+		
+		
+		/**
+		 * Overrides the default implementation to contain
+		 * the cache size. 
+		 * 
+		 * @return true if cache entry is to be removed.
+		 * @param entru
+		 */
+		@Override
+		protected boolean removeEldestEntry(Map.Entry<K,V> entry) {
+			return size() > maxCacheEntries;
+		}
+	}
 }



Mime
View raw message