Class PostSseStream

java.lang.Object
dev.tachyonmcp.core.transport.netty.sse.PostSseStream
All Implemented Interfaces:
OutboundSseStream

public final class PostSseStream extends Object implements 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

    Constructors
    Constructor
    Description
    PostSseStream(io.netty.channel.Channel channel, @Nullable String origin, LongSupplier eventIdSupplier, Duration heartbeatInterval)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the SSE stream.
    void
    comment(@Nullable String message)
    Writes an SSE comment line (: message\r\n), upgrading the stream via OutboundSseStream.start() first if it has not started.
    void
    Activates the SSE stream and emits initial framing.
    boolean
     
    A stable key identifying this stream within its session, used to tag event-log entries and to suffix SSE event ids (<n>#<key>) so a Last-Event-ID can be correlated back to the originating stream for per-stream replay.
    void
     
    boolean
    Returns whether the stream is currently open and its channel can accept a write.
    void
    writeEvent(long sseEventId, byte[] body, @Nullable Runnable onDropped)
    Writes a final response event, invoking onDropped (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.
    void
    writeEvent(@Nullable SseEvent event)
    Writes an SSE event.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PostSseStream

      public PostSseStream(io.netty.channel.Channel channel, @Nullable String origin, LongSupplier eventIdSupplier, Duration heartbeatInterval)
  • Method Details

    • streamKey

      public String streamKey()
      Description copied from interface: OutboundSseStream
      A stable key identifying this stream within its session, used to tag event-log entries and to suffix SSE event ids (<n>#<key>) so a Last-Event-ID can be correlated back to the originating stream for per-stream replay. null identifies the session's general-purpose GET stream.
      Specified by:
      streamKey in interface OutboundSseStream
    • start

      public void start()
      Description copied from interface: OutboundSseStream
      Activates the SSE stream and emits initial framing. Idempotent — subsequent calls are no-ops. May be called from any thread.
      Specified by:
      start in interface OutboundSseStream
    • started

      public boolean started()
      Specified by:
      started in interface OutboundSseStream
      Returns:
      true once the stream has been opened.
    • writable

      public boolean writable()
      Returns whether the stream is currently open and its channel can accept a write.
    • writeEvent

      public void writeEvent(@Nullable SseEvent event)
      Description copied from interface: OutboundSseStream
      Writes an SSE event. If OutboundSseStream.start() has not been called yet, the event is buffered and emitted when the stream upgrades. May be called from any thread.
      Specified by:
      writeEvent in interface OutboundSseStream
      Parameters:
      event - the SSE event to write
    • writeEvent

      public void writeEvent(long sseEventId, byte[] body, @Nullable Runnable onDropped)
      Writes a final response event, invoking onDropped (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

      public void comment(@Nullable String message)
      Description copied from interface: OutboundSseStream
      Writes an SSE comment line (: message\r\n), upgrading the stream via OutboundSseStream.start() first if it has not started. A comment carries no event data — it exists to keep the connection alive without a progress token. A null or 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:
      comment in interface OutboundSseStream
      Parameters:
      message - comment text (a single line; embedded line breaks are flattened), or null
    • close

      public void close()
      Description copied from interface: OutboundSseStream
      Closes the SSE stream. Idempotent — subsequent calls are no-ops.
      Specified by:
      close in interface OutboundSseStream
    • terminate

      public void terminate()