ReadTimeoutHandler वर्ग प्रयोग किया जाता है, तो टाइम-आउट से नियंत्रित किया जा सकता है।
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));
...
जब यह एक टाइम-आउट का कारण होगा, MyHandler.exceptionCaught (ChannelHandlerContext ctx, ExceptionEvent ई) ReadTimeoutException साथ कहा जाता है।
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
if (e.getCause() instanceof ReadTimeoutException) {
// NOP
}
ctx.getChannel().close();
}
स्रोत
2011-02-18 10:54:19