aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Borowitz2011-11-03 15:52:19 (EDT)
committerShawn O. Pearce2011-11-04 14:14:32 (EDT)
commitdff9d56b946552b4a6b802908a22793f95d3738c (patch)
treebe3062149697296b050f13aea3f17bb32ad3255b
parent35d72ac806d73f0c2c2a1a9882321d08044bb6f8 (diff)
downloadjgit-dff9d56b946552b4a6b802908a22793f95d3738c.zip
jgit-dff9d56b946552b4a6b802908a22793f95d3738c.tar.gz
jgit-dff9d56b946552b4a6b802908a22793f95d3738c.tar.bz2
Expose the list of pack files in the DfsBlockCacherefs/changes/42/4542/3
Callers may want to inspect the contents of the cache, which this allows them to do in a read-only fashion without any locking. Change-Id: Ifd78e8ce34e26e5cc33e9dd61d70c593ce479ee0
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsBlockCache.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsBlockCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsBlockCache.java
index 3ae9690..871a2c5 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsBlockCache.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsBlockCache.java
@@ -46,9 +46,11 @@ package org.eclipse.jgit.storage.dfs;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReferenceArray;
@@ -156,6 +158,9 @@ public final class DfsBlockCache {
/** Cache of pack files, indexed by description. */
private final Map<DfsPackDescription, DfsPackFile> packCache;
+ /** View of pack files in the pack cache. */
+ private final Collection<DfsPackFile> packFiles;
+
/** Number of times a block was found in the cache. */
private final AtomicLong statHit;
@@ -203,7 +208,9 @@ public final class DfsBlockCache {
readAheadLimit = cfg.getReadAheadLimit();
readAheadService = cfg.getReadAheadService();
- packCache = new HashMap<DfsPackDescription, DfsPackFile>();
+ packCache = new ConcurrentHashMap<DfsPackDescription, DfsPackFile>(
+ 16, 0.75f, 1);
+ packFiles = Collections.unmodifiableCollection(packCache.values());
statHit = new AtomicLong();
statMiss = new AtomicLong();
@@ -234,6 +241,16 @@ public final class DfsBlockCache {
return statEvict;
}
+ /**
+ * Get the pack files stored in this cache.
+ *
+ * @return a collection of pack files, some of which may not actually be
+ * present; the caller should check the pack's cached size.
+ */
+ public Collection<DfsPackFile> getPackFiles() {
+ return packFiles;
+ }
+
DfsPackFile getOrCreate(DfsPackDescription dsc, DfsPackKey key) {
// TODO This table grows without bound. It needs to clean up
// entries that aren't in cache anymore, and aren't being used