IdleStateHandler

Michael Matthews mikematthews at agtek.com
Thu Jan 14 12:02:41 EST 2010


I am trying to figure out what the correct way to use the 
IdleStateHandler is. I want my
client connections to timeout so I had my handler extend 
IdleStateHandler rather than
SimpleChannelUpstreamHandler. However, I found the connections were 
timing out
even if they were being used. It looks like I have to forward calls to 
messageReceived to
the IdleStateHandler class in order for the timeout to be reset.

Now I'm wondering if I should have added the IdleStateHandler separately 
to the
pipeline and add my handler afterwards modifying it to extend 
SimpleChannelUpstreamHandler.

Currently my pipeline factory looks like:
-------------------
        ChannelPipeline p = Channels.pipeline();
       
        p.addLast("frameDecoder", new 
LengthFieldBasedFrameDecoder(1048576, 0, 4, 0, 4));
        p.addLast("protobufDecoder", new 
ProtobufDecoder(Requests.Request.getDefaultInstance()));

        p.addLast("frameEncoder", new LengthFieldPrepender(4));
        p.addLast("protobufEncoder", new ProtobufEncoder());

        p.addLast("pipelineExecutor", new ExecutionHandler(executor));
        p.addLast("handler", new CommHandler(server));
        return p;
-----------------
Where CommHandler is my sub-class of IdleStateHandler

I'm wondering if I should change it to something like:
-----------------------
        ChannelPipeline p = Channels.pipeline();
       
        p.addLast("frameDecoder", new 
LengthFieldBasedFrameDecoder(1048576, 0, 4, 0, 4));
        p.addLast("protobufDecoder", new 
ProtobufDecoder(Requests.Request.getDefaultInstance()));

        p.addLast("frameEncoder", new LengthFieldPrepender(4));
        p.addLast("protobufEncoder", new ProtobufEncoder());

        p.addLast("pipelineExecutor", new ExecutionHandler(executor));
        p.addLast("handler", new IdleStateHandler(....));
        p.addLast("handler", new CommHandler(server));
        return p;
----------------------

Any thoughts? Does any of that make sense? I've only had half a cup of 
coffee
this morning so the brain is barely functioning.


Michael Matthews



More information about the netty-users mailing list