Search in sources :

Example 21 with HTTP2Stream

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

the class Http2ServerConnection method sendPush.

synchronized void sendPush(int streamId, String host, HttpMethod method, MultiMap headers, String path, Handler<AsyncResult<HttpServerResponse>> completionHandler) {
    Http2Headers headers_ = new DefaultHttp2Headers();
    if (method == HttpMethod.OTHER) {
        throw new IllegalArgumentException("Cannot push HttpMethod.OTHER");
    } else {
        headers_.method(method.name());
    }
    headers_.path(path);
    headers_.scheme(isSsl() ? "https" : "http");
    if (host != null) {
        headers_.authority(host);
    }
    if (headers != null) {
        headers.forEach(header -> headers_.add(header.getKey(), header.getValue()));
    }
    handler.writePushPromise(streamId, headers_, new Handler<AsyncResult<Integer>>() {

        @Override
        public void handle(AsyncResult<Integer> ar) {
            if (ar.succeeded()) {
                synchronized (Http2ServerConnection.this) {
                    int promisedStreamId = ar.result();
                    String contentEncoding = HttpUtils.determineContentEncoding(headers_);
                    Http2Stream promisedStream = handler.connection().stream(promisedStreamId);
                    boolean writable = handler.encoder().flowController().isWritable(promisedStream);
                    Push push = new Push(promisedStream, contentEncoding, method, path, writable, completionHandler);
                    streams.put(promisedStreamId, push);
                    if (maxConcurrentStreams == null || concurrentStreams < maxConcurrentStreams) {
                        concurrentStreams++;
                        context.executeFromIO(push::complete);
                    } else {
                        pendingPushes.add(push);
                    }
                }
            } else {
                context.executeFromIO(() -> {
                    completionHandler.handle(Future.failedFuture(ar.cause()));
                });
            }
        }
    });
}
Also used : Http2Headers(io.netty.handler.codec.http2.Http2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) Http2Stream(io.netty.handler.codec.http2.Http2Stream) AsyncResult(io.vertx.core.AsyncResult)

Example 22 with HTTP2Stream

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

the class NettyClientHandler method goingAway.

/**
   * Handler for a GOAWAY being either sent or received. Fails any streams created after the
   * last known stream.
   */
private void goingAway(Status status) {
    lifecycleManager.notifyShutdown(status);
    final Status goAwayStatus = lifecycleManager.getShutdownStatus();
    final int lastKnownStream = connection().local().lastStreamKnownByPeer();
    try {
        connection().forEachActiveStream(new Http2StreamVisitor() {

            @Override
            public boolean visit(Http2Stream stream) throws Http2Exception {
                if (stream.id() > lastKnownStream) {
                    NettyClientStream.TransportState clientStream = clientStream(stream);
                    if (clientStream != null) {
                        clientStream.transportReportStatus(goAwayStatus, false, new Metadata());
                    }
                    stream.close();
                }
                return true;
            }
        });
    } catch (Http2Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Status(io.grpc.Status) Http2Exception(io.netty.handler.codec.http2.Http2Exception) Http2StreamVisitor(io.netty.handler.codec.http2.Http2StreamVisitor) Metadata(io.grpc.Metadata) Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Example 23 with HTTP2Stream

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

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

the class NettyServerHandler method forcefulClose.

private void forcefulClose(final ChannelHandlerContext ctx, final ForcefulCloseCommand msg, ChannelPromise promise) throws Exception {
    super.close(ctx, promise);
    connection().forEachActiveStream(new Http2StreamVisitor() {

        @Override
        public boolean visit(Http2Stream stream) throws Http2Exception {
            NettyServerStream.TransportState serverStream = serverStream(stream);
            if (serverStream != null) {
                PerfMark.startTask("NettyServerHandler.forcefulClose", serverStream.tag());
                PerfMark.linkIn(msg.getLink());
                try {
                    serverStream.transportReportStatus(msg.getStatus());
                    resetStream(ctx, stream.id(), Http2Error.CANCEL.code(), ctx.newPromise());
                } finally {
                    PerfMark.stopTask("NettyServerHandler.forcefulClose", serverStream.tag());
                }
            }
            stream.close();
            return true;
        }
    });
}
Also used : Http2Exception(io.netty.handler.codec.http2.Http2Exception) Http2StreamVisitor(io.netty.handler.codec.http2.Http2StreamVisitor) Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Example 25 with HTTP2Stream

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

the class NettyClientHandlerTest method connectionWindowShouldBeOverridden.

@Test
public void connectionWindowShouldBeOverridden() throws Exception {
    // 1MiB
    flowControlWindow = 1048576;
    setUp();
    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);
    assertEquals(1048576, actualWindowSize);
}
Also used : Http2LocalFlowController(io.netty.handler.codec.http2.Http2LocalFlowController) Http2Stream(io.netty.handler.codec.http2.Http2Stream) Test(org.junit.Test)

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