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 extendsChannelDuplexHandler{@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 io. Implements io. ChannelHandler was removed from the actual context and it doesn't handle events
anymore.
|
| private void | |
| private void | |
| public void | write(ChannelHandlerContext
the ctx, Object ChannelHandlerContext for which the write operation is madethe message to write msg, ChannelPromise the promise)ChannelPromise to notify once the operation completesOverrides io. Implements io. ChannelHandlerContext#write(Object, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
|
| 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 io. Implements 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 ChannelPromise promise) | |
| write | back to summary |
|---|---|
| public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception Overrides io. Implements io. Doc from io. Calls
| |
| 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 | |
| pack-priv WriteTimeoutHandler. | |
| pack-priv WriteTimeoutHandler. | |
| private final ChannelPromise | |
| pack-priv Future |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | operationComplete(ChannelFuture
the source future)Future which called this callbackImplements io. Future has been completed.
|
| public void |
| ctx | back to summary |
|---|---|
| private final ChannelHandlerContext ctx | |
| next | back to summary |
|---|---|
| pack-priv WriteTimeoutHandler. | |
| prev | back to summary |
|---|---|
| pack-priv WriteTimeoutHandler. | |
| promise | back to summary |
|---|---|
| private final ChannelPromise promise | |
| scheduledFuture | back to summary |
|---|---|
| pack-priv Future<?> scheduledFuture | |
| WriteTimeoutTask | back to summary |
|---|---|
| pack-priv WriteTimeoutTask(ChannelHandlerContext ctx, ChannelPromise promise) | |
| operationComplete | back to summary |
|---|---|
| public void operationComplete(ChannelFuture 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.
| |