From e3a16746a558e2e2d66c58c89b8e835e7fed690d Mon Sep 17 00:00:00 2001 From: leventov Date: Fri, 19 Sep 2014 09:42:46 +0400 Subject: [PATCH] Don't call MapEventListener.onPut() from within ChronicleMap.acquireUsing(key, null) invocation, key is absent in the map instance, i. e. the new value was obtained via valueFactory.create() --- .../net/openhft/chronicle/map/ReplicatedChronicleMap.java | 4 +++- .../java/net/openhft/chronicle/map/VanillaChronicleMap.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java index 9645445bf..2a7c163e6 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java @@ -593,13 +593,15 @@ class ReplicatedChronicleMap extends VanillaChronicleMap return onKeyPresentOnAcquire(key, usingValue, offset, entry); } else { + boolean usingValuePassed = usingValue != null; usingValue = tryObtainUsingValueOnAcquire(keyBytes, key, usingValue, create); if (usingValue != null) { // see VanillaChronicleMap.Segment.acquire() for explanation // why `usingValue` is `create`. offset = putEntryOnAcquire(keyBytes, hash2, usingValue, create, timestamp); incrementSize(); - notifyPut(offset, true, key, usingValue, posFromOffset(offset)); + if (usingValuePassed || !create) + notifyPut(offset, true, key, usingValue, posFromOffset(offset)); return usingValue; } else { return null; diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index 8ce5178f9..cf990baff 100644 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -722,6 +722,7 @@ class VanillaChronicleMap extends AbstractMap if (offset >= 0) { return onKeyPresentOnAcquire(key, usingValue, offset, entry); } else { + boolean usingValuePassed = usingValue != null; usingValue = tryObtainUsingValueOnAcquire(keyBytes, key, usingValue, create); if (usingValue != null) { // If `create` is false, this method was called from get() or getUsing() @@ -730,7 +731,8 @@ class VanillaChronicleMap extends AbstractMap // rather than "using" container to fill up, even if it implements Byteable. offset = putEntry(keyBytes, usingValue, create); incrementSize(); - notifyPut(offset, true, key, usingValue, posFromOffset(offset)); + if (usingValuePassed || !create) + notifyPut(offset, true, key, usingValue, posFromOffset(offset)); return usingValue; } else { return null;