Si se utiliza la clase ReadTimeoutHandler, el tiempo de espera puede ser controlado.
La siguiente es una cotización de Javadoc.
public class MyPipelineFactory implements ChannelPipelineFactory {
private final Timer timer;
public MyPipelineFactory(Timer timer) {
this.timer = timer;
}
public ChannelPipeline getPipeline() {
// An example configuration that implements 30-second read timeout:
return Channels.pipeline(
new ReadTimeoutHandler(timer, 30), // timer must be shared.
new MyHandler());
}
}
ServerBootstrap bootstrap = ...;
Timer timer = new HashedWheelTimer();
...
bootstrap.setPipelineFactory(new MyPipelineFactory(timer));
...
Cuando se causará un tiempo de espera, MyHandler.exceptionCaught (ChannelHandlerContext CTX, ExceptionEvent e) se llama con ReadTimeoutException.
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
if (e.getCause() instanceof ReadTimeoutException) {
// NOP
}
ctx.getChannel().close();
}