Package com.axelor.ai.chat.stream
Class ActiveStream
java.lang.Object
com.axelor.ai.chat.stream.ActiveStream
- All Implemented Interfaces:
AutoCloseable
Generation-side handle for one chat run. The agentic loop appends serialized SSE frames; frames
are flushed to the registry's chunk log and announced on the topic. Under a distributed cache
provider frames are micro-batched (~50L ms) to keep per-token network
roundtrips bounded; under caffeine every append flushes inline.
The cancel signal arrives via the registry topic: isCancelRequested() flips and the
onCancel(java.lang.Runnable) callback runs (immediately, if the signal already arrived).
-
Method Summary
Modifier and TypeMethodDescriptionvoidAppends serialized SSE frames.voidclose()voiddone()Flushes, marks the run done, releases the claim.booleanvoidRecords the assistant message this run generates, from its opening frame.voidRegisters the cancel callback; runs it immediately if cancel was already signalled.voidExempts subsequent appends from the size cap (error/abort/terminator frames).
-
Method Details
-
append
Appends serialized SSE frames. ThrowsStreamOverflowExceptionpast the size cap. -
markTurn
Records the assistant message this run generates, from its opening frame. First frame wins: a resuming client uses it to tell which of its persisted turns this run's replay rebuilds. -
terminating
public void terminating()Exempts subsequent appends from the size cap (error/abort/terminator frames). -
done
public void done()Flushes, marks the run done, releases the claim. Idempotent. Always stops the flusher and removes the listener even if a cache/topic call throws mid-way, so a failure at completion can never leak the virtual thread or the topic listener (or leaveclosedfalse, which would keep the flusher spinning and the claim blocked). -
onCancel
Registers the cancel callback; runs it immediately if cancel was already signalled. -
isCancelRequested
public boolean isCancelRequested() -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-