io.lightflame.bootstrap.PipelineFactory Maven / Gradle / Ivy
The newest version!
package io.lightflame.bootstrap;
import io.lightflame.http.HttpServerHandler;
import io.lightflame.websocket.WsFrameHandler;
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.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler;
import io.netty.handler.ssl.SslContext;
/**
* PipelineFactory
*/
public class PipelineFactory extends ChannelInitializer{
private final SslContext sslCtx;
private int port;
public PipelineFactory(int port, SslContext ssl) {
this.sslCtx = ssl;
this.port = port;
}
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc()));
}
// p.addLast(new HttpServerCodec());
p.addLast(new HttpServerCodec());
p.addLast(new HttpObjectAggregator(65536));
p.addLast(new WebSocketServerCompressionHandler());
p.addLast(new WebSocketServerProtocolHandler("/ws", null, true));
p.addLast(new WsFrameHandler(this.port));
p.addLast(new HttpServerHandler());
}
}