Added a utility method to MapValue for creating tombstone instances
Change-Id: I2ddc30ebb9dac3b865a13c0a32b46b39cafb1aa8
Showing
2 changed files
with
14 additions
and
3 deletions
... | @@ -314,7 +314,7 @@ public class EventuallyConsistentMapImpl<K, V> | ... | @@ -314,7 +314,7 @@ public class EventuallyConsistentMapImpl<K, V> |
314 | checkState(!destroyed, destroyedMessage); | 314 | checkState(!destroyed, destroyedMessage); |
315 | checkNotNull(key, ERROR_NULL_KEY); | 315 | checkNotNull(key, ERROR_NULL_KEY); |
316 | // TODO prevent calls here if value is important for timestamp | 316 | // TODO prevent calls here if value is important for timestamp |
317 | - MapValue<V> tombstone = new MapValue<>(null, timestampProvider.apply(key, null)); | 317 | + MapValue<V> tombstone = MapValue.tombstone(timestampProvider.apply(key, null)); |
318 | MapValue<V> previousValue = removeInternal(key, Optional.empty(), tombstone); | 318 | MapValue<V> previousValue = removeInternal(key, Optional.empty(), tombstone); |
319 | if (previousValue != null) { | 319 | if (previousValue != null) { |
320 | notifyPeers(new UpdateEntry<>(key, tombstone), peerUpdateFunction.apply(key, previousValue.get())); | 320 | notifyPeers(new UpdateEntry<>(key, tombstone), peerUpdateFunction.apply(key, previousValue.get())); |
... | @@ -330,7 +330,7 @@ public class EventuallyConsistentMapImpl<K, V> | ... | @@ -330,7 +330,7 @@ public class EventuallyConsistentMapImpl<K, V> |
330 | checkState(!destroyed, destroyedMessage); | 330 | checkState(!destroyed, destroyedMessage); |
331 | checkNotNull(key, ERROR_NULL_KEY); | 331 | checkNotNull(key, ERROR_NULL_KEY); |
332 | checkNotNull(value, ERROR_NULL_VALUE); | 332 | checkNotNull(value, ERROR_NULL_VALUE); |
333 | - MapValue<V> tombstone = new MapValue<>(null, timestampProvider.apply(key, value)); | 333 | + MapValue<V> tombstone = MapValue.tombstone(timestampProvider.apply(key, value)); |
334 | MapValue<V> previousValue = removeInternal(key, Optional.of(value), tombstone); | 334 | MapValue<V> previousValue = removeInternal(key, Optional.of(value), tombstone); |
335 | if (previousValue != null) { | 335 | if (previousValue != null) { |
336 | notifyPeers(new UpdateEntry<>(key, tombstone), peerUpdateFunction.apply(key, previousValue.get())); | 336 | notifyPeers(new UpdateEntry<>(key, tombstone), peerUpdateFunction.apply(key, previousValue.get())); |
... | @@ -561,7 +561,7 @@ public class EventuallyConsistentMapImpl<K, V> | ... | @@ -561,7 +561,7 @@ public class EventuallyConsistentMapImpl<K, V> |
561 | if (remoteValueDigest != null && remoteValueDigest.isTombstone()) { | 561 | if (remoteValueDigest != null && remoteValueDigest.isTombstone()) { |
562 | MapValue<V> previousValue = removeInternal(key, | 562 | MapValue<V> previousValue = removeInternal(key, |
563 | Optional.empty(), | 563 | Optional.empty(), |
564 | - new MapValue<>(null, remoteValueDigest.timestamp())); | 564 | + MapValue.tombstone(remoteValueDigest.timestamp())); |
565 | if (previousValue != null && previousValue.isAlive()) { | 565 | if (previousValue != null && previousValue.isAlive()) { |
566 | externalEvents.add(new EventuallyConsistentMapEvent<>(REMOVE, key, previousValue.get())); | 566 | externalEvents.add(new EventuallyConsistentMapEvent<>(REMOVE, key, previousValue.get())); |
567 | } | 567 | } | ... | ... |
... | @@ -12,6 +12,17 @@ public class MapValue<V> implements Comparable<MapValue<V>> { | ... | @@ -12,6 +12,17 @@ public class MapValue<V> implements Comparable<MapValue<V>> { |
12 | private final Timestamp timestamp; | 12 | private final Timestamp timestamp; |
13 | private final V value; | 13 | private final V value; |
14 | 14 | ||
15 | + /** | ||
16 | + * Creates a tombstone value with the specified timestamp. | ||
17 | + * @param timestamp timestamp for tombstone | ||
18 | + * @return tombstone MapValue | ||
19 | + * | ||
20 | + * @param <U> value type | ||
21 | + */ | ||
22 | + public static <U> MapValue<U> tombstone(Timestamp timestamp) { | ||
23 | + return new MapValue<>(null, timestamp); | ||
24 | + } | ||
25 | + | ||
15 | public MapValue(V value, Timestamp timestamp) { | 26 | public MapValue(V value, Timestamp timestamp) { |
16 | this.value = value; | 27 | this.value = value; |
17 | this.timestamp = timestamp; | 28 | this.timestamp = timestamp; | ... | ... |
-
Please register or login to post a comment