Package dev.tachyonmcp.core.runtime
Class Session
java.lang.Object
dev.tachyonmcp.core.runtime.Session
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanactivate()Transitions fromSessionState.INITIALIZINGtoSessionState.ACTIVE.Returns the current backpressure state.booleanclearConnection(SseConnection expected) Detachesexpectedif it is still the current connection, resetting toSseConnection.noop().booleanclose()Closes the session and its underlying connection.Recomputes and returns the backpressure state based on stream writability.Returns the current SSE connection.voidconnection(SseConnection connection) Replaces the SSE connection (e.g. after reconnection).longcursor()Returns the last replayed SSE event cursor.voidcursor(long position) Sets the replayed SSE event cursor.voidenableExtension(String extensionId) Enables an extension for this session.booleaninthashCode()id()Returns the unique session identifier.booleanisExtensionEnabled(String extensionId) Returns whether the given extension is enabled for this session.longReturns the nanosecond timestamp of the last activity on this session.@Nullable Protocolprotocol()Returns the protocol negotiated when this session was initialized, if available.voidRecords the protocol negotiated when this session was initialized.@Nullable StringThe POST-SSE stream key the current connection is resuming, parsed from a<n>#<key>Last-Event-ID;nullfor the general GET listening stream or a fresh connection.voidresumingStreamKey(@Nullable String streamKey) Records the POST-SSE stream key the current connection is resuming (ornull).booleanSends an SSE event to the client.booleanReturnstrueif the session should throttle outbound events.state()Returns the current session state.toString()voidtouch()Updates the last-activity timestamp to now.
-
Field Details
-
state
-
lastActivityNanos
protected volatile long lastActivityNanos
-
-
Constructor Details
-
Session
-
-
Method Details
-
id
Returns the unique session identifier. -
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()Transitions fromSessionState.INITIALIZINGtoSessionState.ACTIVE. -
connection
Returns the current SSE connection. -
resumingStreamKey
The POST-SSE stream key the current connection is resuming, parsed from a<n>#<key>Last-Event-ID;nullfor 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
Records the POST-SSE stream key the current connection is resuming (ornull). -
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
Detachesexpectedif it is still the current connection, resetting toSseConnection.noop(). Returnstrueif it was detached. Used by a channel's close listener so a superseded connection's close does not wipe a newer one. -
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
Returns the protocol negotiated when this session was initialized, if available. -
protocol
Records the protocol negotiated when this session was initialized. -
enableExtension
Enables an extension for this session. -
isExtensionEnabled
Returns whether the given extension is enabled for this session. -
computeBackpressure
Recomputes and returns the backpressure state based on stream writability. -
shouldThrottle
public boolean shouldThrottle()Returnstrueif the session should throttle outbound events. -
send
Sends an SSE event to the client. Returnsfalsewithout 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 viaLast-Event-IDon reconnect. -
close
public boolean close()Closes the session and its underlying connection. Returnstrueif this call closed it. -
equals
-
hashCode
public int hashCode() -
toString
-