Package com.tnsai.idempotency
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 failurefailure- 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 cachedfirstAttemptId- 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)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordLightweight snapshot of a stored failure. -
Constructor Summary
ConstructorsConstructorDescriptionIdempotencyEntry(Optional<Object> result, Optional<IdempotencyEntry.FailureSnapshot> failure, Instant storedAt, String firstAttemptId) Creates an instance of aIdempotencyEntryrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.failure()Returns the value of thefailurerecord component.Returns the value of thefirstAttemptIdrecord component.static IdempotencyEntryforFailure(Throwable t, String firstAttemptId) Build a failure entry.static IdempotencyEntryforSuccess(Object result, String firstAttemptId) Build a success entry.final inthashCode()Returns a hash code value for this object.booleantrueif this entry represents a stored failure.booleantrueif this entry represents a stored success.result()Returns the value of theresultrecord component.storedAt()Returns the value of thestoredAtrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
IdempotencyEntry
public IdempotencyEntry(Optional<Object> result, Optional<IdempotencyEntry.FailureSnapshot> failure, Instant storedAt, String firstAttemptId) Creates an instance of aIdempotencyEntryrecord class.- Parameters:
result- the value for theresultrecord componentfailure- the value for thefailurerecord componentstoredAt- the value for thestoredAtrecord componentfirstAttemptId- the value for thefirstAttemptIdrecord component
-
-
Method Details
-
isFailure
public boolean isFailure()trueif this entry represents a stored failure. -
isSuccess
public boolean isSuccess()trueif this entry represents a stored success. -
forSuccess
Build a success entry. Convenience for the common "tool returned X" caching path. -
forFailure
Build a failure entry. Convenience for thecacheFailures = truepath. -
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
result
Returns the value of theresultrecord component.- Returns:
- the value of the
resultrecord component
-
failure
Returns the value of thefailurerecord component.- Returns:
- the value of the
failurerecord component
-
storedAt
Returns the value of thestoredAtrecord component.- Returns:
- the value of the
storedAtrecord component
-
firstAttemptId
Returns the value of thefirstAttemptIdrecord component.- Returns:
- the value of the
firstAttemptIdrecord component
-