IdleStateHandler appears to trigger continuously

B.L. Zeebub roger.varley at
Mon May 16 03:04:46 EDT 2011


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
	private Channel channel;

	private String host;

	private CommandExecutor executor;
	public NettyClientService(String host, CommandExecutor executor) { = host;
		this.executor = executor;
	public void run() {"Trying to connect to host " + host); 
		ClientBootstrap bootstrap = new ClientBootstrap(new
		// 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);
			}"Connected to " + host);

	public void shutdown() {"Channel Close has been called on ClientService.shutdown()");


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;

	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;	
    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 = now;
            e.getChannel().write(new Heartbeat());

View this message in context:
Sent from the Netty User Group mailing list archive at

More information about the netty-users mailing list