Record Class IdempotencyEntry

java.lang.Object
java.lang.Record
com.tnsai.idempotency.IdempotencyEntry
Record Components:
result - successful return value; empty when the entry stores a failure
failure - class name of the throwable + message; empty when the entry stores a success. Stored as a record rather than the throwable so the entry is serializable across stores (Redis / Postgres can't roundtrip arbitrary Throwables)
storedAt - when the entry was cached
firstAttemptId - correlation id of the original call — useful for stitching a duplicate-prevented log line back to the originating event

public record IdempotencyEntry(Optional<Object> result, Optional<IdempotencyEntry.FailureSnapshot> failure, Instant storedAt, String firstAttemptId) extends Record
Stored record of a previous tool / action call's outcome, keyed by its idempotency key in an IdempotencyStore (issue #91).

The entry remembers either the successful result OR the failure that happened — never both. Consumers inspect isFailure() to decide which branch to read. Failures are cached only when the call site opted into it via @Idempotent(cacheFailures = true).

Since:
0.5.0 (issue #91)
  • Constructor Details

  • Method Details

    • isFailure

      public boolean isFailure()
      true if this entry represents a stored failure.
    • isSuccess

      public boolean isSuccess()
      true if this entry represents a stored success.
    • forSuccess

      public static IdempotencyEntry forSuccess(Object result, String firstAttemptId)
      Build a success entry. Convenience for the common "tool returned X" caching path.
    • forFailure

      public static IdempotencyEntry forFailure(Throwable t, String firstAttemptId)
      Build a failure entry. Convenience for the cacheFailures = true path.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • result

      public Optional<Object> result()
      Returns the value of the result record component.
      Returns:
      the value of the result record component
    • failure

      Returns the value of the failure record component.
      Returns:
      the value of the failure record component
    • storedAt

      public Instant storedAt()
      Returns the value of the storedAt record component.
      Returns:
      the value of the storedAt record component
    • firstAttemptId

      public String firstAttemptId()
      Returns the value of the firstAttemptId record component.
      Returns:
      the value of the firstAttemptId record component