From 9f9aaa9b9e13a127885dcc27c992924897b1e1e7 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Sat, 27 Jun 2015 16:17:00 +0100 Subject: [PATCH] Update event to include the previous value. --- .../chronicle/map/ReplicatedChronicleMap.java | 2 +- .../chronicle/map/VanillaChronicleMap.java | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java index 692f71582..8de63569f 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java @@ -1072,7 +1072,7 @@ final class ReplicatedChronicleMap toKey, - GetValueInterops getValueInterops, VB value, + GetValueInterops getValueInterops, VB value, V oldValue, InstanceOrBytesToInstance toValue, long hash2, boolean replaceIfPresent, ReadValue readValue, boolean resultUnused) { return putWithoutLock(copies, segmentState, metaKeyInterop, keyInterop, key, keySize, diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index f1c78c1d6..bfd84aae7 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -2121,11 +2121,20 @@ class VanillaChronicleMap, copies = SegmentState.getCopies(copies); segmentState = SegmentState.get(copies); } + // TODO optimise + V oldValue = null; + if (eventListener != null) + try { + oldValue = lookupUsing((K) key, null, false); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + writeLock(); try { return putWithoutLock(copies, segmentState, metaKeyInterop, keyInterop, key, keySize, toKey, - getValueInterops, value, toValue, + getValueInterops, value, oldValue, toValue, hash2, replaceIfPresent, readValue, resultUnused); } finally { segmentState.close(); @@ -2139,10 +2148,11 @@ class VanillaChronicleMap, @NotNull ThreadLocalCopies copies, @NotNull SegmentState segmentState, MKBI metaKeyInterop, KBI keyInterop, KB key, long keySize, InstanceOrBytesToInstance toKey, - GetValueInterops getValueInterops, VB value, + GetValueInterops getValueInterops, VB value, V oldValue, InstanceOrBytesToInstance toValue, long hash2, boolean replaceIfPresent, ReadValue readValue, boolean resultUnused) { + SearchState searchState = segmentState.searchState; hashLookup.startSearch(hash2, searchState); MultiStoreBytes entry = segmentState.tmpBytes; @@ -2180,7 +2190,7 @@ class VanillaChronicleMap, segmentState.valueSizePos, true, false); if (eventListener != null) eventListener.onPut(toKey.toInstance(copies, key, keySize), - toValue.toInstance(copies, value, valueSize), null, false); + toValue.toInstance(copies, value, valueSize), oldValue, false); return resultUnused ? null : readValue.readNull(); }