From 5db55e566bf54a3c38bd486ed0da46cfdc3e76a8 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Mon, 24 Nov 2014 10:37:55 +0000 Subject: [PATCH] reverted this change back ( allow event listener to be NULL ), but instead introduced "the NOP event listener" --- .../chronicle/map/ReplicatedChronicleMap.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java index c725c74d5..4dfb2a062 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java @@ -31,7 +31,6 @@ import net.openhft.lang.io.NativeBytes; import net.openhft.lang.model.Byteable; import net.openhft.lang.threadlocal.ThreadLocalCopies; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -189,7 +188,7 @@ final class ReplicatedChronicleMap, startOfModificationIterators = offset; - modificationDelegator = new ModificationDelegator(eventListener, modDelBytes); + modificationDelegator = new ModificationDelegator(attachedEventListener(), modDelBytes); } @Override @@ -205,7 +204,7 @@ final class ReplicatedChronicleMap, * @return the event listener added by the user */ MapEventListener> attachedEventListener() { - return eventListener; + return eventListener == null ? MapEventListeners.NOP : eventListener; } @@ -1388,7 +1387,7 @@ final class ReplicatedChronicleMap, private final ATSDirectBitSet modIterSet; private final MapEventListener> nextListener; - public ModificationDelegator(@Nullable final MapEventListener> nextListener, + public ModificationDelegator(@NotNull final MapEventListener> nextListener, final Bytes bytes) { this.nextListener = nextListener; modIterSet = new ATSDirectBitSet(bytes); @@ -1431,12 +1430,12 @@ final class ReplicatedChronicleMap, assert ReplicatedChronicleMap.this == map : "ModificationIterator.onPut() is called from outside of the parent map"; - if (nextListener != null) - try { - nextListener.onPut(map, entry, metaDataBytes, added, key, replacedValue, value, pos, segment); - } catch (Exception e) { - LOG.error("", e); - } + + try { + nextListener.onPut(map, entry, metaDataBytes, added, key, replacedValue, value, pos, segment); + } catch (Exception e) { + LOG.error("", e); + } dirty(map, pos, segment); } @@ -1462,8 +1461,7 @@ final class ReplicatedChronicleMap, assert ReplicatedChronicleMap.this == map : "ModificationIterator.onRemove() is called from outside of the parent map"; - if (nextListener != null) - try { + try { nextListener.onRemove(map, entry, metaDataBytes, key, value, pos, segment); } catch (Exception e) { LOG.error("", e); @@ -1495,8 +1493,7 @@ final class ReplicatedChronicleMap, @Override public void onGetFound(ChronicleMap map, Bytes entry, int metaDataBytes, K key, V value) { - if (nextListener != null) - nextListener.onGetFound(map, entry, metaDataBytes, key, value); + nextListener.onGetFound(map, entry, metaDataBytes, key, value); } /**