TimeoutHandler Class — netty Architecture
Architecture documentation for the TimeoutHandler class in QuicheQuicChannel.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 745f36f6_9a3c_f564_aaaa_aa3880bcb1f5["TimeoutHandler"] e2af940f_f48c_60ab_e67f_c3708214d676["QuicheQuicChannel.java"] 745f36f6_9a3c_f564_aaaa_aa3880bcb1f5 -->|defined in| e2af940f_f48c_60ab_e67f_c3708214d676 8fc73c0a_1c83_08e3_9486_c99948586794["run()"] 745f36f6_9a3c_f564_aaaa_aa3880bcb1f5 -->|method| 8fc73c0a_1c83_08e3_9486_c99948586794 c997df20_22da_3c7d_91cc_a980c6a6738b["scheduleTimeout()"] 745f36f6_9a3c_f564_aaaa_aa3880bcb1f5 -->|method| c997df20_22da_3c7d_91cc_a980c6a6738b b747d616_c157_971c_d76e_49712809b326["cancel()"] 745f36f6_9a3c_f564_aaaa_aa3880bcb1f5 -->|method| b747d616_c157_971c_d76e_49712809b326
Relationship Graph
Source Code
codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicheQuicChannel.java lines 1991–2064
private final class TimeoutHandler implements Runnable {
private ScheduledFuture<?> timeoutFuture;
@Override
public void run() {
QuicheQuicConnection conn = connection;
if (conn.isFreed()) {
return;
}
if (!freeIfClosed()) {
long connAddr = conn.address();
timeoutFuture = null;
// Notify quiche there was a timeout.
Quiche.quiche_conn_on_timeout(connAddr);
if (!freeIfClosed()) {
// We need to call connectionSend when a timeout was triggered.
// See https://docs.rs/quiche/0.6.0/quiche/struct.Connection.html#method.send.
if (connectionSend(conn) != SendResult.NONE) {
flushParent();
}
boolean closed = freeIfClosed();
if (!closed) {
// The connection is alive, reschedule.
scheduleTimeout();
}
}
}
}
// Schedule timeout.
// See https://docs.rs/quiche/0.6.0/quiche/#generating-outgoing-packets
void scheduleTimeout() {
QuicheQuicConnection conn = connection;
if (conn.isFreed()) {
cancel();
return;
}
if (conn.isClosed()) {
cancel();
unsafe().close(newPromise());
return;
}
long nanos = Quiche.quiche_conn_timeout_as_nanos(conn.address());
if (nanos < 0 || nanos == Long.MAX_VALUE) {
// No timeout needed.
cancel();
return;
}
if (timeoutFuture == null) {
timeoutFuture = eventLoop().schedule(this,
nanos, TimeUnit.NANOSECONDS);
} else {
long remaining = timeoutFuture.getDelay(TimeUnit.NANOSECONDS);
if (remaining <= 0) {
// This means the timer already elapsed. In this case just cancel the future and call run()
// directly. This will ensure we correctly call quiche_conn_on_timeout() etc.
cancel();
run();
} else if (remaining > nanos) {
// The new timeout is smaller then what was scheduled before. Let's cancel the old timeout
// and schedule a new one.
cancel();
timeoutFuture = eventLoop().schedule(this, nanos, TimeUnit.NANOSECONDS);
}
}
}
void cancel() {
if (timeoutFuture != null) {
timeoutFuture.cancel(false);
timeoutFuture = null;
}
}
}
Source
Frequently Asked Questions
What is the TimeoutHandler class?
TimeoutHandler is a class in the netty codebase, defined in codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicheQuicChannel.java.
Where is TimeoutHandler defined?
TimeoutHandler is defined in codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicheQuicChannel.java at line 1991.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free