Class WriteTimeoutHandler

All Implemented Interfaces:
ChannelHandler, ChannelOutboundHandler

public class WriteTimeoutHandler extends ChannelOutboundHandlerAdapter
Raises a 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 extends ChannelInitializer<Channel> {
     public void initChannel(Channel channel) {
         channel.pipeline().addLast("writeTimeoutHandler", new WriteTimeoutHandler(30);
         channel.pipeline().addLast("myHandler", new MyHandler());
     }
 }

 // Handler should handle the WriteTimeoutException.
 public class MyHandler extends ChannelDuplexHandler {
     @Override
     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
             throws Exception {
         if (cause instanceof WriteTimeoutException) {
             // do something
         } else {
             super.exceptionCaught(ctx, cause);
         }
     }
 }

 ServerBootstrap bootstrap = ...;
 ...
 bootstrap.childHandler(new MyChannelInitializer());
 ...
 
See Also: