Terminal Decoder
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
nullfor payloads that cannot be decoded (unknown format, wrong version, corrupted bytes). The resume caller convertsnullto ResumeOutcome.CorruptJournal withatSeq = 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
The journal payload type.
The saga result type.