Class IdempotencyStore

java.lang.Object
io.agentscope.extensions.channel.common.IdempotencyStore
All Implemented Interfaces:
InboundEventDeduplicator

public final class IdempotencyStore extends Object implements InboundEventDeduplicator
Bounded in-process implementation of InboundEventDeduplicator. Webhook providers (notably WeCom) commonly retry the same message id under failure; this store de-duplicates by msgId.

Internal map is bounded to maxEntries — when full, entries are evicted to make room: expired entries are dropped first, after which the victim is unspecified. Entries are also lazily expired after ttlMillis.

State lives in the JVM heap, so deduplication only holds within a single process; see InboundEventDeduplicator for multi-instance deployments. This class is thread-safe.

  • Constructor Details

    • IdempotencyStore

      public IdempotencyStore()
      Default 5-minute TTL, 10k entries — sufficient for any single channel's retry burst.
    • IdempotencyStore

      public IdempotencyStore(long ttlMillis, int maxEntries)
  • Method Details

    • firstSeen

      public boolean firstSeen(String key)
      Records key as seen. Returns true when key has not been observed within the TTL (the caller should proceed), false when it is a redelivery. An accepted observation restarts the key's retention window, so after the TTL lapses only the first redelivery proceeds and the rest are still dropped.
      Specified by:
      firstSeen in interface InboundEventDeduplicator
      Parameters:
      key - opaque deduplication key composed by the caller; null is treated as always first-seen
      Returns:
      true when key has not been observed within the implementation's retention horizon and the caller should process the event; false when it is a redelivery and must be dropped
    • size

      public int size()
      Returns the current size; mostly for tests/observability.