Search in sources :

Example 51 with ChannelPipeline

use of io.netty.channel.ChannelPipeline in project brave by openzipkin.

the class ITNettyHttpTracing method init.

@Override
protected void init() throws Exception {
    stop();
    bossGroup = new NioEventLoopGroup(1);
    workerGroup = new NioEventLoopGroup();
    ServerBootstrap b = new ServerBootstrap();
    b.option(ChannelOption.SO_BACKLOG, 1024);
    b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(final Channel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new HttpServerCodec());
            p.addLast(NettyHttpTracing.create(httpTracing).serverHandler());
            p.addLast(new TestHandler(httpTracing));
        }
    });
    Channel ch = b.bind(0).sync().channel();
    port = ((InetSocketAddress) ch.localAddress()).getPort();
}
Also used : NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) Channel(io.netty.channel.Channel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 52 with ChannelPipeline

use of io.netty.channel.ChannelPipeline in project brave by openzipkin.

the class NettyHttpServerBenchmarks method initServer.

@Override
protected int initServer() throws InterruptedException {
    bossGroup = new NioEventLoopGroup(1);
    workerGroup = new NioEventLoopGroup();
    ServerBootstrap b = new ServerBootstrap();
    b.option(ChannelOption.SO_BACKLOG, 1024);
    b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(final Channel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new HttpServerCodec());
            p.addLast(new TracingDispatchHandler());
            p.addLast(new HelloWorldHandler());
        }
    });
    Channel ch = b.bind(0).sync().channel();
    return ((InetSocketAddress) ch.localAddress()).getPort();
}
Also used : NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) InetSocketAddress(java.net.InetSocketAddress) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) Channel(io.netty.channel.Channel) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) RunnerException(org.openjdk.jmh.runner.RunnerException) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 53 with ChannelPipeline

use of io.netty.channel.ChannelPipeline in project BRFS by zhangnianli.

the class NettyChannelInitializer method initChannel.

@Override
protected void initChannel(SocketChannel ch) throws Exception {
    final ChannelPipeline pipeline = ch.pipeline();
    // server端发送的是httpResponse,所以要使用HttpResponseEncoder进行编码
    pipeline.addLast(new HttpResponseEncoder());
    // server端接收到的是httpRequest,所以要使用HttpRequestDecoder进行解码
    pipeline.addLast(new HttpRequestDecoder());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new ChunkedWriteHandler());
    contextHandlers.forEach(new Consumer<NettyHttpContextHandler>() {

        @Override
        public void accept(NettyHttpContextHandler handler) {
            pipeline.addLast(handler);
        }
    });
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 54 with ChannelPipeline

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

the class NonSecureDictionaryClient method startClient.

/**
 * start dictionary client
 *
 * @param address
 * @param port
 */
@Override
public void startClient(String secretKey, String address, int port, boolean encryptSecureServer) {
    LOGGER.audit("Starting client on " + address + " " + port);
    long start = System.currentTimeMillis();
    // Create an Event with 1 thread.
    workerGroup = new NioEventLoopGroup(1);
    Bootstrap clientBootstrap = new Bootstrap();
    clientBootstrap.group(workerGroup).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline pipeline = ch.pipeline();
            // Based on length provided at header, it collects all packets
            pipeline.addLast("LengthDecoder", new LengthFieldBasedFrameDecoder(1048576, 0, 2, 0, 2));
            pipeline.addLast("NonSecureDictionaryClientHandler", nonSecureDictionaryClientHandler);
        }
    });
    clientBootstrap.connect(new InetSocketAddress(address, port));
    LOGGER.info("Dictionary client Started, Total time spent : " + (System.currentTimeMillis() - start));
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) InetSocketAddress(java.net.InetSocketAddress) Bootstrap(io.netty.bootstrap.Bootstrap) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 55 with ChannelPipeline

use of io.netty.channel.ChannelPipeline in project java by wavefrontHQ.

the class PushAgent method startOpenTsdbListener.

protected void startOpenTsdbListener(final String strPort) {
    if (prefix != null && !prefix.isEmpty()) {
        preprocessors.forPort(strPort).forReportPoint().addTransformer(new ReportPointAddPrefixTransformer(prefix));
    }
    preprocessors.forPort(strPort).forReportPoint().addFilter(new ReportPointTimestampInRangeFilter(dataBackfillCutoffHours, dataPrefillCutoffHours));
    final int port = Integer.parseInt(strPort);
    final PostPushDataTimedTask[] flushTasks = getFlushTasks(strPort);
    ChannelInitializer initializer = new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            final ChannelHandler handler = new OpenTSDBPortUnificationHandler(new OpenTSDBDecoder("unknown", customSourceTags), new PointHandlerImpl(strPort, pushValidationLevel, pushBlockedSamples, flushTasks), preprocessors.forPort(strPort));
            ChannelPipeline pipeline = ch.pipeline();
            pipeline.addLast(new PlainTextOrHttpFrameDecoder(handler));
        }
    };
    startAsManagedThread(new TcpIngester(initializer, port).withChildChannelOptions(childChannelOptions), "listener-plaintext-opentsdb-" + port);
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) QueuingChannelHandler(com.wavefront.agent.histogram.QueuingChannelHandler) ChannelHandler(io.netty.channel.ChannelHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) ReportPointAddPrefixTransformer(com.wavefront.agent.preprocessor.ReportPointAddPrefixTransformer) ReportPointTimestampInRangeFilter(com.wavefront.agent.preprocessor.ReportPointTimestampInRangeFilter) ChannelInitializer(io.netty.channel.ChannelInitializer) OpenTSDBDecoder(com.wavefront.ingester.OpenTSDBDecoder) TcpIngester(com.wavefront.ingester.TcpIngester)

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