@Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        if (msg instanceof HttpRequest) {                                    
            final HttpRequest req = (HttpRequest) msg;
            final String uri = req.getUri();
            final String src_ip = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().getHostAddress();
            final String fullUri = req.headers().get("Host") + uri;
            QueryStringDecoder decoder = new QueryStringDecoder(uri);
            String url = decoder.path();
            parameters = decoder.parameters();
            
            if (is100ContinueExpected(req)) {
                ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
            }
                        
            redirect = null;
            final FullHttpResponse response;
            final String urlInLower = url.toLowerCase();
            if (urlInLower.matches("/hello")){
                ctx.executor().parent().terminationFuture().await(AWAIT_DURATION_IN_SECONDS, TimeUnit.SECONDS);
                response = createResponse("Hello World", OK);                
            } else if (urlInLower.equals("/redirect")){                
                if (parameters.containsKey("url")) {
                    redirect = parameters.get("url").get(0);
                    response = performRedirect(redirect); 
                } else {
                    response = createErrorResponse("Bad request", BAD_REQUEST);
                }
            } else if (urlInLower.equals("/status")){
                response = performStatus();
            } else {
                response = createErrorResponse("404 Not found", NOT_FOUND);
            }
            
            ChannelFuture writeFuture;                   
            writeFuture = writeResponse(ctx, req, response);            
            writeFuture.addListener(new ChannelFutureListener() {
                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    int received_bytes = (int) trafficCounter.cumulativeReadBytes();
                    int sent_bytes = (int) trafficCounter.cumulativeWrittenBytes();
                    int totalSpeed = (int) (trafficCounter.lastReadThroughput() + trafficCounter.lastWriteThroughput());
                    if (0 == totalSpeed){
                        totalSpeed = sent_bytes + received_bytes; 
                    }
                    trafficCounter.resetCumulativeTime();
                    StatDAO stat = new StatDAO();
                    stat.addLogRecord(src_ip, fullUri, sent_bytes, received_bytes, totalSpeed, redirect);                    
                }              
            });
        } 
    }