You are viewing a plain text version of this content. The canonical link for it is here.
Posted to kato-commits@incubator.apache.org by mo...@apache.org on 2009/10/28 09:34:32 UTC

svn commit: r830481 - in /incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/util: CacheLinkedHashMap.java CachedRandomAccessFile.java

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;
+		}
+	}
 }