Skip to content

Instantly share code, notes, and snippets.

@ilguzin
Created June 5, 2013 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilguzin/5712536 to your computer and use it in GitHub Desktop.
Save ilguzin/5712536 to your computer and use it in GitHub Desktop.
The way to organize read timeout (read idle timeout) for socket connection with Netty. See. http://docs.jboss.org/netty/3.2/api/org/jboss/netty/handler/timeout/ReadTimeoutHandler.html
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));
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment