Class IdempotencyRecord

java.lang.Object
io.github.ravocode.avoonce.core.domain.IdempotencyRecord

public class IdempotencyRecord extends Object
Immutable value object representing a single idempotency record stored in the repository.

A record captures the full lifecycle of an idempotent request: from the initial lock acquisition (IdempotencyStatus.STARTED), through successful completion (IdempotencyStatus.COMPLETED), or failure (IdempotencyStatus.FAILED).

Repository implementations use this record to enforce exactly-once processing guarantees and replay cached responses on retry.

  • Constructor Details

    • IdempotencyRecord

      public IdempotencyRecord(String idempotencyKey, IdempotencyStatus status, IdempotencyResponse response, Long expiresAt)
      Constructs an IdempotencyRecord without a request hash (hash validation disabled).
      Parameters:
      idempotencyKey - the unique idempotency key.
      status - the current lifecycle status.
      response - the cached response, or null if not yet completed.
      expiresAt - the epoch-millisecond expiry timestamp, or null for COMPLETED records.
    • IdempotencyRecord

      public IdempotencyRecord(String idempotencyKey, IdempotencyStatus status, IdempotencyResponse response, Long expiresAt, String requestHash)
      Constructs an IdempotencyRecord with full fields including a request hash.
      Parameters:
      idempotencyKey - the unique idempotency key.
      status - the current lifecycle status.
      response - the cached response, or null if not yet completed.
      expiresAt - the epoch-millisecond expiry timestamp, or null for COMPLETED records.
      requestHash - the SHA-256 hash of the original request body; may be null to skip validation.
  • Method Details

    • getIdempotencyKey

      public String getIdempotencyKey()
      Returns the unique idempotency key.
      Returns:
      the idempotency key string.
    • getStatus

      public IdempotencyStatus getStatus()
      Returns the current lifecycle status of this record.
      Returns:
      the IdempotencyStatus.
    • getResponse

      public IdempotencyResponse getResponse()
      Returns the cached HTTP response for replay, or null if the request has not completed successfully.
      Returns:
      the IdempotencyResponse, or null.
    • getExpiresAt

      public Long getExpiresAt()
      Returns the epoch-millisecond timestamp at which the STARTED lock expires.
      Returns:
      the expiry timestamp in milliseconds, or null for COMPLETED records.
    • getRequestHash

      public String getRequestHash()
      Returns the SHA-256 hash of the original request body used for payload mismatch detection.
      Returns:
      the hex-encoded SHA-256 hash, or null if hash validation is disabled.