Class SseHeartbeat

java.lang.Object
dev.tachyonmcp.core.transport.netty.sse.SseHeartbeat

public final class SseHeartbeat extends Object
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 Type
    Method
    Description
    static void
    enable(io.netty.channel.Channel channel, Duration interval)
    Enables periodic heartbeats on channel at the given interval.
    static boolean
    isEnabled(io.netty.channel.Channel channel)
     
    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.

    Methods inherited from class java.lang.Object

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

    • enable

      public static void enable(io.netty.channel.Channel channel, Duration interval)
      Enables periodic heartbeats on channel at the given interval. 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:
      true if channel carries 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).