From f7f886938b629d2e0ea23e18da43fbfbd86eb596 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Mon, 24 Nov 2014 10:10:34 +0000 Subject: [PATCH] allow event listener to be NULL --- .../chronicle/map/ReplicatedChronicleMap.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java index 9c0dd6062..c725c74d5 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java @@ -31,6 +31,7 @@ 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; @@ -1387,7 +1388,7 @@ final class ReplicatedChronicleMap, private final ATSDirectBitSet modIterSet; private final MapEventListener> nextListener; - public ModificationDelegator(@NotNull final MapEventListener> nextListener, + public ModificationDelegator(@Nullable final MapEventListener> nextListener, final Bytes bytes) { this.nextListener = nextListener; modIterSet = new ATSDirectBitSet(bytes); @@ -1430,11 +1431,12 @@ final class ReplicatedChronicleMap, assert ReplicatedChronicleMap.this == map : "ModificationIterator.onPut() is called from outside of the parent map"; - try { - nextListener.onPut(map, entry, metaDataBytes, added, key, replacedValue, value, pos, segment); - } catch (Exception e) { - LOG.error("", e); - } + if (nextListener != null) + try { + nextListener.onPut(map, entry, metaDataBytes, added, key, replacedValue, value, pos, segment); + } catch (Exception e) { + LOG.error("", e); + } dirty(map, pos, segment); } @@ -1459,7 +1461,9 @@ final class ReplicatedChronicleMap, K key, V value, long pos, SharedSegment segment) { assert ReplicatedChronicleMap.this == map : "ModificationIterator.onRemove() is called from outside of the parent map"; - try { + + if (nextListener != null) + try { nextListener.onRemove(map, entry, metaDataBytes, key, value, pos, segment); } catch (Exception e) { LOG.error("", e); @@ -1491,7 +1495,8 @@ final class ReplicatedChronicleMap, @Override public void onGetFound(ChronicleMap map, Bytes entry, int metaDataBytes, K key, V value) { - nextListener.onGetFound(map, entry, metaDataBytes, key, value); + if (nextListener != null) + nextListener.onGetFound(map, entry, metaDataBytes, key, value); } /**