From a0ecb8fc6b91d8028d1209ff9d174d236e147935 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Thu, 20 Aug 2015 14:04:49 +0100 Subject: [PATCH] HCOLL-382 add the UpdateResult field to net.openhft.chronicle.map.MapEventListener#onPut --- pom.xml | 2 +- .../chronicle/map/MapEventListener.java | 31 ++++++++++++------- .../chronicle/map/ReplicatedChronicleMap.java | 25 ++++++++------- .../map/ReplicationHubFindByName.java | 5 +-- .../chronicle/map/VanillaChronicleMap.java | 26 +++++++++------- ...tListenerWithTCPSocketReplicationTest.java | 3 +- 6 files changed, 53 insertions(+), 39 deletions(-) diff --git a/pom.xml b/pom.xml index 864e44b62..79c6bd09e 100755 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ 4.0.0 chronicle-map - 2.2.3-SNAPSHOT + 2.3.0-SNAPSHOT OpenHFT/Chronicle-Map Chronicle-Map diff --git a/src/main/java/net/openhft/chronicle/map/MapEventListener.java b/src/main/java/net/openhft/chronicle/map/MapEventListener.java index d68df4e42..12be02611 100644 --- a/src/main/java/net/openhft/chronicle/map/MapEventListener.java +++ b/src/main/java/net/openhft/chronicle/map/MapEventListener.java @@ -17,6 +17,7 @@ package net.openhft.chronicle.map; import net.openhft.chronicle.hash.ChronicleHashBuilder; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -79,7 +80,9 @@ public abstract class MapEventListener implements Serializable { } @Override - public void onPut(Object key, Object value, Object replacedValue, boolean replicationEvent) { + public void onPut(Object key, Object value, Object replacedValue, boolean + replicationEvent, + @NotNull boolean updateResult) { LOGGER.info("{} put {} => {}", prefix, key, value); } @@ -105,26 +108,32 @@ public abstract class MapEventListener implements Serializable { * This method is called whenever a new value is put for the key in the map during calls of such * methods as {@link ChronicleMap#put put}, {@link ChronicleMap#putIfAbsent putIfAbsent}, {@link * ChronicleMap#replace(Object, Object, Object) replace}, etc. When a new value is {@linkplain - * ChronicleMapBuilder#defaultValue(Object) default} for the map or obtained during - * {@link ChronicleMap#acquireUsing acquireUsing} call is put for the key, this method is called - * as well. + * ChronicleMapBuilder#defaultValue(Object) default} for the map or obtained during {@link + * ChronicleMap#acquireUsing acquireUsing} call is put for the key, this method is called as + * well. * *

This method is called when put is already happened. - * @param key the key the given value is put for - * @param newValue the value which is now associated with the given key - * @param replacedValue the value which was replaced by {@code newValue}, {@code null} if the - * key was absent in the map before current {@code ChronicleMap} + * + * @param key the key the given value is put for + * @param newValue the value which is now associated with the given key + * @param replacedValue the value which was replaced by {@code newValue}, {@code null} if the + * key was absent in the map before current {@code ChronicleMap} * @param replicationEvent */ - public void onPut(K key, V newValue, @Nullable V replacedValue, boolean replicationEvent) { + public void onPut(K key, + V newValue, + @Nullable V replacedValue, + boolean replicationEvent, + boolean added) { // do nothing } /** * This is called when an entry is removed. Misses, i. e. when {@code map.remove(key)} is * called, but key is already absent in the map, are not notified. - * @param key the key removed from the map - * @param value the value which was associated with the given key + * + * @param key the key removed from the map + * @param value the value which was associated with the given key * @param replicationEvent */ public void onRemove(K key, V value, boolean replicationEvent) { diff --git a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java index 70a0a877b..a47c018ef 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java @@ -962,7 +962,7 @@ final class ReplicatedChronicleMap, RV, VB extends RV, VBI, MVBI extends MetaBytesInterop> UpdateResult update(@Nullable ThreadLocalCopies copies, @Nullable SegmentState segmentState, - MKBI metaKeyInterop, KBI keyInterop, KB key, long keySize, - InstanceOrBytesToInstance toKey, - GetValueInterops getValueInterops, VB value, - InstanceOrBytesToInstance toValue, - long hash2, - byte identifier, long timeStamp) { + MKBI metaKeyInterop, KBI keyInterop, KB key, long keySize, + InstanceOrBytesToInstance toKey, + GetValueInterops getValueInterops, VB value, + InstanceOrBytesToInstance toValue, + long hash2, + byte identifier, long timeStamp) { segmentStateNotNullImpliesCopiesNotNull(copies, segmentState); if (segmentState == null) { copies = SegmentState.getCopies(copies); @@ -1157,7 +1157,8 @@ final class ReplicatedChronicleMap - *

We can reject put() and removes() when comparing times stamps with remote systems + *

We can reject put() and removes() when comparing times stamps with remote + * systems * * @param entry the maps entry * @param timestamp the time the entry was created or updated diff --git a/src/main/java/net/openhft/chronicle/map/ReplicationHubFindByName.java b/src/main/java/net/openhft/chronicle/map/ReplicationHubFindByName.java index 7c4068fbb..875475168 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicationHubFindByName.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicationHubFindByName.java @@ -57,8 +57,9 @@ class ReplicationHubFindByName implements FindByName { // creates a map based on the details that are sent to the map of builders @Override public void onPut(CharSequence key, MapInstanceBuilder value, - MapInstanceBuilder replacedValue, boolean replicationEvent) { - super.onPut(key, value, replacedValue, replicationEvent); + MapInstanceBuilder replacedValue, boolean replicationEvent, + boolean added0) { + super.onPut(key, value, replacedValue, replicationEvent, added0); boolean added = replacedValue == null; if (!added || value == null) return; diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index 8d5e7bcea..c2b8e1be8 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -2132,7 +2132,7 @@ class VanillaChronicleMap, } if (eventListener != null) { eventListener.onPut(toKey.toInstance(copies, key, keySize), - toValue.toInstance(copies, v, valueSize), null, false); + toValue.toInstance(copies, v, valueSize), null, false, true); } return v; @@ -2168,11 +2168,11 @@ class VanillaChronicleMap, , RV, VB extends RV, VBI, MVBI extends MetaBytesInterop> UpdateResult update(@Nullable ThreadLocalCopies copies, @Nullable SegmentState segmentState, - MKBI metaKeyInterop, KBI keyInterop, KB key, long keySize, - InstanceOrBytesToInstance toKey, - GetValueInterops getValueInterops, VB value, - InstanceOrBytesToInstance toValue, - long hash2) { + MKBI metaKeyInterop, KBI keyInterop, KB key, long keySize, + InstanceOrBytesToInstance toKey, + GetValueInterops getValueInterops, VB value, + InstanceOrBytesToInstance toValue, + long hash2) { shouldNotBeCalledFromReplicatedChronicleMap("Segment.update"); segmentStateNotNullImpliesCopiesNotNull(copies, segmentState); if (segmentState == null) { @@ -2222,7 +2222,8 @@ class VanillaChronicleMap, bytesEventListener.onPut(entry, 0L, metaDataBytes, valueSizePos, false, false); if (eventListener != null) { eventListener.onPut(toKey.toInstance(copies, key, keySize), - toValue.toInstance(copies, value, valueSize), null, false); + toValue.toInstance(copies, value, valueSize), null, false, + false); } } } @@ -2241,7 +2242,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), null, false, true); return UpdateResult.INSERT; } finally { @@ -2334,7 +2335,7 @@ class VanillaChronicleMap, segmentState.valueSizePos, true, false); if (eventListener != null) eventListener.onPut(toKey.toInstance(copies, key, keySize), - toValue.toInstance(copies, value, valueSize), oldValue, false); + toValue.toInstance(copies, value, valueSize), oldValue, false, true); return resultUnused ? null : readValue.readNull(); } @@ -2383,7 +2384,8 @@ class VanillaChronicleMap, bytesEventListener.onPut(entry, 0L, metaDataBytes, valueSizePos, false, remote); if (eventListener != null) { eventListener.onPut(toKey.toInstance(copies, key, keySize), - toValue.toInstance(copies, value, valueSize), prevValueInstance, remote); + toValue.toInstance(copies, value, valueSize), prevValueInstance, remote, + true); } return resultUnused ? null : prevValue; @@ -2764,7 +2766,7 @@ class VanillaChronicleMap, if (eventListener != null) eventListener.onPut(toKey.toInstance(copies, key, keySize), toValue.toInstance(copies, newValue, newValueSize), - toValue.toInstance(copies, prevValue, valueSize), false); + toValue.toInstance(copies, prevValue, valueSize), false, true); return expectedValue == null ? prevValue : Boolean.TRUE; } @@ -2971,7 +2973,7 @@ class VanillaChronicleMap, final Segment segment = segments[segIndex]; ThreadLocalCopies copies = SegmentState.getCopies(null); try (SegmentState segmentState = SegmentState.get(copies)) { - segment.readLock(null); + segment.readLock(null); if (segment.hashLookup().getPositions().isClear(pos)) { // the pos was removed after the previous advance diff --git a/src/test/java/net/openhft/chronicle/map/EventListenerWithTCPSocketReplicationTest.java b/src/test/java/net/openhft/chronicle/map/EventListenerWithTCPSocketReplicationTest.java index 4fe7324f4..df8ca8941 100644 --- a/src/test/java/net/openhft/chronicle/map/EventListenerWithTCPSocketReplicationTest.java +++ b/src/test/java/net/openhft/chronicle/map/EventListenerWithTCPSocketReplicationTest.java @@ -54,7 +54,8 @@ public class EventListenerWithTCPSocketReplicationTest { private static final long serialVersionUID = 1L; @Override - public void onPut(Integer key, CharSequence value, CharSequence replacedValue, boolean replicationEvent) { + public void onPut(Integer key, CharSequence value, CharSequence replacedValue, + boolean replicationEvent, boolean added) { putWasCalled.getAndSet(true); keyRef.set(key); valueRef.set(value);