[Mulgara-svn] r874 - projects/xa2/object-pool/src/scheduler

andrae at mulgara.org andrae at mulgara.org
Thu May 1 04:56:20 UTC 2008


Author: andrae
Date: 2008-04-30 21:56:19 -0700 (Wed, 30 Apr 2008)
New Revision: 874

Added:
   projects/xa2/object-pool/src/scheduler/BlockCache.java
Removed:
   projects/xa2/object-pool/src/scheduler/FileCache.java
Log:
Migrating FileCache to BlockCache.



Copied: projects/xa2/object-pool/src/scheduler/BlockCache.java (from rev 873, projects/xa2/object-pool/src/scheduler/FileCache.java)
===================================================================
--- projects/xa2/object-pool/src/scheduler/BlockCache.java	                        (rev 0)
+++ projects/xa2/object-pool/src/scheduler/BlockCache.java	2008-05-01 04:56:19 UTC (rev 874)
@@ -0,0 +1,47 @@
+/*
+ * Copyright Topaz Foundation 2008
+ * Author Andrae Muys
+ * Date 30th April 2008
+ */
+package scheduler;
+
+import java.io.File;
+import java.ref.SoftReference;
+import java.util.WeakHashMap;
+
+public class BlockCache {
+  private FileHandle handle;
+  // The Block object is required to maintain a strong reference to the Long key obj.
+  private WeakHashMap<Long, SoftReference<Block>> blockCache;
+
+  private static final int LOG2_BLOCK_SIZE = 21;
+
+  BlockCache(FileHandle handle) {
+    this.handle = handle;
+    this.blockCache = new WeakHashMap<Long, SoftReference<Block>>();
+  }
+
+  public Block getBlock(long position) {
+    Long pos = new Long(position >> handle.log2BlockSize());
+    SoftReference<Block> blockRef = blockCache.get(pos);
+    if (blockRef != null) {
+      Block block = blockRef.get();
+      if (block != null) {
+
+        return block;
+      } else {
+        // Note that the combination of soft and weak references means that we need this double check.
+        // Because soft-references prevent weak-references from being reaped it is legal for the gc to reap
+        // the block and the key in subsequent passes.
+        // Here we remove the stale entry so it can be reentered.
+        blockCache.remove(pos);
+      }
+    }
+    Block newBlock = handle.getBlock(pos);
+    // Note we use the newBlock's position, not pos - this ensures the map's entry will be retained until
+    // memory pressure forces the SoftReference to be reaped.
+    blockCache.put(newBlock.getPosition(), new SoftReference(newBlock));
+
+    return newBlock;
+  }
+}

Deleted: projects/xa2/object-pool/src/scheduler/FileCache.java
===================================================================
--- projects/xa2/object-pool/src/scheduler/FileCache.java	2008-05-01 04:55:48 UTC (rev 873)
+++ projects/xa2/object-pool/src/scheduler/FileCache.java	2008-05-01 04:56:19 UTC (rev 874)
@@ -1,47 +0,0 @@
-/*
- * Copyright Topaz Foundation 2008
- * Author Andrae Muys
- * Date 30th April 2008
- */
-package scheduler;
-
-import java.io.File;
-import java.ref.SoftReference;
-import java.util.WeakHashMap;
-
-public class BlockCache {
-  private FileHandle handle;
-  // The Block object is required to maintain a strong reference to the Long key obj.
-  private WeakHashMap<Long, SoftReference<Block>> blockCache;
-
-  private static final int LOG2_BLOCK_SIZE = 21;
-
-  BlockCache(FileHandle handle) {
-    this.handle = handle;
-    this.blockCache = new WeakHashMap<Long, SoftReference<Block>>();
-  }
-
-  public Block getBlock(long position) {
-    Long pos = new Long(position >> handle.log2BlockSize());
-    SoftReference<Block> blockRef = blockCache.get(pos);
-    if (blockRef != null) {
-      Block block = blockRef.get();
-      if (block != null) {
-
-        return block;
-      } else {
-        // Note that the combination of soft and weak references means that we need this double check.
-        // Because soft-references prevent weak-references from being reaped it is legal for the gc to reap
-        // the block and the key in subsequent passes.
-        // Here we remove the stale entry so it can be reentered.
-        blockCache.remove(pos);
-      }
-    }
-    Block newBlock = handle.getBlock(pos);
-    // Note we use the newBlock's position, not pos - this ensures the map's entry will be retained until
-    // memory pressure forces the SoftReference to be reaped.
-    blockCache.put(newBlock.getPosition(), new SoftReference(newBlock));
-
-    return newBlock;
-  }
-}




More information about the Mulgara-svn mailing list