Class ChannelHandlerUtils
java.lang.Object
dev.tachyonmcp.core.transport.netty.ChannelHandlerUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcaptureInitRequest(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpRequest req, ServerEngine server) When a customSessionIdGeneratoris configured on a stateful server, stashes a detached copy of the request (method/URI/headers) on the channel's interaction context so the generator can read it at session-creation time.static @Nullable ChannelContextgetInteractionContext(io.netty.channel.ChannelHandlerContext ctx) Returns the protocol interaction context bound to this channel, ornull.static @Nullable SessiongetSession(io.netty.channel.Channel channel) Returns the session bound to this channel, ornull.static ChannelContextrequireInteractionContext(io.netty.channel.ChannelHandlerContext ctx) static voidsendAccepted(io.netty.channel.ChannelHandlerContext ctx, @Nullable String origin) static io.netty.channel.ChannelFuturesendPlainTextAndClose(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpResponseStatus status, String message) Writes atext/plainresponse and closes the connection.static io.netty.channel.ChannelFuturesendPlainTextAndClose(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpResponseStatus status, String message, @Nullable String origin) static io.netty.channel.ChannelFuturesendResponseAndClose(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpResponseStatus status, String contentType, byte[] body, @Nullable String origin) Zero-copy overload for GC-managed bodies: wraps the byte[] at send time on the event loop.static io.netty.channel.ChannelFuturesendResponseAndClose(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpResponseStatus status, String contentType, io.netty.buffer.ByteBuf body, @Nullable String origin) Writes a response with the given content type and body, then closes the connection with aConnection: closeheader.static voidsetSession(io.netty.channel.ChannelHandlerContext ctx, Session session) Binds a session to the channel and installs theSessionTouchHandlerif not already present.
-
Method Details
-
setSession
Binds a session to the channel and installs theSessionTouchHandlerif not already present. Every outbound byte written to this channel will refresh the session's liveness.- Parameters:
ctx- the channel handler contextsession- the session to bind
-
getSession
Returns the session bound to this channel, ornull.- Parameters:
channel- the channel- Returns:
- the session, or
null
-
getInteractionContext
public static @Nullable ChannelContext getInteractionContext(io.netty.channel.ChannelHandlerContext ctx) Returns the protocol interaction context bound to this channel, ornull.- Parameters:
ctx- the channel handler context- Returns:
- the interaction context, or
null
-
requireInteractionContext
-
captureInitRequest
public static void captureInitRequest(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpRequest req, ServerEngine server) When a customSessionIdGeneratoris configured on a stateful server, stashes a detached copy of the request (method/URI/headers) on the channel's interaction context so the generator can read it at session-creation time. A copy is required because the pooled request is released before the async dispatch runs.- Parameters:
ctx- the channel handler contextreq- the HTTP request to captureserver- the server engine
-
sendAccepted
public static void sendAccepted(io.netty.channel.ChannelHandlerContext ctx, @Nullable String origin) -
sendPlainTextAndClose
public static io.netty.channel.ChannelFuture sendPlainTextAndClose(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpResponseStatus status, String message) Writes atext/plainresponse and closes the connection. The response carriesConnection: closeso the client does not return the socket to its keep-alive pool (reusing a socket the server is about to close causes intermittent "other side closed" errors, e.g. with undici on Linux). Prefer this oversendPlainText(...).addListener(CLOSE). -
sendPlainTextAndClose
-
sendResponseAndClose
public static io.netty.channel.ChannelFuture sendResponseAndClose(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpResponseStatus status, String contentType, io.netty.buffer.ByteBuf body, @Nullable String origin) Writes a response with the given content type and body, then closes the connection with aConnection: closeheader. SeesendPlainTextAndClose(io.netty.channel.ChannelHandlerContext, io.netty.handler.codec.http.HttpResponseStatus, java.lang.String)for why the header matters. -
sendResponseAndClose
public static io.netty.channel.ChannelFuture sendResponseAndClose(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpResponseStatus status, String contentType, byte[] body, @Nullable String origin) Zero-copy overload for GC-managed bodies: wraps the byte[] at send time on the event loop.
-