Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.nettyhttpserver.server; import com.nettyhttpserver.server.util.HttpRequestHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.group.DefaultChannelGroup; import io.netty.handler.codec.http.HttpRequest; import io.netty.util.concurrent.ImmediateEventExecutor; import java.sql.SQLException; /** * * @author McKey */ class NettyServerHandler extends ChannelInboundHandlerAdapter { //private static Timer timer = new HashedWheelTimer(); private static DefaultChannelGroup allChannels = new DefaultChannelGroup("netty-receiver", ImmediateEventExecutor.INSTANCE); public NettyServerHandler() { } @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { allChannels.add(ctx.channel()); } @Override public void channelReadComplete(ChannelHandlerContext ctx) { ctx.flush(); } @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws SQLException { if (msg instanceof HttpRequest) HttpRequestHandler.handle(ctx, (HttpRequest) msg, allChannels); } }