Class ReadTimeoutHandler

All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler, ChannelOutboundHandler

public class ReadTimeoutHandler extends IdleStateHandler
Raises a ReadTimeoutException when no data was read within a certain period of time.
 // The connection is closed when there is no inbound traffic
 // for 30 seconds.

 public class MyChannelInitializer extends ChannelInitializer<Channel> {
     public void initChannel(Channel channel) {
         channel.pipeline().addLast("readTimeoutHandler", new ReadTimeoutHandler(30));
         channel.pipeline().addLast("myHandler", new MyHandler());
     }
 }

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

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