Interface MergePolicy<K,V>
- Type Parameters:
K- key typeV- value type
- All Known Subinterfaces:
CustomMergePolicy<K,V>
- All Known Implementing Classes:
DiscardMergePolicy, ExpirationTimeMergePolicy, HigherHitsMergePolicy, LatestAccessMergePolicy, LatestUpdateMergePolicy, PassThroughMergePolicy, PutIfAbsentMergePolicy
public sealed interface MergePolicy<K,V>
permits CustomMergePolicy<K,V>, DiscardMergePolicy<K,V>, ExpirationTimeMergePolicy<K,V>, HigherHitsMergePolicy<K,V>, LatestAccessMergePolicy<K,V>, LatestUpdateMergePolicy<K,V>, PassThroughMergePolicy<K,V>, PutIfAbsentMergePolicy<K,V>
Strategy for resolving conflicts when an incoming WAN replication event
meets an existing local value.
Unlike WanConsumer.ConflictResolver (which
operates on raw byte arrays and timestamps only), MergePolicy carries
richer MergePolicy.MergeEntry metadata (timestamp, writer id, reads, access, and expiration) and returns an
Optional so implementations can explicitly reject the incoming
update without having to encode that intent as a sentinel byte array.
Return semantics:
Optional.of(value)— apply this value locally (overwrites existing)Optional.empty()— reject the incoming update; keep existing as-is
This interface is sealed so built-in policies remain explicit, while custom
implementations extend via the non-sealed CustomMergePolicy SPI.
- Since:
- 2.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordA replication entry with timestamp, writer-id, read-hit, access-time, and expiration-time metadata for merge policies. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longExpiration-time sentinel for entries that do not expire. -
Method Summary
Modifier and TypeMethodDescriptionmerge(@NonNull K key, @NonNull MergePolicy.MergeEntry<V> incoming, @Nullable MergePolicy.MergeEntry<V> existing) Merge an incoming replication entry against the existing local entry.
-
Field Details
-
NO_EXPIRATION_TIME_MILLIS
static final long NO_EXPIRATION_TIME_MILLISExpiration-time sentinel for entries that do not expire.- See Also:
-
-
Method Details
-
merge
@NonNull Optional<V> merge(@NonNull K key, @NonNull MergePolicy.MergeEntry<V> incoming, @Nullable MergePolicy.MergeEntry<V> existing) Merge an incoming replication entry against the existing local entry.- Parameters:
key- the key being replicated (non-null)incoming- the incoming entry from the remote cluster (non-null)existing- the current local entry, ornullif the key has no local value- Returns:
- the value to keep (non-empty to apply, empty to reject the incoming)
-