Search in sources :

Example 11 with Http2ConnectionHandler

use of io.netty.handler.codec.http2.Http2ConnectionHandler in project netty by netty.

the class NoPriorityByteDistributionBenchmark method setupTrial.

@Setup(Level.Trial)
public void setupTrial() throws Exception {
    connection = new DefaultHttp2Connection(false);
    dataRefresherKey = connection.newKey();
    // Create the flow controller
    switch(algorithm) {
        case WFQ:
            distributor = new WeightedFairQueueByteDistributor(connection, 0);
            break;
        case UNIFORM:
            distributor = new UniformStreamByteDistributor(connection);
            break;
    }
    controller = new DefaultHttp2RemoteFlowController(connection, new ByteCounter(distributor));
    connection.remote().flowController(controller);
    Http2ConnectionHandler handler = new Http2ConnectionHandlerBuilder().encoderEnforceMaxConcurrentStreams(false).validateHeaders(false).frameListener(new Http2FrameAdapter()).connection(connection).build();
    ctx = new EmbeddedChannelWriteReleaseHandlerContext(PooledByteBufAllocator.DEFAULT, handler) {

        @Override
        protected void handleException(Throwable t) {
            handleUnexpectedException(t);
        }
    };
    handler.handlerAdded(ctx);
    handler.channelActive(ctx);
    // Create the streams, each initialized with MAX_INT bytes.
    for (int i = 0; i < numStreams; ++i) {
        Http2Stream stream = connection.local().createStream(toStreamId(i), false);
        addData(stream, Integer.MAX_VALUE);
        stream.setProperty(dataRefresherKey, new DataRefresher(stream));
    }
}
Also used : DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Http2FrameAdapter(io.netty.handler.codec.http2.Http2FrameAdapter) Http2ConnectionHandler(io.netty.handler.codec.http2.Http2ConnectionHandler) WeightedFairQueueByteDistributor(io.netty.handler.codec.http2.WeightedFairQueueByteDistributor) Http2ConnectionHandlerBuilder(io.netty.handler.codec.http2.Http2ConnectionHandlerBuilder) EmbeddedChannelWriteReleaseHandlerContext(io.netty.microbench.channel.EmbeddedChannelWriteReleaseHandlerContext) DefaultHttp2RemoteFlowController(io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController) Http2Stream(io.netty.handler.codec.http2.Http2Stream) UniformStreamByteDistributor(io.netty.handler.codec.http2.UniformStreamByteDistributor) Setup(org.openjdk.jmh.annotations.Setup)

Example 12 with Http2ConnectionHandler

use of io.netty.handler.codec.http2.Http2ConnectionHandler in project rest.li by linkedin.

the class Http2ChannelInitializer method configureClearText.

/**
 * Configure the pipeline for HTTP/2 clear text.
 */
private void configureClearText(NioSocketChannel channel) {
    final HttpClientCodec sourceCodec = new HttpClientCodec(_maxInitialLineLength, _maxHeaderSize, _maxChunkSize);
    UnsupportedHandler unsupportedHandler = new UnsupportedHandler();
    Http2MultiplexHandler multiplexHandler = new Http2MultiplexHandler(unsupportedHandler, unsupportedHandler);
    Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec((Http2ConnectionHandler) Http2FrameCodecBuilder.forClient().initialSettings(createHttp2Settings()).build(), multiplexHandler);
    final ChannelPromise upgradePromise = channel.newPromise();
    channel.attr(NettyChannelAttributes.INITIALIZATION_FUTURE).set(upgradePromise);
    channel.pipeline().addLast(sourceCodec);
    channel.pipeline().addLast(new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, _maxContentLength));
    channel.pipeline().addLast(new Http2ProtocolUpgradeHandler(upgradePromise));
}
Also used : UnsupportedHandler(com.linkedin.r2.netty.handler.http2.UnsupportedHandler) Http2MultiplexHandler(io.netty.handler.codec.http2.Http2MultiplexHandler) Http2ProtocolUpgradeHandler(com.linkedin.r2.netty.handler.http2.Http2ProtocolUpgradeHandler) Http2ClientUpgradeCodec(io.netty.handler.codec.http2.Http2ClientUpgradeCodec) ChannelPromise(io.netty.channel.ChannelPromise) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) HttpClientUpgradeHandler(io.netty.handler.codec.http.HttpClientUpgradeHandler)

Aggregations

Channel (io.netty.channel.Channel)6 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)5 Http2ConnectionHandler (io.netty.handler.codec.http2.Http2ConnectionHandler)5 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)4 ChannelPipeline (io.netty.channel.ChannelPipeline)4 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)4 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)4 DefaultHttp2Connection (io.netty.handler.codec.http2.DefaultHttp2Connection)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Bootstrap (io.netty.bootstrap.Bootstrap)3 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)3 DefaultHttp2ConnectionDecoder (io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder)3 DefaultHttp2ConnectionEncoder (io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder)3 DefaultHttp2FrameReader (io.netty.handler.codec.http2.DefaultHttp2FrameReader)3 DefaultHttp2FrameWriter (io.netty.handler.codec.http2.DefaultHttp2FrameWriter)3 Http2Connection (io.netty.handler.codec.http2.Http2Connection)3 Http2ConnectionHandlerBuilder (io.netty.handler.codec.http2.Http2ConnectionHandlerBuilder)3 Http2Exception (io.netty.handler.codec.http2.Http2Exception)3 Http2FrameAdapter (io.netty.handler.codec.http2.Http2FrameAdapter)3 ByteBuf (io.netty.buffer.ByteBuf)2