Search in sources :

Example 11 with ChunkedWriteHandler

use of org.apache.flink.shaded.netty4.io.netty.handler.stream.ChunkedWriteHandler 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 12 with ChunkedWriteHandler

use of org.apache.flink.shaded.netty4.io.netty.handler.stream.ChunkedWriteHandler in project jackrabbit-oak by apache.

the class GetBlobResponseEncoderTest method shouldEncodeOneChunkResponse.

@Test
public void shouldEncodeOneChunkResponse() throws Exception {
    byte[] blobData = new byte[] { 1, 2, 3 };
    String blobId = "blobId";
    byte mask = createMask(1, 1);
    EmbeddedChannel channel = new EmbeddedChannel(new ChunkedWriteHandler(), new GetBlobResponseEncoder(3));
    channel.writeOutbound(new GetBlobResponse("clientId", blobId, new ByteArrayInputStream(blobData), blobData.length));
    ByteBuf buffer = (ByteBuf) channel.readOutbound();
    ByteBuf expected = createBlobChunkBuffer(Messages.HEADER_BLOB, 3L, blobId, blobData, mask);
    assertEquals(expected, buffer);
}
Also used : ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 13 with ChunkedWriteHandler

use of org.apache.flink.shaded.netty4.io.netty.handler.stream.ChunkedWriteHandler in project ratpack by ratpack.

the class DefaultRatpackServer method buildChannel.

protected Channel buildChannel(final ServerConfig serverConfig, final ChannelHandler handlerAdapter) throws InterruptedException {
    SslContext sslContext = serverConfig.getNettySslContext();
    this.useSsl = sslContext != null;
    ServerBootstrap serverBootstrap = new ServerBootstrap();
    serverConfig.getConnectTimeoutMillis().ifPresent(i -> {
        serverBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, i);
        serverBootstrap.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, i);
    });
    serverConfig.getMaxMessagesPerRead().ifPresent(i -> {
        FixedRecvByteBufAllocator allocator = new FixedRecvByteBufAllocator(i);
        serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, allocator);
        serverBootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, allocator);
    });
    serverConfig.getReceiveBufferSize().ifPresent(i -> {
        serverBootstrap.option(ChannelOption.SO_RCVBUF, i);
        serverBootstrap.childOption(ChannelOption.SO_RCVBUF, i);
    });
    serverConfig.getWriteSpinCount().ifPresent(i -> {
        serverBootstrap.option(ChannelOption.WRITE_SPIN_COUNT, i);
        serverBootstrap.childOption(ChannelOption.WRITE_SPIN_COUNT, i);
    });
    serverConfig.getConnectQueueSize().ifPresent(i -> serverBootstrap.option(ChannelOption.SO_BACKLOG, i));
    return serverBootstrap.group(execController.getEventLoopGroup()).channel(ChannelImplDetector.getServerSocketChannelImpl()).option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT).childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline pipeline = ch.pipeline();
            new ConnectionIdleTimeout(pipeline, serverConfig.getIdleTimeout());
            if (sslContext != null) {
                SSLEngine sslEngine = sslContext.newEngine(PooledByteBufAllocator.DEFAULT);
                pipeline.addLast("ssl", new SslHandler(sslEngine));
            }
            pipeline.addLast("decoder", new HttpRequestDecoder(serverConfig.getMaxInitialLineLength(), serverConfig.getMaxHeaderSize(), serverConfig.getMaxChunkSize(), false));
            pipeline.addLast("encoder", new HttpResponseEncoder());
            pipeline.addLast("deflater", new IgnorableHttpContentCompressor());
            pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
            pipeline.addLast("adapter", handlerAdapter);
            ch.config().setAutoRead(false);
        }
    }).bind(buildSocketAddress(serverConfig)).sync().channel();
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) SSLEngine(javax.net.ssl.SSLEngine) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) SslHandler(io.netty.handler.ssl.SslHandler) HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) ConnectionIdleTimeout(ratpack.http.internal.ConnectionIdleTimeout) SslContext(io.netty.handler.ssl.SslContext)

Example 14 with ChunkedWriteHandler

use of org.apache.flink.shaded.netty4.io.netty.handler.stream.ChunkedWriteHandler in project teiid by teiid.

the class SocketListener method configureChannelPipeline.

protected void configureChannelPipeline(ChannelPipeline pipeline, SSLConfiguration config, StorageManager storageManager) throws Exception {
    if (config != null) {
        SSLEngine engine = config.getServerSSLEngine();
        if (engine != null) {
            // $NON-NLS-1$
            pipeline.addLast("ssl", new SslHandler(engine));
        }
    }
    pipeline.addLast("decoder", new // $NON-NLS-1$
    ObjectDecoder(// $NON-NLS-1$
    maxMessageSize, maxLobSize, Thread.currentThread().getContextClassLoader(), storageManager));
    // $NON-NLS-1$
    pipeline.addLast("chunker", new ChunkedWriteHandler());
    // $NON-NLS-1$
    pipeline.addLast("encoder", new ObjectEncoder());
    // $NON-NLS-1$
    pipeline.addLast("handler", this.channelHandler);
}
Also used : ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) SSLEngine(javax.net.ssl.SSLEngine) SslHandler(io.netty.handler.ssl.SslHandler)

Example 15 with ChunkedWriteHandler

use of org.apache.flink.shaded.netty4.io.netty.handler.stream.ChunkedWriteHandler in project rpki-validator-3 by RIPE-NCC.

the class RtrServer method runNetty.

private void runNetty() throws InterruptedException {
    bossGroup = new NioEventLoopGroup();
    workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {

            @Override
            public void initChannel(SocketChannel ch) {
                ChannelTrafficShapingHandler traffic = new ChannelTrafficShapingHandler(0);
                RtrClientHandler rtrClientHandler = rtrClientHandlerProvider.get();
                rtrClientHandler.setTrafficShapingHandler(traffic);
                ch.pipeline().addLast(traffic, new PduCodec(), new ChunkedWriteHandler(), rtrClientHandler);
            }
        }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);
        log.info("Running RTR at port {}", port);
        ChannelFuture f = b.bind(port).sync();
        f.channel().closeFuture().sync();
    } finally {
        shutdownWorkers();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ChannelTrafficShapingHandler(io.netty.handler.traffic.ChannelTrafficShapingHandler) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) PduCodec(net.ripe.rpki.rtr.adapter.netty.PduCodec) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Aggregations

ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)46 ChannelPipeline (io.netty.channel.ChannelPipeline)24 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)16 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)11 SslHandler (io.netty.handler.ssl.SslHandler)10 HttpRequestDecoder (io.netty.handler.codec.http.HttpRequestDecoder)9 ByteBuf (io.netty.buffer.ByteBuf)8 SocketChannel (io.netty.channel.socket.SocketChannel)8 HttpResponseEncoder (io.netty.handler.codec.http.HttpResponseEncoder)8 LoggingHandler (io.netty.handler.logging.LoggingHandler)8 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)7 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)7 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)6 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)6 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)5 IOException (java.io.IOException)5 ChannelFuture (io.netty.channel.ChannelFuture)4 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)4 HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)4 HttpContentDecompressor (io.netty.handler.codec.http.HttpContentDecompressor)4