Class SseHeartbeat
java.lang.Object
dev.tachyonmcp.core.transport.netty.sse.SseHeartbeat
Keeps long-lived SSE streams alive across idle periods. A channel carrying an open SSE response is
marked via
enable(Channel, Duration) which starts a scheduler that periodically writes
an SSE comment heartbeat (:\r\n). The scheduler runs on the channel's event loop.
A heartbeat byte flowing through the pipeline triggers SessionTouchHandler
which refreshes session liveness — no scattered touch() calls needed.
A heartbeat is itself a chunk write, so a failed write (dead client, RST) closes the channel.
Call with interval <= 0 to disable heartbeats (silent SSE channels then close on idle
via the existing idle handler).
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidEnables periodic heartbeats onchannelat the giveninterval.static booleanisEnabled(io.netty.channel.Channel channel) static voidsend(io.netty.channel.Channel channel) Writes an SSE comment heartbeat (:\r\n) on the channel, closing the channel if the write fails.
-
Method Details
-
enable
Enables periodic heartbeats onchannelat the giveninterval.interval <= 0(Duration.isZero()or negative) disables heartbeats entirely. Call after the SSE response headers are written. -
isEnabled
public static boolean isEnabled(io.netty.channel.Channel channel) - Returns:
trueifchannelcarries an open SSE stream.
-
send
public static void send(io.netty.channel.Channel channel) Writes an SSE comment heartbeat (:\r\n) on the channel, closing the channel if the write fails. Skipped when the channel is inactive or already backpressured (bytes are pending, so the stream is not actually idle).
-