package chat.server.netty;
|
|
import chat.server.im.IMDispatcher;
|
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.socket.SocketChannel;
|
import io.netty.handler.codec.http.HttpObjectAggregator;
|
import io.netty.handler.codec.http.HttpRequestDecoder;
|
import io.netty.handler.codec.http.HttpResponseEncoder;
|
import io.netty.handler.stream.ChunkedWriteHandler;
|
|
public class NettyHttpChannelInitializer extends ChannelInitializer<SocketChannel> {
|
|
|
@Override
|
protected void initChannel(SocketChannel channel) throws Exception {
|
ChannelPipeline pipeline = channel.pipeline();
|
|
ChannelHandler decoder = new HttpRequestDecoder();
|
ChannelHandler encoder = new HttpResponseEncoder();
|
ChannelHandler chunkedWriteHandler = new ChunkedWriteHandler();
|
ChannelHandler aggregator = new HttpObjectAggregator(100 * 1024 * 1024);
|
ChannelHandler dispatcher = new IMDispatcher();
|
|
pipeline.addLast(decoder);
|
pipeline.addLast(encoder);
|
pipeline.addLast(chunkedWriteHandler);
|
pipeline.addLast(aggregator);
|
pipeline.addLast(dispatcher);
|
}
|
|
}
|