From ca2746b0be89dfcdd405004f89a9f3d8a714cfcc Mon Sep 17 00:00:00 2001 From: "yuhang.zhao" Date: Wed, 20 Jul 2016 15:03:10 +0800 Subject: [PATCH] add on remove entry call back method and open free method extending by subclass --- .../openhft/chronicle/map/ReplicatedChronicleMap.java | 11 +++++++++++ .../openhft/chronicle/map/VanillaChronicleMap.java | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java index 69b554c21..466b276b7 100755 --- a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java @@ -1496,6 +1496,7 @@ class ReplicatedChronicleMap, if (!keyEquals(keyInterop, metaKeyInterop, key, keySize, entry)) continue; // key is found + onRemoveEntry(this, pos); entry.skip(keySize); long timestampPos = entry.position(); long replacedTimestamp = entry.readLong(timestampPos); @@ -1572,6 +1573,7 @@ class ReplicatedChronicleMap, hashLookup.putAfterFailedSearch(searchState, pos); hashLookup.removePosition(pos); + onRemoveEntry(this, pos); // listener.onRemove() might be missing here // depends on onRemove() semantics } @@ -1583,6 +1585,15 @@ class ReplicatedChronicleMap, return resultUnused ? null : readValue.readNull(); } } + + /** + * call when remove an entry in segment, regardless of local or remote remove, entry found or not found.
+ * caller has held the segment write lock + * @param segment + * @param pos + */ + void onRemoveEntry(Segment segment, long pos){ + } , RV, VB extends RV, VBI, MVBI extends MetaBytesInterop> diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index 06b11f4dd..40750ab8a 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -2618,7 +2618,7 @@ class VanillaChronicleMap, } } - private void free(long fromPos, int chunks) { + void free(long fromPos, int chunks) { freeList.clear(fromPos, fromPos + chunks); if (fromPos < nextPosToSearchFrom) nextPosToSearchFrom = fromPos;