Search in sources :

Example 21 with Http2Connection

use of io.netty.handler.codec.http2.Http2Connection in project grpc-java by grpc.

the class NettyServerHandler method newHandler.

static NettyServerHandler newHandler(ChannelPromise channelUnused, Http2FrameReader frameReader, Http2FrameWriter frameWriter, ServerTransportListener transportListener, List<? extends ServerStreamTracer.Factory> streamTracerFactories, TransportTracer transportTracer, int maxStreams, boolean autoFlowControl, int flowControlWindow, int maxHeaderListSize, int maxMessageSize, long keepAliveTimeInNanos, long keepAliveTimeoutInNanos, long maxConnectionIdleInNanos, long maxConnectionAgeInNanos, long maxConnectionAgeGraceInNanos, boolean permitKeepAliveWithoutCalls, long permitKeepAliveTimeInNanos, Attributes eagAttributes) {
    Preconditions.checkArgument(maxStreams > 0, "maxStreams must be positive: %s", maxStreams);
    Preconditions.checkArgument(flowControlWindow > 0, "flowControlWindow must be positive: %s", flowControlWindow);
    Preconditions.checkArgument(maxHeaderListSize > 0, "maxHeaderListSize must be positive: %s", maxHeaderListSize);
    Preconditions.checkArgument(maxMessageSize > 0, "maxMessageSize must be positive: %s", maxMessageSize);
    final Http2Connection connection = new DefaultHttp2Connection(true);
    WeightedFairQueueByteDistributor dist = new WeightedFairQueueByteDistributor(connection);
    // Make benchmarks fast again.
    dist.allocationQuantum(16 * 1024);
    DefaultHttp2RemoteFlowController controller = new DefaultHttp2RemoteFlowController(connection, dist);
    connection.remote().flowController(controller);
    final KeepAliveEnforcer keepAliveEnforcer = new KeepAliveEnforcer(permitKeepAliveWithoutCalls, permitKeepAliveTimeInNanos, TimeUnit.NANOSECONDS);
    // Create the local flow controller configured to auto-refill the connection window.
    connection.local().flowController(new DefaultHttp2LocalFlowController(connection, DEFAULT_WINDOW_UPDATE_RATIO, true));
    frameWriter = new WriteMonitoringFrameWriter(frameWriter, keepAliveEnforcer);
    Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(connection, frameWriter);
    encoder = new Http2ControlFrameLimitEncoder(encoder, 10000);
    Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(connection, encoder, frameReader);
    Http2Settings settings = new Http2Settings();
    settings.initialWindowSize(flowControlWindow);
    settings.maxConcurrentStreams(maxStreams);
    settings.maxHeaderListSize(maxHeaderListSize);
    return new NettyServerHandler(channelUnused, connection, transportListener, streamTracerFactories, transportTracer, decoder, encoder, settings, maxMessageSize, keepAliveTimeInNanos, keepAliveTimeoutInNanos, maxConnectionIdleInNanos, maxConnectionAgeInNanos, maxConnectionAgeGraceInNanos, keepAliveEnforcer, autoFlowControl, eagAttributes);
}
Also used : DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Http2Connection(io.netty.handler.codec.http2.Http2Connection) DefaultHttp2ConnectionDecoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder) WeightedFairQueueByteDistributor(io.netty.handler.codec.http2.WeightedFairQueueByteDistributor) DefaultHttp2ConnectionEncoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder) Http2ConnectionDecoder(io.netty.handler.codec.http2.Http2ConnectionDecoder) DefaultHttp2ConnectionDecoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder) DefaultHttp2LocalFlowController(io.netty.handler.codec.http2.DefaultHttp2LocalFlowController) DefaultHttp2RemoteFlowController(io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController) Http2ConnectionEncoder(io.netty.handler.codec.http2.Http2ConnectionEncoder) DefaultHttp2ConnectionEncoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder) Http2Settings(io.netty.handler.codec.http2.Http2Settings)

Example 22 with Http2Connection

use of io.netty.handler.codec.http2.Http2Connection in project grpc-java by grpc.

the class NettyClientHandlerTest method newHandler.

@Override
protected NettyClientHandler newHandler() throws Http2Exception {
    Http2Connection connection = new DefaultHttp2Connection(false);
    // Create and close a stream previous to the nextStreamId.
    Http2Stream stream = connection.local().createStream(streamId - 2, true);
    stream.close();
    final Ticker ticker = new Ticker() {

        @Override
        public long read() {
            return nanoTime;
        }
    };
    Supplier<Stopwatch> stopwatchSupplier = new Supplier<Stopwatch>() {

        @Override
        public Stopwatch get() {
            return Stopwatch.createUnstarted(ticker);
        }
    };
    return NettyClientHandler.newHandler(connection, frameReader(), frameWriter(), lifecycleManager, mockKeepAliveManager, false, flowControlWindow, maxHeaderListSize, stopwatchSupplier, tooManyPingsRunnable, transportTracer, Attributes.EMPTY, "someauthority", null);
}
Also used : DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Http2Connection(io.netty.handler.codec.http2.Http2Connection) Ticker(com.google.common.base.Ticker) Stopwatch(com.google.common.base.Stopwatch) Supplier(com.google.common.base.Supplier) Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Example 23 with Http2Connection

use of io.netty.handler.codec.http2.Http2Connection in project ballerina by ballerina-lang.

the class HTTP2ClientInitializer method initChannel.

@Override
public void initChannel(SocketChannel ch) throws Exception {
    final Http2Connection connection = new DefaultHttp2Connection(false);
    connectionHandler = new HttpToHttp2ConnectionHandlerBuilder().frameListener(new DelegatingDecompressorFrameListener(connection, new InboundHttp2ToHttpAdapterBuilder(connection).maxContentLength(maxContentLength).propagateSettings(true).build())).frameLogger(logger).connection(connection).build();
    responseHandler = new HTTP2ResponseHandler();
    settingsHandler = new HTTP2SettingsHandler(ch.newPromise());
    if (sslCtx != null) {
        configureSsl(ch);
    } else {
        configureClearText(ch);
    }
}
Also used : DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) DelegatingDecompressorFrameListener(io.netty.handler.codec.http2.DelegatingDecompressorFrameListener) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Http2Connection(io.netty.handler.codec.http2.Http2Connection) InboundHttp2ToHttpAdapterBuilder(io.netty.handler.codec.http2.InboundHttp2ToHttpAdapterBuilder) HttpToHttp2ConnectionHandlerBuilder(io.netty.handler.codec.http2.HttpToHttp2ConnectionHandlerBuilder)

Example 24 with Http2Connection

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

the class InboundHttp2ToHttpAdapterTest method boostrapEnv.

private void boostrapEnv(int clientLatchCount, int clientLatchCount2, int serverLatchCount, int serverLatchCount2, int settingsLatchCount) throws InterruptedException {
    final CountDownLatch prefaceWrittenLatch = new CountDownLatch(1);
    clientDelegator = null;
    serverDelegator = null;
    serverConnectedChannel = null;
    maxContentLength = 1024;
    final CountDownLatch serverChannelLatch = new CountDownLatch(1);
    serverLatch = new CountDownLatch(serverLatchCount);
    clientLatch = new CountDownLatch(clientLatchCount);
    serverLatch2 = new CountDownLatch(serverLatchCount2);
    clientLatch2 = new CountDownLatch(clientLatchCount2);
    settingsLatch = new CountDownLatch(settingsLatchCount);
    sb = new ServerBootstrap();
    cb = new Bootstrap();
    sb.group(new DefaultEventLoopGroup());
    sb.channel(LocalServerChannel.class);
    sb.childHandler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            serverConnectedChannel = ch;
            ChannelPipeline p = ch.pipeline();
            Http2Connection connection = new DefaultHttp2Connection(true);
            serverHandler = new Http2ConnectionHandlerBuilder().frameListener(new InboundHttp2ToHttpAdapterBuilder(connection).maxContentLength(maxContentLength).validateHttpHeaders(true).propagateSettings(true).build()).connection(connection).gracefulShutdownTimeoutMillis(0).build();
            p.addLast(serverHandler);
            serverDelegator = new HttpResponseDelegator(serverListener, serverLatch, serverLatch2);
            p.addLast(serverDelegator);
            settingsDelegator = new HttpSettingsDelegator(settingsListener, settingsLatch);
            p.addLast(settingsDelegator);
            serverChannelLatch.countDown();
        }
    });
    cb.group(new DefaultEventLoopGroup());
    cb.channel(LocalChannel.class);
    cb.handler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            Http2Connection connection = new DefaultHttp2Connection(false);
            clientHandler = new Http2ConnectionHandlerBuilder().frameListener(new InboundHttp2ToHttpAdapterBuilder(connection).maxContentLength(maxContentLength).build()).connection(connection).gracefulShutdownTimeoutMillis(0).build();
            p.addLast(clientHandler);
            clientDelegator = new HttpResponseDelegator(clientListener, clientLatch, clientLatch2);
            p.addLast(clientDelegator);
            p.addLast(new ChannelHandlerAdapter() {

                @Override
                public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
                    Http2Exception e = getEmbeddedHttp2Exception(cause);
                    if (e != null) {
                        clientException = e;
                        clientLatch.countDown();
                    } else {
                        super.exceptionCaught(ctx, cause);
                    }
                }
            });
            p.addLast(new ChannelInboundHandlerAdapter() {

                @Override
                public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
                    if (evt == Http2ConnectionPrefaceAndSettingsFrameWrittenEvent.INSTANCE) {
                        prefaceWrittenLatch.countDown();
                        ctx.pipeline().remove(this);
                    }
                }
            });
        }
    });
    serverChannel = sb.bind(new LocalAddress("InboundHttp2ToHttpAdapterTest")).sync().channel();
    ChannelFuture ccf = cb.connect(serverChannel.localAddress());
    assertTrue(ccf.awaitUninterruptibly().isSuccess());
    clientChannel = ccf.channel();
    assertTrue(prefaceWrittenLatch.await(5, SECONDS));
    assertTrue(serverChannelLatch.await(5, SECONDS));
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Http2CodecUtil.getEmbeddedHttp2Exception(io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception) LocalAddress(io.netty.channel.local.LocalAddress) LocalServerChannel(io.netty.channel.local.LocalServerChannel) LocalChannel(io.netty.channel.local.LocalChannel) Http2TestUtil.runInChannel(io.netty.handler.codec.http2.Http2TestUtil.runInChannel) Channel(io.netty.channel.Channel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) Http2CodecUtil.getEmbeddedHttp2Exception(io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception) ChannelPipeline(io.netty.channel.ChannelPipeline) ChannelHandlerAdapter(io.netty.channel.ChannelHandlerAdapter) Bootstrap(io.netty.bootstrap.Bootstrap) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) HttpObject(io.netty.handler.codec.http.HttpObject) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter)

Example 25 with Http2Connection

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

the class Http2ClientPipelineInitializer method configureHttpPipeline.

/**
 * Sets up HTTP/2 over TCP through protocol upgrade (h2c) pipeline
 */
private void configureHttpPipeline(Channel channel, Http2Connection connection) throws Exception {
    Http2StreamCodec http2Codec = new Http2StreamCodecBuilder().connection(connection).maxContentLength(_maxResponseSize).gracefulShutdownTimeoutMillis(_gracefulShutdownTimeout).build();
    HttpClientCodec sourceCodec = new HttpClientCodec(MAX_INITIAL_LINE_LENGTH, _maxHeaderSize, _maxChunkSize);
    Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec(http2Codec);
    HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, MAX_CLIENT_UPGRADE_CONTENT_LENGTH);
    Http2SchemeHandler schemeHandler = new Http2SchemeHandler(HttpScheme.HTTP.toString());
    Http2UpgradeHandler upgradeRequestHandler = new Http2UpgradeHandler();
    Http2StreamResponseHandler responseHandler = new Http2StreamResponseHandler();
    channel.pipeline().addLast("sourceCodec", sourceCodec);
    channel.pipeline().addLast("upgradeHandler", upgradeHandler);
    channel.pipeline().addLast("upgradeRequestHandler", upgradeRequestHandler);
    channel.pipeline().addLast("schemeHandler", schemeHandler);
    channel.pipeline().addLast("responseHandler", responseHandler);
}
Also used : Http2ClientUpgradeCodec(io.netty.handler.codec.http2.Http2ClientUpgradeCodec) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) HttpClientUpgradeHandler(io.netty.handler.codec.http.HttpClientUpgradeHandler)

Aggregations

Http2Connection (io.netty.handler.codec.http2.Http2Connection)19 DefaultHttp2Connection (io.netty.handler.codec.http2.DefaultHttp2Connection)14 Http2ConnectionDecoder (io.netty.handler.codec.http2.Http2ConnectionDecoder)8 Http2Settings (io.netty.handler.codec.http2.Http2Settings)8 DefaultHttp2ConnectionEncoder (io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder)7 Http2ConnectionEncoder (io.netty.handler.codec.http2.Http2ConnectionEncoder)6 DefaultHttp2ConnectionDecoder (io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder)5 DefaultHttp2FrameReader (io.netty.handler.codec.http2.DefaultHttp2FrameReader)5 Http2Stream (io.netty.handler.codec.http2.Http2Stream)5 Bootstrap (io.netty.bootstrap.Bootstrap)4 Channel (io.netty.channel.Channel)4 ChannelFuture (io.netty.channel.ChannelFuture)4 ChannelPipeline (io.netty.channel.ChannelPipeline)4 DefaultHttp2FrameWriter (io.netty.handler.codec.http2.DefaultHttp2FrameWriter)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)3 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)3 DefaultHttp2LocalFlowController (io.netty.handler.codec.http2.DefaultHttp2LocalFlowController)3 Http2ConnectionHandler (io.netty.handler.codec.http2.Http2ConnectionHandler)3