added further fields to ByteEventListener such as byte replacedIdentifier, long timeStamp, long replacedTimeStamp

This commit is contained in:
Rob Austin
2015-12-14 11:17:37 +00:00
parent a46a0f0ceb
commit d1513a4ba9
4 changed files with 68 additions and 34 deletions
@@ -22,23 +22,20 @@ import net.openhft.lang.io.Bytes;
import java.io.Serializable;
/**
* <ul>
* <li>Methods must not update {@code entry} state ({@linkplain Bytes#position(long) position},
* {@linkplain Bytes#limit() limit}).</li>
* <li>Methods must not update entry bytes, except in metadata area</li>
* <li>From {@code metaDataPos} offset metadata area starts in the given {@code entry}, listener
* should be itself aware of it's length (see {@link ChronicleMapBuilder#metaDataBytes(int)}).</li>
* <li>From {@code keyPos} offset key area in the given {@code entry}, serialized key size
* (using {@linkplain ChronicleMapBuilder#keySizeMarshaller(SizeMarshaller)}), directly followed
* by the serialized key itself.</li>
* <li>From {@code valuePos} offset value area in the given {@code entry}, serialized value size
* (using {@linkplain ChronicleMapBuilder#keySizeMarshaller(SizeMarshaller)}), then (optionally)
* alignment (see {@link ChronicleMapBuilder#entryAndValueAlignment(Alignment)}
* ), followed by the serialized value itself.</li>
* </ul>
* <ul> <li>Methods must not update {@code entry} state ({@linkplain Bytes#position(long) position},
* {@linkplain Bytes#limit() limit}).</li> <li>Methods must not update entry bytes, except in
* metadata area</li> <li>From {@code metaDataPos} offset metadata area starts in the given {@code
* entry}, listener should be itself aware of it's length (see {@link
* ChronicleMapBuilder#metaDataBytes(int)}).</li> <li>From {@code keyPos} offset key area in the
* given {@code entry}, serialized key size (using {@linkplain ChronicleMapBuilder#keySizeMarshaller(SizeMarshaller)}),
* directly followed by the serialized key itself.</li> <li>From {@code valuePos} offset value area
* in the given {@code entry}, serialized value size (using {@linkplain
* ChronicleMapBuilder#keySizeMarshaller(SizeMarshaller)}), then (optionally) alignment (see {@link
* ChronicleMapBuilder#entryAndValueAlignment(Alignment)} ), followed by the serialized value
* itself.</li> </ul>
*
* <p>There are helper methods {@link ChronicleMap#readKey(Bytes, long)} and
* {@link ChronicleMap#readValue(Bytes, long)} that help to deal with this.
* <p>There are helper methods {@link ChronicleMap#readKey(Bytes, long)} and {@link
* ChronicleMap#readValue(Bytes, long)} that help to deal with this.
*/
public abstract class BytesMapEventListener implements Serializable {
private static final long serialVersionUID = 0L;
@@ -48,12 +45,14 @@ public abstract class BytesMapEventListener implements Serializable {
}
public void onPut(Bytes entry, long metaDataPos, long keyPos, long valuePos, boolean added,
boolean replicationEvent, boolean hasValueChanged) {
boolean replicationEvent, boolean hasValueChanged, byte identifier,
byte replacedIdentifier, long timeStamp, long replacedTimeStamp) {
// do nothing
}
public void onRemove(Bytes entry, long metaDataPos, long keyPos, long valuePos,
boolean replicationEvent) {
boolean replicationEvent, byte identifier,
byte replacedIdentifier, long timeStamp, long replacedTimeStamp) {
// do nothing
}
}
@@ -950,7 +950,8 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
onPut(this, pos);
if (bytesEventListener != null) {
bytesEventListener.onPut(entry, 0L, metaDataBytes, valuePos, true, false,
true);
true, localIdentifier, replacedIdentifier, timestamp,
replacedTimestamp);
}
if (eventListener != null) {
V valueInstance = toValue.toInstance(copies, v, valueSize);
@@ -1157,7 +1158,10 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
if (bytesEventListener != null) {
boolean hasValueChanged = updateResult != UpdateResult.UNCHANGED;
bytesEventListener.onPut(
entry, 0L, metaDataBytes, valueSizePos, false, false, hasValueChanged);
entry, 0L, metaDataBytes, valueSizePos, false, false,
hasValueChanged,
identifier, replacedIdentifier,
timeStamp, replacedTimestamp);
}
if (eventListener != null) {
boolean hasValueChanged = updateResult != UpdateResult.UNCHANGED;
@@ -1198,9 +1202,13 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
// put callbacks
onPutMaybeRemote(segmentState.pos, false);
if (bytesEventListener != null)
if (bytesEventListener != null) {
byte replacedIdentifier = 0;
long replacedTimestamp = 0;
bytesEventListener.onPut(entry, 0L, metaDataBytes,
segmentState.valueSizePos, true, false, true);
segmentState.valueSizePos, true, false, true, identifier, replacedIdentifier, timeStamp, replacedTimestamp);
}
if (eventListener != null) {
byte replacedIdentifier = 0;
long replacedTimestamp = 0;
@@ -1323,9 +1331,13 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
// put callbacks
onPutMaybeRemote(segmentState.pos, remote);
if (bytesEventListener != null)
if (bytesEventListener != null) {
byte replacedIdentifier = 0;
long replacedTimestamp = 0;
bytesEventListener.onPut(entry, 0L, metaDataBytes,
segmentState.valueSizePos, true, remote, true);
segmentState.valueSizePos, true, remote, true, identifier, replacedIdentifier, timestamp,
replacedTimestamp);
}
if (eventListener != null) {
byte replacedIdentifier = 0;
long replacedTimestamp = 0;
@@ -2108,8 +2108,12 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
onPut(this, segmentState.pos);
if (bytesEventListener != null) {
long keyPos = metaDataBytes;
byte replacedIdentifier = (byte) 0;
long replacedTimeStamp = 0;
bytesEventListener.onPut(entry, 0L, keyPos, segmentState.valueSizePos, true,
false, true);
false, true,
segmentState.identifier, replacedIdentifier,
segmentState.timestamp, replacedTimeStamp);
}
if (eventListener != null) {
byte replacedIdentifier = (byte) 0;
@@ -2209,7 +2213,11 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
// put callbacks
onPutMaybeRemote(segmentState.pos, false);
if (bytesEventListener != null)
bytesEventListener.onPut(entry, 0L, metaDataBytes, valueSizePos, false, false, hasValueChanged);
bytesEventListener.onPut(entry, 0L, metaDataBytes, valueSizePos, false,
false, hasValueChanged,
segmentState.identifier, (byte) 0,
segmentState.timestamp, 0
);
if (eventListener != null) {
eventListener.onPut(toKey.toInstance(copies, key, keySize),
@@ -2230,9 +2238,14 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
// put callbacks
onPut(this, segmentState.pos);
if (bytesEventListener != null)
if (bytesEventListener != null) {
byte replacedIdentifier = 0;
long replacedTimeStamp = 0;
bytesEventListener.onPut(entry, 0L, metaDataBytes,
segmentState.valueSizePos, true, false, hasValueChanged);
segmentState.valueSizePos, true, false, true,
segmentState.identifier, replacedIdentifier,
segmentState.timestamp, replacedTimeStamp);
}
if (eventListener != null) {
byte replacedIdentifier = 0;
long replacedTimeStamp = 0;
@@ -2332,7 +2345,8 @@ 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, false, hasValueChanged);
segmentState.valueSizePos, true, false, hasValueChanged,
segmentState.identifier, (byte) 0, segmentState.timestamp, 0);
if (eventListener != null)
eventListener.onPut(toKey.toInstance(copies, key, keySize),
toValue.toInstance(copies, value, valueSize), null, false, true, true,
@@ -2397,7 +2411,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, remote, hasValueChanged);
bytesEventListener.onPut(entry, 0L, metaDataBytes, valueSizePos, false, remote,
hasValueChanged,
segmentState.identifier, replacedIdentifier,
segmentState.timestamp, replacedTimestamp);
if (eventListener != null) {
eventListener.onPut(toKey.toInstance(copies, key, keySize),
toValue.toInstance(copies, value, valueSize), prevValueInstance, remote,
@@ -2643,7 +2660,9 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
// remove callbacks
onRemoveMaybeRemote(pos, remote);
if (bytesEventListener != null)
bytesEventListener.onRemove(entry, 0L, metaDataBytes, valueSizePos, remote);
bytesEventListener.onRemove(entry, 0L, metaDataBytes, valueSizePos, remote,
segmentState.identifier, replacedIdentifier,
segmentState.timestamp, replacedTimestamp);
if (eventListener != null) {
V removedValueForEventListener =
toValue.toInstance(copies, removedValue, valueSize);
@@ -2798,7 +2817,10 @@ 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, false, hasValueChanged);
bytesEventListener.onPut(entry, 0L, keyPos, segmentState.valueSizePos, true,
false, hasValueChanged,
segmentState.identifier, replacedIdentifier,
segmentState.timestamp, replacedTimestamp);
}
if (eventListener != null)
eventListener.onPut(toKey.toInstance(copies, key, keySize),