Class ReadTimeoutHandler

java.lang.Object
org.jboss.netty.channel.SimpleChannelUpstreamHandler
org.jboss.netty.handler.timeout.ReadTimeoutHandler
All Implemented Interfaces:
ChannelHandler, ChannelUpstreamHandler, LifeCycleAwareChannelHandler, ExternalResourceReleasable

Raises a ReadTimeoutException when no data was read within a certain period of time.
public class MyPipelineFactory implements ChannelPipelineFactory {

    private final Timer timer;
    private final ChannelHandler timeoutHandler;

    public MyPipelineFactory(Timer timer) {
        this.timer = timer;
        this.timeoutHandler = new ReadTimeoutHandler(timer, 30), // timer must be shared.
    }

    public ChannelPipeline getPipeline() {
        // An example configuration that implements 30-second read timeout:
        return Channels.pipeline(
            timeoutHandler,
            new MyHandler());
    }
}

ServerBootstrap bootstrap = ...;
Timer timer = new HashedWheelTimer();
...
bootstrap.setPipelineFactory(new MyPipelineFactory(timer));
...
The Timer which was specified when the ReadTimeoutHandler is created should be stopped manually by calling releaseExternalResources() or Timer.stop() when your application shuts down.
See Also: