Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would suggest to add the <a href="http://netty.io/3.6/api/org/jboss/netty/handler/timeout/IdleStateHandler.html" rel="nofollow">IdleStateHandler</a> and then add your custom implementation of <a href="http://netty.io/3.6/api/org/jboss/netty/handler/timeout/IdleStateAwareChannelHandler.html" rel="nofollow">IdleStateAwareUpstreamHandler</a> which can react on the idle state. This works out very well for me on many different projects.</p> <p>The javadocs list the following example, that you could use as the base of your implementation:</p> <pre class="lang-java prettyprint-override"><code>public class MyPipelineFactory implements ChannelPipelineFactory { private final Timer timer; private final ChannelHandler idleStateHandler; public MyPipelineFactory(Timer timer) { this.timer = timer; this.idleStateHandler = new IdleStateHandler(timer, 60, 30, 0); // timer must be shared. } public ChannelPipeline getPipeline() { return Channels.pipeline( idleStateHandler, new MyHandler()); } } // Handler should handle the IdleStateEvent triggered by IdleStateHandler. public class MyHandler extends IdleStateAwareChannelHandler { @Override public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) { if (e.getState() == IdleState.READER_IDLE) { e.getChannel().close(); } else if (e.getState() == IdleState.WRITER_IDLE) { e.getChannel().write(new PingMessage()); } } } ServerBootstrap bootstrap = ...; Timer timer = new HashedWheelTimer(); ... bootstrap.setPipelineFactory(new MyPipelineFactory(timer)); ... </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload