Contents
- Description
- Method Summary
- Method Details
- flush()
- write(ToClientPacket)
- writeAndFlush(ToClientPacket)
- write(ToClientPacket[])
- writeAndFlush(ToClientPacket[])
- isActive()
- isWritable()
- remoteAddress()
- formatRemoteAddress()
- disconnect(FormattedMessage)
- getPacketStatsRecorder()
- getSniHostname()
- isFromSameOrigin(ChannelConnection)
- execute(Runnable)
- getClientCertificate()
- initTimeoutContext(String, String)
- updateTimeoutContext(String, String)
- updateTimeoutContext(String)
- setPacketTimeout(Duration)
- clearPacketTimeout()
- setStageTimeout(String, Duration, BooleanSupplier, Runnable)
- clearStageTimeout()
- logConnectionTimings(String, Level)
- setupAuxiliaryChannels(ConnectionHandler, BiConsumer)
- setChannelHandler(ConnectionHandler)
- closeConnection()
- closeApplicationConnection()
- closeApplicationConnection(QuicApplicationErrorCode)
- closeApplicationConnection(QuicApplicationErrorCode, FormattedMessage)
- updateStreamPriority(int, boolean)
Interface ChannelConnection
- All Known Implementing Classes:
NettyUtil.NettyChannelConnection
public interface ChannelConnection
-
Method Summary
Modifier and TypeMethodDescriptionvoidCancels any currently scheduled packet read timeout.voidCancels any currently scheduled stage timeout.voidCloses the connection gracefully as an application-level close with no error.voidCloses the connection gracefully with a specific application error code.voidcloseApplicationConnection(QuicApplicationErrorCode errorCode, FormattedMessage reason) Closes the connection gracefully with an application error code and reason message.voidvoiddisconnect(FormattedMessage message) voidvoidflush()voidinitTimeoutContext(String stage, String identifier) Initializes the timeout context for a new connection.booleanisActive()booleanTests if this connection andothercome from the same remote origin.booleanvoidlogConnectionTimings(String message, Level level) Logs connection timing information, tracking the time delta between consecutive calls.voidsetChannelHandler(ConnectionHandler handler) Replaces the current packet handler on this connection.voidsetPacketTimeout(Duration timeout) Sets the packet read timeout for the decoder.voidsetStageTimeout(String stage, Duration timeout, BooleanSupplier condition, Runnable onTimeout) Schedules a stage timeout that fires the given callback if the condition is not met within the specified duration.setupAuxiliaryChannels(ConnectionHandler handler, BiConsumer<NetworkChannel, ChannelConnection> onChannelReady) Creates auxiliary network channels (e.g., Chunks, WorldMap) for this connection.voidupdateStreamPriority(int urgency, boolean incremental) Updates the QUIC stream priority for this connection's stream.voidupdateTimeoutContext(String stage) Updates the timeout context with a new stage, keeping the existing identifier.voidupdateTimeoutContext(String stage, String identifier) Updates the timeout context with a new stage and identifier.voidwrite(ToClientPacket packet) voidwrite(ToClientPacket[] packets) voidwriteAndFlush(ToClientPacket packet) voidwriteAndFlush(ToClientPacket[] packets)
-
Method Details
-
flush
void flush() -
write
-
writeAndFlush
-
write
-
writeAndFlush
-
isActive
boolean isActive() -
isWritable
boolean isWritable() -
remoteAddress
SocketAddress remoteAddress() -
formatRemoteAddress
String formatRemoteAddress() -
disconnect
-
getPacketStatsRecorder
-
getSniHostname
-
isFromSameOrigin
Tests if this connection andothercome from the same remote origin. A reconnecting player opens a new connection, so this must compare remote addresses. It must not compare connection identity, which is never equal across two connections. Implementations delegate toConnectionOrigin.isFromSameOrigin(SocketAddress, SocketAddress).- Parameters:
other- the connection to compare against- Returns:
trueif both connections are from the same origin
-
execute
-
getClientCertificate
X509Certificate getClientCertificate() -
initTimeoutContext
Initializes the timeout context for a new connection. Call this once when the first handler is registered.- Parameters:
stage- The initial stage name.identifier- The player identifier (typically remote address at this point).
-
updateTimeoutContext
-
updateTimeoutContext
Updates the timeout context with a new stage, keeping the existing identifier.- Parameters:
stage- The new stage name.
-
setPacketTimeout
Sets the packet read timeout for the decoder.- Parameters:
timeout- The timeout duration.
-
clearPacketTimeout
void clearPacketTimeout()Cancels any currently scheduled packet read timeout. -
setStageTimeout
void setStageTimeout(@Nonnull String stage, @Nonnull Duration timeout, @Nonnull BooleanSupplier condition, @Nonnull Runnable onTimeout) Schedules a stage timeout that fires the given callback if the condition is not met within the specified duration. Cancels any previously scheduled stage timeout.- Parameters:
stage- The stage name (for logging).timeout- The timeout duration.condition- Returns true if the stage completed successfully (timeout should not fire).onTimeout- Callback to run when the timeout fires and the condition is not met.
-
clearStageTimeout
void clearStageTimeout()Cancels any currently scheduled stage timeout. -
logConnectionTimings
-
setupAuxiliaryChannels
@Nonnull CompletableFuture<Void> setupAuxiliaryChannels(@Nonnull ConnectionHandler handler, @Nonnull BiConsumer<NetworkChannel, ChannelConnection> onChannelReady) Creates auxiliary network channels (e.g., Chunks, WorldMap) for this connection. For multiplexed transports (QUIC), creates separate unidirectional streams.- Parameters:
handler- The connection handler for pipeline setup on new streams.onChannelReady- Called for each auxiliary channel when it is ready, with theNetworkChanneland the correspondingChannelConnection.- Returns:
- a future that completes when all auxiliary channels are set up.
-
setChannelHandler
Replaces the current packet handler on this connection. Manages lifecycle callbacks (unregistered/registered) on old and new handlers.- Parameters:
handler- The new handler to set
-
closeConnection
void closeConnection() -
closeApplicationConnection
void closeApplicationConnection()Closes the connection gracefully as an application-level close with no error. Use this after sending a Disconnect packet for clean shutdown. -
closeApplicationConnection
Closes the connection gracefully with a specific application error code. For QUIC, sends an APPLICATION_CLOSE frame to properly notify the client.- Parameters:
errorCode- Application-defined error code
-
closeApplicationConnection
void closeApplicationConnection(@Nonnull QuicApplicationErrorCode errorCode, @Nonnull FormattedMessage reason) Closes the connection gracefully with an application error code and reason message. The reason is serialized as aFormattedMessageinto the QUIC CONNECTION_CLOSE frame so the peer can render a localized disconnect reason.- Parameters:
errorCode- Application-defined error codereason- Reason message carried in the CONNECTION_CLOSE reason phrase
-
updateStreamPriority
void updateStreamPriority(int urgency, boolean incremental) Updates the QUIC stream priority for this connection's stream. Lower urgency values indicate higher priority. Incremental streams may be interleaved with other streams at the same urgency level.- Parameters:
urgency- The urgency level (0 = highest priority)incremental- Whether this stream's data can be interleaved with other streams
-