mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-286 HCOLL-292 added replicationEvent flag to event callbacks
This commit is contained in:
@@ -44,11 +44,13 @@ public abstract class BytesMapEventListener implements Serializable {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public void onPut(Bytes entry, long metaDataPos, long keyPos, long valuePos, boolean added) {
|
||||
public void onPut(Bytes entry, long metaDataPos, long keyPos, long valuePos, boolean added,
|
||||
boolean replicationEvent) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public void onRemove(Bytes entry, long metaDataPos, long keyPos, long valuePos) {
|
||||
public void onRemove(Bytes entry, long metaDataPos, long keyPos, long valuePos,
|
||||
boolean replicationEvent) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,12 +81,12 @@ public abstract class MapEventListener<K, V> implements Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPut(Object key, Object value, Object replacedValue) {
|
||||
public void onPut(Object key, Object value, Object replacedValue, boolean replicationEvent) {
|
||||
LOGGER.info("{} put {} => {}", prefix, key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(Object key, Object value) {
|
||||
public void onRemove(Object key, Object value, boolean replicationEvent) {
|
||||
LOGGER.info("{} remove {} was {}", prefix, key, value);
|
||||
}
|
||||
}
|
||||
@@ -112,24 +112,24 @@ public abstract class MapEventListener<K, V> implements Serializable {
|
||||
* as well.
|
||||
*
|
||||
* <p>This method is called when put is already happened.
|
||||
*
|
||||
* @param key the key the given value is put for
|
||||
* @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}
|
||||
* key was absent in the map before current {@code ChronicleMap}
|
||||
* @param replicationEvent
|
||||
*/
|
||||
public void onPut(K key, V newValue, @Nullable V replacedValue) {
|
||||
public void onPut(K key, V newValue, @Nullable V replacedValue, boolean replicationEvent) {
|
||||
// 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 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) {
|
||||
public void onRemove(K key, V value, boolean replicationEvent) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
@@ -766,11 +766,11 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
// put callbacks
|
||||
onPut(this, pos);
|
||||
if (bytesEventListener != null) {
|
||||
bytesEventListener.onPut(entry, 0L, metaDataBytes, valuePos, true);
|
||||
bytesEventListener.onPut(entry, 0L, metaDataBytes, valuePos, true, false);
|
||||
}
|
||||
if (eventListener != null) {
|
||||
V valueInstance = toValue.toInstance(copies, v, valueSize);
|
||||
eventListener.onPut(keyInstance, valueInstance, null);
|
||||
eventListener.onPut(keyInstance, valueInstance, null, false);
|
||||
}
|
||||
entryCreated(lock);
|
||||
return v;
|
||||
@@ -974,10 +974,10 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
onPutMaybeRemote(segmentState.pos, remote);
|
||||
if (bytesEventListener != null)
|
||||
bytesEventListener.onPut(entry, 0L, metaDataBytes,
|
||||
segmentState.valueSizePos, true);
|
||||
segmentState.valueSizePos, true, remote);
|
||||
if (eventListener != null)
|
||||
eventListener.onPut(toKey.toInstance(copies, key, keySize),
|
||||
toValue.toInstance(copies, value, valueSize), null);
|
||||
toValue.toInstance(copies, value, valueSize), null, remote);
|
||||
|
||||
return resultUnused ? null : readValue.readNull();
|
||||
}
|
||||
|
||||
@@ -57,8 +57,8 @@ class ReplicationHubFindByName<K> 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) {
|
||||
super.onPut(key, value, replacedValue);
|
||||
MapInstanceBuilder replacedValue, boolean replicationEvent) {
|
||||
super.onPut(key, value, replacedValue, replicationEvent);
|
||||
boolean added = replacedValue == null;
|
||||
if (!added || value == null)
|
||||
return;
|
||||
|
||||
@@ -1758,11 +1758,11 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
onPut(this, segmentState.pos);
|
||||
if (bytesEventListener != null) {
|
||||
long keyPos = metaDataBytes;
|
||||
bytesEventListener.onPut(entry, 0L, keyPos, segmentState.valueSizePos, true);
|
||||
bytesEventListener.onPut(entry, 0L, keyPos, segmentState.valueSizePos, true, false);
|
||||
}
|
||||
if (eventListener != null) {
|
||||
eventListener.onPut(toKey.toInstance(copies, key, keySize),
|
||||
toValue.toInstance(copies, v, valueSize), null);
|
||||
toValue.toInstance(copies, v, valueSize), null, false);
|
||||
}
|
||||
|
||||
return v;
|
||||
@@ -1866,10 +1866,10 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
onPut(this, segmentState.pos);
|
||||
if (bytesEventListener != null)
|
||||
bytesEventListener.onPut(entry, 0L, metaDataBytes,
|
||||
segmentState.valueSizePos, true);
|
||||
segmentState.valueSizePos, true, false);
|
||||
if (eventListener != null)
|
||||
eventListener.onPut(toKey.toInstance(copies, key, keySize),
|
||||
toValue.toInstance(copies, value, valueSize), null);
|
||||
toValue.toInstance(copies, value, valueSize), null, false);
|
||||
|
||||
return resultUnused ? null : readValue.readNull();
|
||||
}
|
||||
@@ -1913,10 +1913,10 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
// put callbacks
|
||||
onPutMaybeRemote(segmentState.pos, remote);
|
||||
if (bytesEventListener != null)
|
||||
bytesEventListener.onPut(entry, 0L, metaDataBytes, valueSizePos, false);
|
||||
bytesEventListener.onPut(entry, 0L, metaDataBytes, valueSizePos, false, remote);
|
||||
if (eventListener != null) {
|
||||
eventListener.onPut(toKey.toInstance(copies, key, keySize),
|
||||
toValue.toInstance(copies, value, valueSize), prevValueInstance);
|
||||
toValue.toInstance(copies, value, valueSize), prevValueInstance, remote);
|
||||
}
|
||||
|
||||
return resultUnused ? null : prevValue;
|
||||
@@ -2153,12 +2153,12 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
// remove callbacks
|
||||
onRemoveMaybeRemote(pos, remote);
|
||||
if (bytesEventListener != null)
|
||||
bytesEventListener.onRemove(entry, 0L, metaDataBytes, valueSizePos);
|
||||
bytesEventListener.onRemove(entry, 0L, metaDataBytes, valueSizePos, remote);
|
||||
if (eventListener != null) {
|
||||
V removedValueForEventListener =
|
||||
toValue.toInstance(copies, removedValue, valueSize);
|
||||
eventListener.onRemove(toKey.toInstance(copies, key, keySize),
|
||||
removedValueForEventListener);
|
||||
removedValueForEventListener, remote);
|
||||
}
|
||||
|
||||
return booleanResult ? Boolean.TRUE : removedValue;
|
||||
@@ -2292,12 +2292,12 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
onPut(this, segmentState.pos);
|
||||
if (bytesEventListener != null) {
|
||||
long keyPos = metaDataBytes;
|
||||
bytesEventListener.onPut(entry, 0L, keyPos, segmentState.valueSizePos, true);
|
||||
bytesEventListener.onPut(entry, 0L, keyPos, segmentState.valueSizePos, true, false);
|
||||
}
|
||||
if (eventListener != null)
|
||||
eventListener.onPut(toKey.toInstance(copies, key, keySize),
|
||||
toValue.toInstance(copies, newValue, newValueSize),
|
||||
toValue.toInstance(copies, prevValue, valueSize));
|
||||
toValue.toInstance(copies, prevValue, valueSize), false);
|
||||
|
||||
return expectedValue == null ? prevValue : Boolean.TRUE;
|
||||
}
|
||||
@@ -2590,9 +2590,9 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
// remove callbacks
|
||||
onRemove(segment, pos);
|
||||
if (bytesEventListener != null)
|
||||
bytesEventListener.onRemove(entry, 0L, metaDataBytes, valueSizePos);
|
||||
bytesEventListener.onRemove(entry, 0L, metaDataBytes, valueSizePos, false);
|
||||
if (eventListener != null)
|
||||
eventListener.onRemove(returnedEntry.getKey(), returnedEntry.getValue());
|
||||
eventListener.onRemove(returnedEntry.getKey(), returnedEntry.getValue(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,14 +76,14 @@ public class CHMMetaDataTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPut(Bytes entry, long metaDataPos, long keyPos, long valuePos, boolean added) {
|
||||
public void onPut(Bytes entry, long metaDataPos, long keyPos, long valuePos, boolean added, boolean replicationEvent) {
|
||||
if (added)
|
||||
assertEquals(0, entry.readLong(metaDataPos));
|
||||
entry.writeLong(metaDataPos, timeStamps.incrementAndGet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(Bytes entry, long metaDataPos, long keyPos, long valuePos) {
|
||||
public void onRemove(Bytes entry, long metaDataPos, long keyPos, long valuePos, boolean replicationEvent) {
|
||||
System.out.println("Removed entry with ts of " + entry.readLong(metaDataPos));;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -55,7 +55,7 @@ public class EventListenerWithTCPSocketReplicationTest {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void onPut(Integer key, CharSequence value, CharSequence replacedValue) {
|
||||
public void onPut(Integer key, CharSequence value, CharSequence replacedValue, boolean replicationEvent) {
|
||||
putWasCalled.getAndSet(true);
|
||||
keyRef.set(key);
|
||||
valueRef.set(value);
|
||||
@@ -63,7 +63,7 @@ public class EventListenerWithTCPSocketReplicationTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(Integer key, CharSequence value) {
|
||||
public void onRemove(Integer key, CharSequence value, boolean replicationEvent) {
|
||||
wasRemoved.set(true);
|
||||
valueRemoved.set(value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user