mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-26 05:41:08 +01:00
Added a utility method to MapValue for creating tombstone instances
Change-Id: I2ddc30ebb9dac3b865a13c0a32b46b39cafb1aa8
This commit is contained in:
parent
a0ac487b96
commit
43f37959da
@ -314,7 +314,7 @@ public class EventuallyConsistentMapImpl<K, V>
|
|||||||
checkState(!destroyed, destroyedMessage);
|
checkState(!destroyed, destroyedMessage);
|
||||||
checkNotNull(key, ERROR_NULL_KEY);
|
checkNotNull(key, ERROR_NULL_KEY);
|
||||||
// TODO prevent calls here if value is important for timestamp
|
// TODO prevent calls here if value is important for timestamp
|
||||||
MapValue<V> tombstone = new MapValue<>(null, timestampProvider.apply(key, null));
|
MapValue<V> tombstone = MapValue.tombstone(timestampProvider.apply(key, null));
|
||||||
MapValue<V> previousValue = removeInternal(key, Optional.empty(), tombstone);
|
MapValue<V> previousValue = removeInternal(key, Optional.empty(), tombstone);
|
||||||
if (previousValue != null) {
|
if (previousValue != null) {
|
||||||
notifyPeers(new UpdateEntry<>(key, tombstone), peerUpdateFunction.apply(key, previousValue.get()));
|
notifyPeers(new UpdateEntry<>(key, tombstone), peerUpdateFunction.apply(key, previousValue.get()));
|
||||||
@ -330,7 +330,7 @@ public class EventuallyConsistentMapImpl<K, V>
|
|||||||
checkState(!destroyed, destroyedMessage);
|
checkState(!destroyed, destroyedMessage);
|
||||||
checkNotNull(key, ERROR_NULL_KEY);
|
checkNotNull(key, ERROR_NULL_KEY);
|
||||||
checkNotNull(value, ERROR_NULL_VALUE);
|
checkNotNull(value, ERROR_NULL_VALUE);
|
||||||
MapValue<V> tombstone = new MapValue<>(null, timestampProvider.apply(key, value));
|
MapValue<V> tombstone = MapValue.tombstone(timestampProvider.apply(key, value));
|
||||||
MapValue<V> previousValue = removeInternal(key, Optional.of(value), tombstone);
|
MapValue<V> previousValue = removeInternal(key, Optional.of(value), tombstone);
|
||||||
if (previousValue != null) {
|
if (previousValue != null) {
|
||||||
notifyPeers(new UpdateEntry<>(key, tombstone), peerUpdateFunction.apply(key, previousValue.get()));
|
notifyPeers(new UpdateEntry<>(key, tombstone), peerUpdateFunction.apply(key, previousValue.get()));
|
||||||
@ -561,7 +561,7 @@ public class EventuallyConsistentMapImpl<K, V>
|
|||||||
if (remoteValueDigest != null && remoteValueDigest.isTombstone()) {
|
if (remoteValueDigest != null && remoteValueDigest.isTombstone()) {
|
||||||
MapValue<V> previousValue = removeInternal(key,
|
MapValue<V> previousValue = removeInternal(key,
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
new MapValue<>(null, remoteValueDigest.timestamp()));
|
MapValue.tombstone(remoteValueDigest.timestamp()));
|
||||||
if (previousValue != null && previousValue.isAlive()) {
|
if (previousValue != null && previousValue.isAlive()) {
|
||||||
externalEvents.add(new EventuallyConsistentMapEvent<>(REMOVE, key, previousValue.get()));
|
externalEvents.add(new EventuallyConsistentMapEvent<>(REMOVE, key, previousValue.get()));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,17 @@ public class MapValue<V> implements Comparable<MapValue<V>> {
|
|||||||
private final Timestamp timestamp;
|
private final Timestamp timestamp;
|
||||||
private final V value;
|
private final V value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a tombstone value with the specified timestamp.
|
||||||
|
* @param timestamp timestamp for tombstone
|
||||||
|
* @return tombstone MapValue
|
||||||
|
*
|
||||||
|
* @param <U> value type
|
||||||
|
*/
|
||||||
|
public static <U> MapValue<U> tombstone(Timestamp timestamp) {
|
||||||
|
return new MapValue<>(null, timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
public MapValue(V value, Timestamp timestamp) {
|
public MapValue(V value, Timestamp timestamp) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user