From adb309185c43befc432a898b83bf0b3337c185b9 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Sat, 12 Dec 2015 15:12:42 +0000 Subject: [PATCH] added identifier etc for remove events. --- .../chronicle/map/MapEventListener.java | 50 +++++-------------- .../chronicle/map/ReplicatedChronicleMap.java | 18 +++++-- .../chronicle/map/VanillaChronicleMap.java | 19 ++++--- 3 files changed, 39 insertions(+), 48 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/MapEventListener.java b/src/main/java/net/openhft/chronicle/map/MapEventListener.java index 0ca16958b..48e1c9275 100644 --- a/src/main/java/net/openhft/chronicle/map/MapEventListener.java +++ b/src/main/java/net/openhft/chronicle/map/MapEventListener.java @@ -97,6 +97,7 @@ public abstract class MapEventListener implements Serializable { } + private static class LoggingMapEventListener extends MapEventListener { private static final long serialVersionUID = 0L; public final static Logger LOGGER = LoggerFactory.getLogger(LoggingMapEventListener.class); @@ -119,7 +120,7 @@ public abstract class MapEventListener implements Serializable { } @Override - public void onRemove(Object key, Object value, boolean replicationEvent) { + public void onRemove(Object key, Object value, boolean replicationEvent, byte identifier, byte replacedIdentifier, long timestamp, long replacedTimeStamp) { LOGGER.info("{} remove {} was {}", prefix, key, value); } } @@ -136,47 +137,22 @@ public abstract class MapEventListener implements Serializable { // do nothing } - /** - * 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. - * - *

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 replicationEvent {@code true} if its a replicaiton event - * @param timestamp the time the event occurred - * @param replacedTimestamp the time stamp that has just been replaced - * @param identifier the node identifier associated with this update - * @param replacedTimestamp the identifier that has just been replaced. - */ - public void onPut(K key, - V newValue, - @Nullable V replacedValue, - boolean replicationEvent, - boolean added, long timestamp, - long replacedTimestamp, - byte identifier, - byte replacedIdentifier, - boolean hasValueChanged) { - - } - /** * 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 replicationEvent + * @param key the key removed from the map + * @param value the value which was associated with the given key + * @param replicationEvent {@code true} if its a replication event + * @param identifier the identifer used for replicaiton or zero if not definded + * @param replacedIdentifier the replaced identifer used for replicaiton or zero if not + * definded + * @param timestamp the timestamp used for replicaiton or zero if not definded + * @param replacedTimeStamp the replaced timestamp used for replicaiton or zero if not + * definded */ - public void onRemove(K key, V value, boolean replicationEvent) { + public void onRemove(K key, V value, boolean replicationEvent, byte identifier, + byte replacedIdentifier, long timestamp, long replacedTimeStamp) { // do nothing } } diff --git a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java index 12efa0310..7bd9eb9b0 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java @@ -1448,7 +1448,8 @@ final class ReplicatedChronicleMap ((TimestampTrackingEntry) returnedEntry).timestamp) { + final long timestamp = ((TimestampTrackingEntry) returnedEntry).timestamp; + + if (replacedTimeStamp > timestamp) { // The entry was updated after being returned from iterator.next() // Check that it is still the entry with the same key K key = returnedEntry.getKey(); @@ -1717,7 +1724,8 @@ final class ReplicatedChronicleMap, } return removeEntry(copies, searchState, key, keySize, toKey, toValue, readValue, resultUnused, hashLookup, entry, pos, valueSizePos, - valueSize, false, true, expectedValue != null); + valueSize, false, true, expectedValue != null, (byte) 0, 0, + (byte) 0, 0); } // key is not found if (expectedValue == null) { @@ -2594,7 +2595,7 @@ class VanillaChronicleMap, ReadValue readValue, boolean resultUnused, MultiMap hashLookup, MultiStoreBytes entry, long pos, long valueSizePos, long valueSize, boolean remote, boolean removeFromMultiMap, - boolean booleanResult) { + boolean booleanResult, byte identifier, long timestamp, byte replacedIdentifier, long replacedTimestamp) { // get the removed value, if needed RV removedValue = null; if ((!booleanResult && !resultUnused) || eventListener != null) { @@ -2621,7 +2622,8 @@ class VanillaChronicleMap, V removedValueForEventListener = toValue.toInstance(copies, removedValue, valueSize); eventListener.onRemove(toKey.toInstance(copies, key, keySize), - removedValueForEventListener, remote); + removedValueForEventListener, remote, identifier, replacedIdentifier, + timestamp, replacedTimestamp); } return booleanResult ? Boolean.TRUE : removedValue; @@ -3037,11 +3039,14 @@ class VanillaChronicleMap, long position = entry.position(); final long segmentHash = segmentHash(Hasher.hash(entry, position, position + keySize)); - removePresent(segment, pos, entry, keySize, segmentHash, true); + removePresent(segment, pos, entry, keySize, segmentHash, true, (byte) 0, + (byte) 0, + 0, 0); } final void removePresent(Segment segment, long pos, NativeBytes entry, long keySize, - long segmentHash, boolean removeFromMultiMap) { + long segmentHash, boolean removeFromMultiMap, final byte identifier, + final byte replacedIdentifier, final long timestamp, final long replacedTimeStamp) { entry.skip(keySize); segment.manageReplicationBytes(entry, true, true); long valueSizePos = entry.position(); @@ -3060,7 +3065,9 @@ class VanillaChronicleMap, if (bytesEventListener != null) bytesEventListener.onRemove(entry, 0L, metaDataBytes, valueSizePos, false); if (eventListener != null) - eventListener.onRemove(returnedEntry.getKey(), returnedEntry.getValue(), false); + eventListener.onRemove(returnedEntry.getKey(), returnedEntry.getValue(), false, + identifier, + replacedIdentifier, timestamp, replacedTimeStamp); } }