TerminalDecoder

fun interface TerminalDecoder<P, R>

User-supplied decoder that extracts a saga result R and TerminalOutcome from a journal Terminal entry's payload P.

Called once by ca.acendas.kstate.saga.StatefulSagaExecutor.resume when the last journal entry has phase ca.acendas.kstate.saga.journal.EntryPhase.Terminal.

Contract

  • Return non-null for payloads that were written by this executor — i.e., that encode a result and a TerminalOutcome discriminator.

  • Return null for payloads that cannot be decoded (unknown format, wrong version, corrupted bytes). The resume caller converts null to ResumeOutcome.CorruptJournal with atSeq = terminalEntry.seq.

  • Pure — must not perform I/O or mutate external state.

  • Exception-safe — if the decoder throws, the executor catches and wraps in ResumeOutcome.CorruptJournal with reason = "terminal-decode threw: <message>".

Example

// P = MyPayload, R = String
val decoder = TerminalDecoder<MyPayload, String> { payload ->
when (payload) {
is MyPayload.Terminal -> Pair(payload.result, payload.terminalOutcome)
else -> null // not a terminal payload variant
}
}

Parameters

P

The journal payload type.

R

The saga result type.

Functions

Link copied to clipboard
abstract fun decode(payload: P): Pair<R, TerminalOutcome>?

Decodes payload into a (result, terminalOutcome) pair, or returns null if payload is not a recognisable Terminal payload.