Search in sources :

Example 26 with HTTP2Stream

use of org.eclipse.jetty.http2.HTTP2Stream 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 27 with HTTP2Stream

use of org.eclipse.jetty.http2.HTTP2Stream in project grpc-java by grpc.

the class NettyServerHandlerTest method connectionWindowShouldBeOverridden.

@Test
public void connectionWindowShouldBeOverridden() throws Exception {
    // 1MiB
    flowControlWindow = 1048576;
    manualSetUp();
    Http2Stream connectionStream = connection().connectionStream();
    Http2LocalFlowController localFlowController = connection().local().flowController();
    int actualInitialWindowSize = localFlowController.initialWindowSize(connectionStream);
    int actualWindowSize = localFlowController.windowSize(connectionStream);
    assertEquals(flowControlWindow, actualWindowSize);
    assertEquals(flowControlWindow, actualInitialWindowSize);
}
Also used : Http2LocalFlowController(io.netty.handler.codec.http2.Http2LocalFlowController) Http2Stream(io.netty.handler.codec.http2.Http2Stream) Test(org.junit.Test)

Example 28 with HTTP2Stream

use of org.eclipse.jetty.http2.HTTP2Stream in project grpc-java by grpc.

the class NettyHandlerTestBase method windowUpdateMatchesTarget.

@Test
public void windowUpdateMatchesTarget() throws Exception {
    manualSetUp();
    Http2Stream connectionStream = connection().connectionStream();
    Http2LocalFlowController localFlowController = connection().local().flowController();
    makeStream();
    AbstractNettyHandler handler = (AbstractNettyHandler) handler();
    handler.setAutoTuneFlowControl(true);
    ByteBuf data = ctx().alloc().buffer(1024);
    while (data.isWritable()) {
        data.writeLong(1111);
    }
    int length = data.readableBytes();
    ByteBuf frame = dataFrame(3, false, data.copy());
    channelRead(frame);
    int accumulator = length;
    // 40 is arbitrary, any number large enough to trigger a window update would work
    for (int i = 0; i < 40; i++) {
        channelRead(dataFrame(3, false, data.copy()));
        accumulator += length;
    }
    long pingData = handler.flowControlPing().payload();
    channelRead(pingFrame(true, pingData));
    assertEquals(accumulator, handler.flowControlPing().getDataSincePing());
    assertEquals(2 * accumulator, localFlowController.initialWindowSize(connectionStream));
}
Also used : Http2LocalFlowController(io.netty.handler.codec.http2.Http2LocalFlowController) Http2Stream(io.netty.handler.codec.http2.Http2Stream) CompositeByteBuf(io.netty.buffer.CompositeByteBuf) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 29 with HTTP2Stream

use of org.eclipse.jetty.http2.HTTP2Stream in project grpc-java by grpc.

the class NettyClientHandler method createStreamTraced.

private void createStreamTraced(final int streamId, final NettyClientStream.TransportState stream, final Http2Headers headers, boolean isGet, final boolean shouldBeCountedForInUse, final ChannelPromise promise) {
    // Create an intermediate promise so that we can intercept the failure reported back to the
    // application.
    ChannelPromise tempPromise = ctx().newPromise();
    encoder().writeHeaders(ctx(), streamId, headers, 0, isGet, tempPromise).addListener(new ChannelFutureListener() {

        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            if (future.isSuccess()) {
                // The http2Stream will be null in case a stream buffered in the encoder
                // was canceled via RST_STREAM.
                Http2Stream http2Stream = connection().stream(streamId);
                if (http2Stream != null) {
                    stream.getStatsTraceContext().clientOutboundHeaders();
                    http2Stream.setProperty(streamKey, stream);
                    // be later than we would like.
                    if (shouldBeCountedForInUse) {
                        inUseState.updateObjectInUse(http2Stream, true);
                    }
                    // Attach the client stream to the HTTP/2 stream object as user data.
                    stream.setHttp2Stream(http2Stream);
                }
                // Otherwise, the stream has been cancelled and Netty is sending a
                // RST_STREAM frame which causes it to purge pending writes from the
                // flow-controller and delete the http2Stream. The stream listener has already
                // been notified of cancellation so there is nothing to do.
                // Just forward on the success status to the original promise.
                promise.setSuccess();
            } else {
                Throwable cause = future.cause();
                if (cause instanceof StreamBufferingEncoder.Http2GoAwayException) {
                    StreamBufferingEncoder.Http2GoAwayException e = (StreamBufferingEncoder.Http2GoAwayException) cause;
                    Status status = statusFromH2Error(Status.Code.UNAVAILABLE, "GOAWAY closed buffered stream", e.errorCode(), e.debugData());
                    cause = status.asRuntimeException();
                    stream.transportReportStatus(status, RpcProgress.MISCARRIED, true, new Metadata());
                } else if (cause instanceof StreamBufferingEncoder.Http2ChannelClosedException) {
                    Status status = lifecycleManager.getShutdownStatus();
                    if (status == null) {
                        status = Status.UNAVAILABLE.withCause(cause).withDescription("Connection closed while stream is buffered");
                    }
                    stream.transportReportStatus(status, RpcProgress.MISCARRIED, true, new Metadata());
                }
                promise.setFailure(cause);
            }
        }
    });
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Status(io.grpc.Status) StreamBufferingEncoder(io.netty.handler.codec.http2.StreamBufferingEncoder) Metadata(io.grpc.Metadata) ChannelPromise(io.netty.channel.ChannelPromise) ChannelFutureListener(io.netty.channel.ChannelFutureListener) Http2Exception(io.netty.handler.codec.http2.Http2Exception) StatusException(io.grpc.StatusException) ClosedChannelException(java.nio.channels.ClosedChannelException) Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Example 30 with HTTP2Stream

use of org.eclipse.jetty.http2.HTTP2Stream in project vert.x by eclipse.

the class Http2ConnectionBase method setWindowSize.

@Override
public HttpConnection setWindowSize(int windowSize) {
    try {
        Http2Stream stream = handler.encoder().connection().connectionStream();
        int delta = windowSize - this.windowSize;
        handler.decoder().flowController().incrementWindowSize(stream, delta);
        this.windowSize = windowSize;
        return this;
    } catch (Http2Exception e) {
        throw new VertxException(e);
    }
}
Also used : Http2Exception(io.netty.handler.codec.http2.Http2Exception) VertxException(io.vertx.core.VertxException) Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Aggregations

Http2Stream (io.netty.handler.codec.http2.Http2Stream)26 Http2Exception (io.netty.handler.codec.http2.Http2Exception)10 Test (org.junit.Test)9 Metadata (io.grpc.Metadata)6 Http2StreamVisitor (io.netty.handler.codec.http2.Http2StreamVisitor)6 Status (io.grpc.Status)5 Http2Connection (io.netty.handler.codec.http2.Http2Connection)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 HttpFields (org.eclipse.jetty.http.HttpFields)4 HTTP2Session (org.eclipse.jetty.http2.HTTP2Session)4 HTTP2Stream (org.eclipse.jetty.http2.HTTP2Stream)4 Session (org.eclipse.jetty.http2.api.Session)4 Stream (org.eclipse.jetty.http2.api.Stream)4 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)4 ChannelFuture (io.netty.channel.ChannelFuture)3 Http2LocalFlowController (io.netty.handler.codec.http2.Http2LocalFlowController)3 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)3 FuturePromise (org.eclipse.jetty.util.FuturePromise)3 ByteBuf (io.netty.buffer.ByteBuf)2 DefaultHttp2Connection (io.netty.handler.codec.http2.DefaultHttp2Connection)2