IdleStateHandler appears to trigger continuously

"이희승 (Trustin Lee)" trustin at gmail.com
Mon May 16 03:55:05 EDT 2011


I guess the default time unit is 'seconds'? :-)

Let me take a look when I have some time.  Busy at the moment..

On Mon 16 May 2011 04:48:04 PM KST, Norman Maurer wrote:
> Using a idle event every 3 milliseconds is prolly the cause. I can't
> believe you set it to 3ms for a good reason:
> 
> http://docs.jboss.org/netty/3.2/api/org/jboss/netty/handler/timeout/IdleStateHandler.html
> 
> Bye,
> Norman
> 
> 
> 2011/5/16 B.L. Zeebub<roger.varley at googlemail.com>:
>> Hi
>>
>> Have I misunderstood or mis-configured the use of the idleStateHandler? I
>> thought it should trigger only when there has been neither a read or a write
>> for the defined interval. What I'm seeing is the idle state event is being
>> fired every interval regardless of whether or not there is traffic going
>> through my pipeline. (I see the message "IdleStateHandler invoked: "
>> approximately every 3000 ms) I see this in 3.2.3 and 3.2.4.
>>
>> 1) My start-up class.
>>
>> public class NettyClientService implements Runnable {
>>
>>         private static final Logger logger = Logger
>>         .getLogger(NettyClientService.class.getName());
>>
>>         private Channel channel;
>>
>>         private String host;
>>
>>         private CommandExecutor executor;
>>
>>         public NettyClientService(String host, CommandExecutor executor) {
>>                 this.host = host;
>>                 this.executor = executor;
>>         }
>>
>>         public void run() {
>>
>>                 logger.info("Trying to connect to host " + host);
>>
>>                 ClientBootstrap bootstrap = new ClientBootstrap(new
>> OioClientSocketChannelFactory(Executors
>>                                 .newCachedThreadPool()));
>>
>>                 // Set up the event pipeline factory.
>>                 Timer timer = new HashedWheelTimer();
>>                 bootstrap.setPipelineFactory(new ClientPipelineFactory(executor,timer));
>>                 bootstrap.setOption("keepAlive", true);
>>
>>                 // Make a new connection.
>>                 ChannelFuture future = bootstrap.connect(new InetSocketAddress(
>>                                 host, 5956));
>>
>>                 channel = future.awaitUninterruptibly().getChannel();
>>                 if (!channel.isConnected()) {
>>
>>                         logger.error("Failed to connect to " + host);
>>                         executor.close();
>>                         bootstrap.releaseExternalResources();
>>                         return;
>>                         }
>>
>>                 logger.info("Connected to " + host);
>>         }
>>
>>         public void shutdown() {
>>                 logger.info("Channel Close has been called on ClientService.shutdown()");
>>                 channel.close();
>>         }
>>
>>
>> }
>>
>> 2) My PipelineFactory
>>
>> public class ClientPipelineFactory implements ChannelPipelineFactory {
>>
>>         private CommandExecutor executor;
>>         private Timer timer;
>>
>>         public ClientPipelineFactory(CommandExecutor executor, Timer timer) {
>>                 this.executor = executor;
>>                 this.timer = timer;
>>         }
>>
>>         @Override
>>         public ChannelPipeline getPipeline() throws Exception {
>>
>>                 ChannelPipeline pipeline = Channels.pipeline();
>>
>>                 pipeline.addLast("ObjectEncoder", new ObjectEncoder());
>>                 pipeline.addLast("ObjectDecoder", new ObjectDecoder());
>>                 pipeline.addLast("IdleStateHandler", new IdleStateHandler(timer,0,0,3));
>>                 pipeline.addLast("TimeOutHandler", new IdleStateTimeoutHandler());
>>                 pipeline.addLast("ChannelHandler",new ChannelExecutor(executor));
>>                 return pipeline;
>>         }
>>
>> }
>>
>> 3) My timeout handler class
>>
>> public class IdleStateTimeoutHandler extends IdleStateAwareChannelHandler {
>>
>>     long lastinvocation;
>>
>>         @Override
>>     public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) {
>>         if (e.getState() == IdleState.ALL_IDLE) {
>>                 //TODO remove
>>                 long now = System.currentTimeMillis();
>>                 System.out.println("IdleStateHandler invoked: " + (now -
>> lastinvocation));
>>                 lastinvocation = now;
>>             e.getChannel().write(new Heartbeat());
>>         }
>>     }
>> }
>>
>> --
>> View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/IdleStateHandler-appears-to-trigger-continuously-tp6367688p6367688.html
>> Sent from the Netty User Group mailing list archive at Nabble.com.
>> _______________________________________________
>> netty-users mailing list
>> netty-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/netty-users
>>
> 
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users


More information about the netty-users mailing list