WriteTimeoutException when a write operation cannot finish in a certain period of time.
// The connection is closed when a write operation cannot finish in 30 seconds. public class MyChannelInitializer extendsChannelInitializer<Channel> { public void initChannel(Channelchannel) { channel.pipeline().addLast("writeTimeoutHandler", newWriteTimeoutHandler(30); channel.pipeline().addLast("myHandler", new MyHandler()); } } // Handler should handle theWriteTimeoutException. public class MyHandler implementsChannelHandler{@Overridepublic void exceptionCaught(ChannelHandlerContextctx,Throwablecause) throwsException{ if (cause instanceofWriteTimeoutException) { // do something } else { super.exceptionCaught(ctx, cause); } } }ServerBootstrapbootstrap = ...; ... bootstrap.childHandler(new MyChannelInitializer()); ...
ReadTimeoutHandler, IdleStateHandler
| Modifier and Type | Class and Description |
|---|---|
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private WriteTimeoutHandler. | lastTask
A doubly-linked list to track all WriteTimeoutTasks |
| private static final long | |
| private final long |
| Access | Constructor and Description |
|---|---|
| public | |
| public | WriteTimeoutHandler(long
write timeout timeout, TimeUnit the unit)TimeUnit of timeoutCreates a new instance. |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public void | handlerRemoved(ChannelHandlerContext ctx)
Overrides default io. ChannelHandler was removed from the actual context and it doesn't handle events
anymore.
|
| private void | |
| private void | |
| public Future | write(ChannelHandlerContext
the ctx, Object ChannelHandlerContext for which the write operation is madethe message to write msg)Overrides default io. |
| protected void |
| closed | back to summary |
|---|---|
| private boolean closed | |
| lastTask | back to summary |
|---|---|
| private WriteTimeoutHandler. A doubly-linked list to track all WriteTimeoutTasks | |
| MIN_TIMEOUT_NANOS | back to summary |
|---|---|
| private static final long MIN_TIMEOUT_NANOS | |
| timeoutNanos | back to summary |
|---|---|
| private final long timeoutNanos | |
| WriteTimeoutHandler | back to summary |
|---|---|
| public WriteTimeoutHandler(int timeoutSeconds) Creates a new instance.
| |
| WriteTimeoutHandler | back to summary |
|---|---|
| public WriteTimeoutHandler(long timeout, TimeUnit unit) Creates a new instance. | |
| addWriteTimeoutTask | back to summary |
|---|---|
| private void addWriteTimeoutTask(WriteTimeoutHandler. | |
| handlerRemoved | back to summary |
|---|---|
| public void handlerRemoved(ChannelHandlerContext ctx) throws Exception Overrides default io. Doc from io. Gets called after the
| |
| removeWriteTimeoutTask | back to summary |
|---|---|
| private void removeWriteTimeoutTask(WriteTimeoutHandler. | |
| scheduleTimeout | back to summary |
|---|---|
| private void scheduleTimeout(final ChannelHandlerContext ctx, final Future<Void> future) | |
| write | back to summary |
|---|---|
| public Future Overrides default io. Doc from io. Called once a write operation is made. The write operation will write the messages through the
| |
| writeTimedOut | back to summary |
|---|---|
| protected void writeTimedOut(ChannelHandlerContext ctx) throws Exception Is called when a write timeout was detected | |
| Modifier and Type | Field and Description |
|---|---|
| private final ChannelHandlerContext | |
| private final Future | |
| pack-priv WriteTimeoutHandler. | |
| pack-priv WriteTimeoutHandler. | |
| pack-priv Future |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | operationComplete(Future<? extends Void>
the source future)Future which called this callbackImplements io. Future has been completed.
|
| public void |
| ctx | back to summary |
|---|---|
| private final ChannelHandlerContext ctx | |
| future | back to summary |
|---|---|
| private final Future<Void> future | |
| next | back to summary |
|---|---|
| pack-priv WriteTimeoutHandler. | |
| prev | back to summary |
|---|---|
| pack-priv WriteTimeoutHandler. | |
| scheduledFuture | back to summary |
|---|---|
| pack-priv Future<?> scheduledFuture | |
| WriteTimeoutTask | back to summary |
|---|---|
| pack-priv WriteTimeoutTask(ChannelHandlerContext ctx, Future<Void> future) | |
| operationComplete | back to summary |
|---|---|
| public void operationComplete(Future<? extends Void> future) throws Exception Implements io. Doc from io. Invoked when the operation associated with the | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation.
| |