Created
June 5, 2013 08:44
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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