Class ExpirationTimeMergePolicy<K,V>

java.lang.Object
com.loomcache.server.wan.merge.ExpirationTimeMergePolicy<K,V>
Type Parameters:
K - key type
V - value type
All Implemented Interfaces:
MergePolicy<K,V>

public final class ExpirationTimeMergePolicy<K,V> extends Object implements MergePolicy<K,V>
Merge policy that keeps the entry that will expire later.

Entries without an expiration time use MergePolicy.NO_EXPIRATION_TIME_MILLIS, so they win over entries with finite TTLs. When expiration times tie, the policy falls back to the same deterministic timestamp and writer-id ordering as LatestUpdateMergePolicy.

Since:
2.0
  • Constructor Details

    • ExpirationTimeMergePolicy

      public ExpirationTimeMergePolicy()
  • Method Details

    • instance

      public static <K,V> @NonNull ExpirationTimeMergePolicy<K,V> instance()
      Return the shared instance of this stateless policy.
      Type Parameters:
      K - key type
      V - value type
      Returns:
      a shared ExpirationTimeMergePolicy instance
    • merge

      public @NonNull Optional<V> merge(@NonNull K key, @NonNull MergePolicy.MergeEntry<V> incoming, @Nullable MergePolicy.MergeEntry<V> existing)
      Description copied from interface: MergePolicy
      Merge an incoming replication entry against the existing local entry.
      Specified by:
      merge in interface MergePolicy<K,V>
      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)