Class PostSseStream
java.lang.Object
dev.tachyonmcp.core.transport.netty.sse.PostSseStream
- All Implemented Interfaces:
OutboundSseStream
Per-POST SSE response stream. Lazily upgrades the POST response from JSON to an SSE stream
when the dispatching handler emits a server-to-client message.
All state transitions and queued-event mutations are serialized onto the channel's
EventLoop. The state is volatile only because started() and
writable() may be queried from another thread; only the event loop writes it.
-
Constructor Summary
ConstructorsConstructorDescriptionPostSseStream(io.netty.channel.Channel channel, @Nullable String origin, LongSupplier eventIdSupplier, Duration heartbeatInterval) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the SSE stream.voidWrites an SSE comment line (: message\r\n), upgrading the stream viaOutboundSseStream.start()first if it has not started.voidstart()Activates the SSE stream and emits initial framing.booleanstarted()A stable key identifying this stream within its session, used to tag event-log entries and to suffix SSE event ids (<n>#<key>) so aLast-Event-IDcan be correlated back to the originating stream for per-stream replay.voidbooleanwritable()Returns whether the stream is currently open and its channel can accept a write.voidwriteEvent(long sseEventId, byte[] body, @Nullable Runnable onDropped) Writes a final response event, invokingonDropped(on the event loop) when the write is discarded because this stream is already closed or its channel is dead — letting the caller re-deliver the buffered response to a reconnected stream instead of losing it.voidwriteEvent(@Nullable SseEvent event) Writes an SSE event.
-
Constructor Details
-
PostSseStream
public PostSseStream(io.netty.channel.Channel channel, @Nullable String origin, LongSupplier eventIdSupplier, Duration heartbeatInterval)
-
-
Method Details
-
streamKey
Description copied from interface:OutboundSseStreamA stable key identifying this stream within its session, used to tag event-log entries and to suffix SSE event ids (<n>#<key>) so aLast-Event-IDcan be correlated back to the originating stream for per-stream replay.nullidentifies the session's general-purpose GET stream.- Specified by:
streamKeyin interfaceOutboundSseStream
-
start
public void start()Description copied from interface:OutboundSseStreamActivates the SSE stream and emits initial framing. Idempotent — subsequent calls are no-ops. May be called from any thread.- Specified by:
startin interfaceOutboundSseStream
-
started
public boolean started()- Specified by:
startedin interfaceOutboundSseStream- Returns:
trueonce the stream has been opened.
-
writable
public boolean writable()Returns whether the stream is currently open and its channel can accept a write. -
writeEvent
Description copied from interface:OutboundSseStreamWrites an SSE event. IfOutboundSseStream.start()has not been called yet, the event is buffered and emitted when the stream upgrades. May be called from any thread.- Specified by:
writeEventin interfaceOutboundSseStream- Parameters:
event- the SSE event to write
-
writeEvent
Writes a final response event, invokingonDropped(on the event loop) when the write is discarded because this stream is already closed or its channel is dead — letting the caller re-deliver the buffered response to a reconnected stream instead of losing it. -
comment
Description copied from interface:OutboundSseStreamWrites an SSE comment line (: message\r\n), upgrading the stream viaOutboundSseStream.start()first if it has not started. A comment carries no event data — it exists to keep the connection alive without a progress token. Anullor blank message emits a bare:\r\n. May be called from any thread. Default is a no-op for transports that do not support raw comments.- Specified by:
commentin interfaceOutboundSseStream- Parameters:
message- comment text (a single line; embedded line breaks are flattened), ornull
-
close
public void close()Description copied from interface:OutboundSseStreamCloses the SSE stream. Idempotent — subsequent calls are no-ops.- Specified by:
closein interfaceOutboundSseStream
-
terminate
public void terminate()
-