Search in sources :

Example 6 with Http2StreamVisitor

use of io.netty.handler.codec.http2.Http2StreamVisitor 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 7 with Http2StreamVisitor

use of io.netty.handler.codec.http2.Http2StreamVisitor 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 8 with Http2StreamVisitor

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

the class DefaultHttp2ConnectionTest method removeAllStreamsWhileIteratingActiveStreams.

@Test
public void removeAllStreamsWhileIteratingActiveStreams() throws Exception {
    final Endpoint<Http2RemoteFlowController> remote = client.remote();
    final Endpoint<Http2LocalFlowController> local = client.local();
    for (int c = 3, s = 2; c < 5000; c += 2, s += 2) {
        local.createStream(c, false);
        remote.createStream(s, false);
    }
    final Promise<Void> promise = group.next().newPromise();
    final CountDownLatch latch = new CountDownLatch(client.numActiveStreams());
    client.forEachActiveStream(new Http2StreamVisitor() {

        @Override
        public boolean visit(Http2Stream stream) {
            client.close(promise).addListener(new FutureListener<Void>() {

                @Override
                public void operationComplete(Future<Void> future) throws Exception {
                    assertTrue(promise.isDone());
                    latch.countDown();
                }
            });
            return true;
        }
    });
    assertTrue(latch.await(5, TimeUnit.SECONDS));
}
Also used : FutureListener(io.netty.util.concurrent.FutureListener) CountDownLatch(java.util.concurrent.CountDownLatch) Endpoint(io.netty.handler.codec.http2.Http2Connection.Endpoint) Future(io.netty.util.concurrent.Future) Test(org.junit.jupiter.api.Test)

Aggregations

Http2Exception (io.netty.handler.codec.http2.Http2Exception)6 Http2Stream (io.netty.handler.codec.http2.Http2Stream)6 Http2StreamVisitor (io.netty.handler.codec.http2.Http2StreamVisitor)6 Metadata (io.grpc.Metadata)4 Status (io.grpc.Status)4 Endpoint (io.netty.handler.codec.http2.Http2Connection.Endpoint)2 Future (io.netty.util.concurrent.Future)2 FutureListener (io.netty.util.concurrent.FutureListener)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Test (org.junit.jupiter.api.Test)2 InternalStatus (io.grpc.InternalStatus)1 RpcProgress (io.grpc.internal.ClientStreamListener.RpcProgress)1 Tag (io.perfmark.Tag)1