public class RequestController extends IdleStateAwareChannelUpstreamHandler{ public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e)throws Exception{ //Shut down connection to client and roll everything back } public void channelConnected(ChannelHandlerContext ctx,ChannelStateEvent e)throws Exception{ if(!acquireConnectionSlot()){ //Maximum number of allowed server connections reached, // respond with 503 service unavailable // and shutdown connection } else { // set up the connection's request pipeline } } public void messageReceived(ChannelHandlerContext ctx,MessageEvent e)throws Exception{ if(isDone()){ return; } if (e.getMessage() instanceof HttpRequest){ handleHttpRequest((HttpRequest)e.getMessage()); } else if (e.getMessage() instanceof HttpChunk){ handleHttpChunk((HttpChunk)e.getMessage()); } } }