Interface MergePolicy<K,V>

Type Parameters:
K - key type
V - value type
All Known Subinterfaces:
CustomMergePolicy<K,V>
All Known Implementing Classes:
DiscardMergePolicy, ExpirationTimeMergePolicy, HigherHitsMergePolicy, LatestAccessMergePolicy, LatestUpdateMergePolicy, PassThroughMergePolicy, PutIfAbsentMergePolicy

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 Classes
    Modifier and Type
    Interface
    Description
    static final record 
    A replication entry with timestamp, writer-id, read-hit, access-time, and expiration-time metadata for merge policies.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Expiration-time sentinel for entries that do not expire.
  • Method Summary

    Modifier and Type
    Method
    Description
    @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.
  • Field Details

    • NO_EXPIRATION_TIME_MILLIS

      static final long NO_EXPIRATION_TIME_MILLIS
      Expiration-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, or null if the key has no local value
      Returns:
      the value to keep (non-empty to apply, empty to reject the incoming)