use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project ambry by linkedin.
the class FrontendNettyChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
// If channel handler implementations are not annotated with @Sharable, Netty creates a new instance of every class
// in the pipeline for every connection.
// i.e. if there are a 1000 active connections there will be a 1000 NettyMessageProcessor instances.
ChannelPipeline pipeline = ch.pipeline();
// connection stats handler to track connection related metrics
pipeline.addLast("connectionStatsHandler", connectionStatsHandler);
// if SSL is enabled, add an SslHandler before the HTTP codec
if (sslFactory != null) {
InetSocketAddress peerAddress = ch.remoteAddress();
String peerHost = peerAddress.getHostName();
int peerPort = peerAddress.getPort();
SslHandler sslHandler = new SslHandler(sslFactory.createSSLEngine(peerHost, peerPort, SSLFactory.Mode.SERVER));
pipeline.addLast("sslHandler", sslHandler);
}
pipeline.addLast("codec", new HttpServerCodec(nettyConfig.nettyServerMaxInitialLineLength, nettyConfig.nettyServerMaxHeaderSize, nettyConfig.nettyServerMaxChunkSize)).addLast("healthCheckHandler", new HealthCheckHandler(restServerState, nettyMetrics)).addLast("publicAccessLogHandler", new PublicAccessLogHandler(publicAccessLogger, nettyMetrics)).addLast("idleStateHandler", new IdleStateHandler(0, 0, nettyConfig.nettyServerIdleTimeSeconds)).addLast("chunker", new ChunkedWriteHandler());
if (addedChannelHandlers != null) {
pipeline.addLast(addedChannelHandlers.toArray(new ChannelHandler[0]));
}
// custom processing class that interfaces with a RestRequestService.
pipeline.addLast("processor", new NettyMessageProcessor(nettyMetrics, nettyConfig, performanceConfig, requestHandler));
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project java by wavefrontHQ.
the class ProxyUtil method createInitializer.
/**
* Create a {@link ChannelInitializer} with multiple dynamically created
* {@link ChannelHandler} objects.
*
* @param channelHandlerSuppliers Suppliers of ChannelHandlers.
* @param port port number.
* @param idleTimeout idle timeout in seconds.
* @param sslContext SSL context.
* @return channel initializer
*/
static ChannelInitializer<SocketChannel> createInitializer(Iterable<Supplier<ChannelHandler>> channelHandlerSuppliers, int port, int idleTimeout, @Nullable SslContext sslContext) {
String strPort = String.valueOf(port);
ChannelHandler idleStateEventHandler = new IdleStateEventHandler(Metrics.newCounter(new TaggedMetricName("listeners", "connections.idle.closed", "port", strPort)));
ChannelHandler connectionTracker = new ConnectionTrackingHandler(Metrics.newCounter(new TaggedMetricName("listeners", "connections.accepted", "port", strPort)), Metrics.newCounter(new TaggedMetricName("listeners", "connections.active", "port", strPort)));
if (sslContext != null) {
logger.info("TLS enabled on port: " + port);
}
return new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
if (sslContext != null) {
pipeline.addLast(sslContext.newHandler(ch.alloc()));
}
pipeline.addFirst("idlehandler", new IdleStateHandler(idleTimeout, 0, 0));
pipeline.addLast("idlestateeventhandler", idleStateEventHandler);
pipeline.addLast("connectiontracker", connectionTracker);
channelHandlerSuppliers.forEach(x -> pipeline.addLast(x.get()));
}
};
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project BRFS by zhangnianli.
the class FileChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// pipeline.addLast(new JsonBytesDecoder(true));
// pipeline.addLast(new ReadObjectDecoder());
pipeline.addLast(new LineBasedFrameDecoder(1024 * 16));
pipeline.addLast(new ReadObjectStringDecoder());
pipeline.addLast(new ChunkedWriteHandler());
pipeline.addLast(fileReadHandler);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project BRFS by zhangnianli.
the class NettyChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// server端发送的是httpResponse,所以要使用HttpResponseEncoder进行编码
pipeline.addLast(new HttpResponseEncoder());
// server端接收到的是httpRequest,所以要使用HttpRequestDecoder进行解码
pipeline.addLast(new HttpRequestDecoder());
pipeline.addLast(new HttpObjectAggregator(maxHttpContentLength));
pipeline.addLast(new ChunkedWriteHandler());
if (authenticationHandler != null) {
pipeline.addLast(authenticationHandler);
}
pipeline.addLast(contextHandler);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project BRFS by zhangnianli.
the class MessageChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new IdleStateHandler(DEFAULT_READ_IDLE_TIMEOUT_SECONDS, 0, 0));
pipeline.addLast(new MessageResponseEncoder());
pipeline.addLast(new MessageProtocolDecoder());
pipeline.addLast(messageDispatcher);
}
Aggregations