Search in sources :

Example 1 with Endpoint

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

the class DefaultHttp2ConnectionTest method removeAllStreamsWhileIteratingActiveStreamsAndExceptionOccurs.

@Test
public void removeAllStreamsWhileIteratingActiveStreamsAndExceptionOccurs() throws InterruptedException, Http2Exception {
    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(1);
    try {
        client.forEachActiveStream(new Http2StreamVisitor() {

            @Override
            public boolean visit(Http2Stream stream) throws Http2Exception {
                // This close call is basically a noop, because the following statement will throw an exception.
                client.close(promise);
                // Do an invalid operation while iterating.
                remote.createStream(3, false);
                return true;
            }
        });
    } catch (Http2Exception ignored) {
        client.close(promise).addListener(new FutureListener<Void>() {

            @Override
            public void operationComplete(Future<Void> future) throws Exception {
                assertTrue(promise.isDone());
                latch.countDown();
            }
        });
    }
    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.Test)

Example 2 with Endpoint

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

the class DefaultHttp2ConnectionTest method removeAllStreamsWithManyActiveStreams.

@Test
public void removeAllStreamsWithManyActiveStreams() throws InterruptedException, Http2Exception {
    Endpoint<Http2RemoteFlowController> remote = client.remote();
    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);
    }
    testRemoveAllStreams();
}
Also used : Endpoint(io.netty.handler.codec.http2.Http2Connection.Endpoint) Test(org.junit.Test)

Example 3 with Endpoint

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

the class AbstractNettyHandler method sendInitialConnectionWindow.

/**
   * Sends initial connection window to the remote endpoint if necessary.
   */
private void sendInitialConnectionWindow() throws Http2Exception {
    if (ctx.channel().isActive() && initialConnectionWindow > 0) {
        Http2Stream connectionStream = connection().connectionStream();
        int currentSize = connection().local().flowController().windowSize(connectionStream);
        int delta = initialConnectionWindow - currentSize;
        decoder().flowController().incrementWindowSize(connectionStream, delta);
        initialConnectionWindow = -1;
        ctx.flush();
    }
}
Also used : Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Example 4 with Endpoint

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

the class Http2ConnectionHandler method onConnectionError.

/**
     * Handler for a connection error. Sends a GO_AWAY frame to the remote endpoint. Once all
     * streams are closed, the connection is shut down.
     *
     * @param ctx the channel context
     * @param cause the exception that was caught
     * @param http2Ex the {@link Http2Exception} that is embedded in the causality chain. This may
     *            be {@code null} if it's an unknown exception.
     */
protected void onConnectionError(ChannelHandlerContext ctx, Throwable cause, Http2Exception http2Ex) {
    if (http2Ex == null) {
        http2Ex = new Http2Exception(INTERNAL_ERROR, cause.getMessage(), cause);
    }
    ChannelPromise promise = ctx.newPromise();
    ChannelFuture future = goAway(ctx, http2Ex);
    switch(http2Ex.shutdownHint()) {
        case GRACEFUL_SHUTDOWN:
            doGracefulShutdown(ctx, future, promise);
            break;
        default:
            future.addListener(new ClosingChannelFutureListener(ctx, promise));
            break;
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Http2CodecUtil.getEmbeddedHttp2Exception(io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception) ChannelPromise(io.netty.channel.ChannelPromise)

Example 5 with Endpoint

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

the class Http2FrameCodec method writeHeadersFrame.

private void writeHeadersFrame(Http2HeadersFrame headersFrame, ChannelPromise promise) {
    int streamId = headersFrame.streamId();
    if (!isStreamIdValid(streamId)) {
        final Endpoint<Http2LocalFlowController> localEndpoint = http2Handler.connection().local();
        streamId = localEndpoint.incrementAndGetNextStreamId();
        try {
            // Try to create a stream in OPEN state before writing headers, to catch errors on stream creation
            // early on i.e. max concurrent streams limit reached, stream id exhaustion, etc.
            localEndpoint.createStream(streamId, false);
        } catch (Http2Exception e) {
            promise.setFailure(e);
            return;
        }
        ctx.fireUserEventTriggered(new Http2StreamActiveEvent(streamId, headersFrame));
    }
    http2Handler.encoder().writeHeaders(http2HandlerCtx, streamId, headersFrame.headers(), headersFrame.padding(), headersFrame.isEndStream(), promise);
}
Also used : Endpoint(io.netty.handler.codec.http2.Http2Connection.Endpoint)

Aggregations

Endpoint (io.netty.handler.codec.http2.Http2Connection.Endpoint)4 Test (org.junit.Test)3 Future (io.netty.util.concurrent.Future)2 FutureListener (io.netty.util.concurrent.FutureListener)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelPromise (io.netty.channel.ChannelPromise)1 Http2CodecUtil.getEmbeddedHttp2Exception (io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception)1 Http2Stream (io.netty.handler.codec.http2.Http2Stream)1