Search in sources :

Example 86 with ChannelPipeline

use of io.netty.channel.ChannelPipeline in project x-pipe by ctripcorp.

the class NettyKeyedPoolClientFactory method doStart.

@Override
protected void doStart() throws Exception {
    eventLoopGroup = new NioEventLoopGroup(eventLoopThreads, XpipeThreadFactory.create("NettyKeyedPoolClientFactory"));
    b.group(eventLoopGroup).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true).handler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new LoggingHandler());
            p.addLast(new NettySimpleMessageHandler());
            p.addLast(new NettyClientHandler());
        }
    });
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) LoggingHandler(io.netty.handler.logging.LoggingHandler) NettySimpleMessageHandler(com.ctrip.xpipe.netty.NettySimpleMessageHandler) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 87 with ChannelPipeline

use of io.netty.channel.ChannelPipeline in project x-pipe by ctripcorp.

the class PsyncLatencyTest method startGetLatency.

private void startGetLatency() {
    EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
    Bootstrap b = new Bootstrap();
    b.group(eventLoopGroup).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true).handler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new LoggingHandler(LogLevel.DEBUG));
            p.addLast(new NettySimpleMessageHandler());
            p.addLast(new ReceiveMessageHandler(runId, offset));
        }
    });
    b.connect(dest);
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) LoggingHandler(io.netty.handler.logging.LoggingHandler) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Bootstrap(io.netty.bootstrap.Bootstrap) NettySimpleMessageHandler(com.ctrip.xpipe.netty.NettySimpleMessageHandler) ReceiveMessageHandler(com.ctrip.xpipe.redis.keeper.simple.latency.netty.ReceiveMessageHandler) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 88 with ChannelPipeline

use of io.netty.channel.ChannelPipeline in project x-pipe by ctripcorp.

the class DefaultRedisKeeperServer method startServer.

protected void startServer() throws InterruptedException {
    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new LoggingHandler(LogLevel.DEBUG));
            p.addLast(new NettySimpleMessageHandler());
            p.addLast(new NettyMasterHandler(DefaultRedisKeeperServer.this, new CommandHandlerManager(), keeperConfig.getTrafficReportIntervalMillis()));
        }
    });
    serverSocketChannel = (ServerSocketChannel) b.bind(currentKeeperMeta.getPort()).sync().channel();
}
Also used : NettyMasterHandler(com.ctrip.xpipe.redis.keeper.netty.NettyMasterHandler) SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ServerSocketChannel(io.netty.channel.socket.ServerSocketChannel) LoggingHandler(io.netty.handler.logging.LoggingHandler) NettySimpleMessageHandler(com.ctrip.xpipe.netty.NettySimpleMessageHandler) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) XpipeRuntimeException(com.ctrip.xpipe.exception.XpipeRuntimeException) RedisSlavePromotionException(com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException) IOException(java.io.IOException) ChannelPipeline(io.netty.channel.ChannelPipeline) CommandHandlerManager(com.ctrip.xpipe.redis.keeper.handler.CommandHandlerManager)

Example 89 with ChannelPipeline

use of io.netty.channel.ChannelPipeline in project drill by apache.

the class AbstractRemoteConnection method addSecurityHandlers.

/**
 * Helps to add all the required security handler's after negotiation for encryption is completed.
 * <p>Handler's before encryption is negotiated are:</p>
 * <ul>
 *    <li>  PROTOCOL_DECODER {@link ProtobufLengthDecoder} </li>
 *    <li>  MESSAGE_DECODER {@link RpcDecoder}  </li>
 *    <li>  PROTOCOL_ENCODER {@link RpcEncoder} </li>
 *    <li>  HANDSHAKE_HANDLER {@link org.apache.drill.exec.rpc.BasicClient.ClientHandshakeHandler} OR
 *                            {@link org.apache.drill.exec.rpc.BasicServer.ServerHandshakeHandler}  </li>
 *    <li>  optional - IDLE_STATE_HANDLER {@link org.apache.drill.exec.rpc.BasicClient.IdlePingHandler} OR
 *                   - TIMEOUT_HANDLER {@link org.apache.drill.exec.rpc.BasicServer.LoggingReadTimeoutHandler}  </li>
 *    <li>  MESSAGE_HANDLER {@link org.apache.drill.exec.rpc.RpcBus.InboundHandler} </li>
 *    <li>  EXCEPTION_HANDLER {@link RpcExceptionHandler} </li>
 * </ul>
 * <p>Handler's after encryption is negotiated are:</p>
 * <ul>
 *    <li>  LENGTH_DECODER_HANDLER {@link LengthFieldBasedFrameDecoder}
 *    <li>  SASL_DECRYPTION_HANDLER {@link SaslDecryptionHandler}
 *    <li>  PROTOCOL_DECODER {@link ProtobufLengthDecoder}
 *    <li>  MESSAGE_DECODER {@link RpcDecoder}
 *    <li>  SASL_ENCRYPTION_HANDLER {@link SaslEncryptionHandler}
 *    <li>  CHUNK_CREATION_HANDLER {@link ChunkCreationHandler}
 *    <li>  PROTOCOL_ENCODER {@link RpcEncoder}
 *    <li>  HANDSHAKE_HANDLER {@link org.apache.drill.exec.rpc.BasicClient.ClientHandshakeHandler} OR
 *                            {@link org.apache.drill.exec.rpc.BasicServer.ServerHandshakeHandler}
 *    <li>  optional - IDLE_STATE_HANDLER {@link org.apache.drill.exec.rpc.BasicClient.IdlePingHandler} OR
 *                   - TIMEOUT_HANDLER {@link org.apache.drill.exec.rpc.BasicServer.LoggingReadTimeoutHandler}
 *    <li>  MESSAGE_HANDLER {@link org.apache.drill.exec.rpc.RpcBus.InboundHandler}
 *    <li>  EXCEPTION_HANDLER {@link RpcExceptionHandler}
 * </ul>
 * <p>
 *  If encryption is enabled ChunkCreationHandler is always added to divide the Rpc message into chunks of
 *  negotiated {@link EncryptionContextImpl#wrapSizeLimit} bytes. This helps to make a generic encryption handler.
 * </p>
 */
@Override
public void addSecurityHandlers() {
    final ChannelPipeline channelPipeline = getChannel().pipeline();
    if (channelPipeline.names().contains(RpcConstants.SSL_HANDLER)) {
        channelPipeline.addAfter(RpcConstants.SSL_HANDLER, RpcConstants.SASL_DECRYPTION_HANDLER, new SaslDecryptionHandler(saslCodec, getMaxWrappedSize(), OutOfMemoryHandler.DEFAULT_INSTANCE));
        channelPipeline.addAfter(RpcConstants.SSL_HANDLER, RpcConstants.LENGTH_DECODER_HANDLER, new LengthFieldBasedFrameDecoder(ByteOrder.BIG_ENDIAN, Integer.MAX_VALUE, RpcConstants.LENGTH_FIELD_OFFSET, RpcConstants.LENGTH_FIELD_LENGTH, RpcConstants.LENGTH_ADJUSTMENT, RpcConstants.INITIAL_BYTES_TO_STRIP, true));
    } else {
        channelPipeline.addFirst(RpcConstants.SASL_DECRYPTION_HANDLER, new SaslDecryptionHandler(saslCodec, getMaxWrappedSize(), OutOfMemoryHandler.DEFAULT_INSTANCE));
        channelPipeline.addFirst(RpcConstants.LENGTH_DECODER_HANDLER, new LengthFieldBasedFrameDecoder(ByteOrder.BIG_ENDIAN, Integer.MAX_VALUE, RpcConstants.LENGTH_FIELD_OFFSET, RpcConstants.LENGTH_FIELD_LENGTH, RpcConstants.LENGTH_ADJUSTMENT, RpcConstants.INITIAL_BYTES_TO_STRIP, true));
    }
    channelPipeline.addAfter(RpcConstants.MESSAGE_DECODER, RpcConstants.SASL_ENCRYPTION_HANDLER, new SaslEncryptionHandler(saslCodec, getWrapSizeLimit(), OutOfMemoryHandler.DEFAULT_INSTANCE));
    channelPipeline.addAfter(RpcConstants.SASL_ENCRYPTION_HANDLER, RpcConstants.CHUNK_CREATION_HANDLER, new ChunkCreationHandler(getWrapSizeLimit()));
}
Also used : LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 90 with ChannelPipeline

use of io.netty.channel.ChannelPipeline in project component-runtime by Talend.

the class ProxyInitializer method initChannel.

@Override
protected void initChannel(final SocketChannel channel) {
    final ChannelPipeline pipeline = channel.pipeline();
    pipeline.addLast("logging", new LoggingHandler(LogLevel.valueOf(api.getLogLevel()))).addLast("http-decoder", new HttpRequestDecoder()).addLast("http-encoder", new HttpResponseEncoder()).addLast("http-keepalive", new HttpServerKeepAliveHandler()).addLast("aggregator", new HttpObjectAggregator(Integer.MAX_VALUE)).addLast("chunked-writer", new ChunkedWriteHandler()).addLast("talend-junit-api-server", newHandler());
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) LoggingHandler(io.netty.handler.logging.LoggingHandler) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) HttpServerKeepAliveHandler(io.netty.handler.codec.http.HttpServerKeepAliveHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

ChannelPipeline (io.netty.channel.ChannelPipeline)331 SocketChannel (io.netty.channel.socket.SocketChannel)95 Channel (io.netty.channel.Channel)86 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)84 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)77 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)74 Bootstrap (io.netty.bootstrap.Bootstrap)72 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)62 ChannelFuture (io.netty.channel.ChannelFuture)61 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)57 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)57 EventLoopGroup (io.netty.channel.EventLoopGroup)49 InetSocketAddress (java.net.InetSocketAddress)43 SslHandler (io.netty.handler.ssl.SslHandler)42 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)37 IOException (java.io.IOException)35 LoggingHandler (io.netty.handler.logging.LoggingHandler)33 StringDecoder (io.netty.handler.codec.string.StringDecoder)32 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)30 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)29