Class Session

java.lang.Object
dev.tachyonmcp.core.runtime.Session

public class Session extends Object
A streamable-HTTP session shared by protocols on this transport. Tracks lifecycle state and the SSE channel (connection, backpressure, replay cursor) for a single client identified by a unique string ID1
  • Field Details

  • Constructor Details

  • Method Details

    • id

      public String id()
      Returns the unique session identifier.
    • state

      public SessionState state()
      Returns the current session state.
    • lastActivityNanos

      public long lastActivityNanos()
      Returns the nanosecond timestamp of the last activity on this session.
    • touch

      public void touch()
      Updates the last-activity timestamp to now.
    • activate

      public boolean activate()
    • connection

      public SseConnection connection()
      Returns the current SSE connection.
    • resumingStreamKey

      public @Nullable String resumingStreamKey()
      The POST-SSE stream key the current connection is resuming, parsed from a <n>#<key> Last-Event-ID; null for the general GET listening stream or a fresh connection. Lets a late POST-SSE response be re-delivered live to a connection that explicitly resumed that stream, without crossing streams.
    • resumingStreamKey

      public void resumingStreamKey(@Nullable String streamKey)
      Records the POST-SSE stream key the current connection is resuming (or null).
    • connection

      public void connection(SseConnection connection)
      Replaces the SSE connection (e.g. after reconnection). Closes the previously attached connection so a superseded channel is not left open (and kept alive by SSE heartbeats). If the session is (or becomes) SessionState.CLOSED, the incoming connection is closed instead of attached.
    • clearConnection

      public boolean clearConnection(SseConnection expected)
      Detaches expected if it is still the current connection, resetting to SseConnection.noop(). Returns true if it was detached. Used by a channel's close listener so a superseded connection's close does not wipe a newer one.
    • backpressure

      public Backpressure backpressure()
      Returns the current backpressure state.
    • cursor

      public long cursor()
      Returns the last replayed SSE event cursor.
    • cursor

      public void cursor(long position)
      Sets the replayed SSE event cursor.
    • protocol

      public @Nullable Protocol protocol()
      Returns the protocol negotiated when this session was initialized, if available.
    • protocol

      public void protocol(Protocol protocol)
      Records the protocol negotiated when this session was initialized.
    • enableExtension

      public void enableExtension(String extensionId)
      Enables an extension for this session.
    • isExtensionEnabled

      public boolean isExtensionEnabled(String extensionId)
      Returns whether the given extension is enabled for this session.
    • computeBackpressure

      public Backpressure computeBackpressure()
      Recomputes and returns the backpressure state based on stream writability.
    • shouldThrottle

      public boolean shouldThrottle()
      Returns true if the session should throttle outbound events.
    • send

      public boolean send(SseEvent event)
      Sends an SSE event to the client. Returns false without sending when no connection is attached or the stream is throttled (Backpressure.COLD) — a slow client must not accumulate events in the channel's outbound buffer. Dropped events stay in the event log and are replayable via Last-Event-ID on reconnect.
    • close

      public boolean close()
      Closes the session and its underlying connection. Returns true if this call closed it.
    • equals

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object