SagaStep

interface SagaStep<T : SagaStep<T>>(source)

Persistence-agnostic contract for a single step of a saga.

Implementations can be backed by any storage technology (JPA, MongoDB, DynamoDB, in-memory, …). The engine and adapters only depend on this interface, never on a concrete entity class.

All fields are exposed as read-only (val). State transitions are performed exclusively through behavior methods that encapsulate the aggregate's invariants. See Saga for the rationale behind this design.

Inheritors

Properties

Link copied to clipboard
abstract val compensationStepId: Long?

When this step compensates another, the id of the originally-completed step it reverts.

Link copied to clipboard
abstract val completedAt: Instant?

Instant the step reached a terminal status; null while it is still in progress.

Link copied to clipboard
abstract val createdAt: Instant

Instant the step row was created.

Link copied to clipboard
abstract val errorMessage: String?

Latest failure reason if the step failed or its compensation failed; null otherwise.

Link copied to clipboard
abstract val id: Long?

Storage-assigned surrogate id; null until the row is first persisted.

Link copied to clipboard
abstract val payload: String?

Step-local payload as a JSON string; null when the step carries no data.

Link copied to clipboard
abstract val sagaId: String

Owning saga's id (Saga.id).

Link copied to clipboard
abstract val status: SagaStepStatus

Current lifecycle SagaStepStatus; see the enum's KDoc for terminal/transient semantics.

Link copied to clipboard
abstract val stepName: String

Step name; conventionally a SagaTypeValue.value. Compensation rows are prefixed with Compensate.

Link copied to clipboard
abstract val version: Long?

JPA optimistic-locking version, or null for storage backends that do not provide one.

Functions

Link copied to clipboard
abstract fun linkToCompensationStep(compensationStepId: Long): T

Records the id of the compensating step that reverted this one.

Link copied to clipboard
abstract fun markCompensated(): T
Link copied to clipboard
abstract fun markCompensationFailed(error: String?): T

Transitions to SagaStepStatus.COMPENSATION_FAILED and stores error as errorMessage.

Link copied to clipboard
abstract fun markCompleted(): T

Transitions to SagaStepStatus.COMPLETED and stamps completedAt.

Link copied to clipboard
abstract fun markFailed(error: String): T

Transitions to SagaStepStatus.FAILED and stores error as errorMessage.