WriteTimeoutTask Class — netty Architecture
Architecture documentation for the WriteTimeoutTask class in WriteTimeoutHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 31b01ed4_f756_395a_3500_81e356092658["WriteTimeoutTask"] 2b552d7b_2e84_2905_efd6_2d637843dd63["WriteTimeoutHandler.java"] 31b01ed4_f756_395a_3500_81e356092658 -->|defined in| 2b552d7b_2e84_2905_efd6_2d637843dd63 8ddddbce_a36c_8313_a972_17e32c804b11["WriteTimeoutTask()"] 31b01ed4_f756_395a_3500_81e356092658 -->|method| 8ddddbce_a36c_8313_a972_17e32c804b11 c648ed62_c9a2_bda9_3781_a21c17f43d8a["run()"] 31b01ed4_f756_395a_3500_81e356092658 -->|method| c648ed62_c9a2_bda9_3781_a21c17f43d8a 59da182b_72ed_d838_5542_f6d99ed8cefe["operationComplete()"] 31b01ed4_f756_395a_3500_81e356092658 -->|method| 59da182b_72ed_d838_5542_f6d99ed8cefe
Relationship Graph
Source Code
handler/src/main/java/io/netty/handler/timeout/WriteTimeoutHandler.java lines 186–235
private final class WriteTimeoutTask implements Runnable, ChannelFutureListener {
private final ChannelHandlerContext ctx;
private final ChannelPromise promise;
// WriteTimeoutTask is also a node of a doubly-linked list
WriteTimeoutTask prev;
WriteTimeoutTask next;
Future<?> scheduledFuture;
WriteTimeoutTask(ChannelHandlerContext ctx, ChannelPromise promise) {
this.ctx = ctx;
this.promise = promise;
}
@Override
public void run() {
// Was not written yet so issue a write timeout
// The promise itself will be failed with a ClosedChannelException once the close() was issued
// See https://github.com/netty/netty/issues/2159
if (!promise.isDone()) {
try {
writeTimedOut(ctx);
} catch (Throwable t) {
ctx.fireExceptionCaught(t);
}
}
removeWriteTimeoutTask(this);
}
@Override
public void operationComplete(ChannelFuture future) throws Exception {
// scheduledFuture has already be set when reaching here
scheduledFuture.cancel(false);
// Check if its safe to modify the "doubly-linked-list" that we maintain. If its not we will schedule the
// modification so its picked up by the executor..
if (ctx.executor().inEventLoop()) {
removeWriteTimeoutTask(this);
} else {
// So let's just pass outself to the executor which will then take care of remove this task
// from the doubly-linked list. Schedule ourself is fine as the promise itself is done.
//
// This fixes https://github.com/netty/netty/issues/11053
assert promise.isDone();
ctx.executor().execute(this);
}
}
}
Source
Frequently Asked Questions
What is the WriteTimeoutTask class?
WriteTimeoutTask is a class in the netty codebase, defined in handler/src/main/java/io/netty/handler/timeout/WriteTimeoutHandler.java.
Where is WriteTimeoutTask defined?
WriteTimeoutTask is defined in handler/src/main/java/io/netty/handler/timeout/WriteTimeoutHandler.java at line 186.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free