类 io.netty.handler.codec.http2.Http2GoAwayFrame 源码实例Demo

下面列出了怎么用 io.netty.handler.codec.http2.Http2GoAwayFrame 的API类实例代码及写法,或者点击链接到github查看源代码。


@Override
public final void channelRead(ChannelHandlerContext ctx, Object msg) {
    if (msg instanceof Http2SettingsFrame) {
        if (ackSettings(ctx, (Http2SettingsFrame) msg)) {
            ctx.writeAndFlush(Http2SettingsAckFrame.INSTANCE);
        }
    } else if (msg instanceof Http2GoAwayFrame) {
        Http2GoAwayFrame goAwayFrame = (Http2GoAwayFrame) msg;
        goAwayFrame.release();
        parentContext.onClosing.onComplete();

        // We trigger the graceful close process here (with no timeout) to make sure the socket is closed once
        // the existing streams are closed. The MultiplexCodec may simulate a GOAWAY when the stream IDs are
        // exhausted so we shouldn't rely upon our peer to close the transport.
        parentContext.keepAliveManager.initiateGracefulClose(parentContext.onClosing::onComplete);
    } else if (msg instanceof Http2PingFrame) {
        parentContext.keepAliveManager.pingReceived((Http2PingFrame) msg);
    } else {
        ctx.fireChannelRead(msg);
    }
}
 

protected static void incrementCounter(Registry registry, String counterName, String metricId, Http2Frame frame)
{
    long errorCode;
    if (frame instanceof Http2ResetFrame) {
        errorCode = ((Http2ResetFrame) frame).errorCode();
    }
    else if (frame instanceof Http2GoAwayFrame) {
        errorCode = ((Http2GoAwayFrame) frame).errorCode();
    }
    else {
        errorCode = -1;
    }

    registry.counter(counterName,
            "id", metricId,
            "frame", frame.name(),
            "error_code", Long.toString(errorCode))
            .increment();
}
 

private Http2PingFrame initiateGracefulCloseVerifyGoAwayAndPing(final KeepAliveManager manager) {
    manager.initiateGracefulClose(() -> { });
    Http2GoAwayFrame firstGoAway = verifyWrite(instanceOf(Http2GoAwayFrame.class));
    assertThat("Unexpected error in go_away", firstGoAway.errorCode(), is(Http2Error.NO_ERROR.code()));
    Http2PingFrame pingFrame = verifyWrite(instanceOf(Http2PingFrame.class));
    verifyNoWrite();
    return pingFrame;
}
 

private void verifySecondGoAway() {
    Http2GoAwayFrame secondGoAway = verifyWrite(instanceOf(Http2GoAwayFrame.class));
    assertThat("Unexpected error in go_away", secondGoAway.errorCode(), is(Http2Error.NO_ERROR.code()));
    verifyNoScheduledTasks();
}
 

private void verifyChannelCloseOnMissingPingAck(final ScheduledTask ackTimeoutTask) {
    ackTimeoutTask.task.run();
    verifyWrite(instanceOf(Http2GoAwayFrame.class));
    verifyNoScheduledTasks();
    assertThat("Channel not closed.", channel.isOpen(), is(false));
}
 

@Override
protected void channelRead0(ChannelHandlerContext ctx, Http2GoAwayFrame msg) {
    LOGGER.info(() -> "goaway" + ctx.channel());
    closedByClientH2ConnectionCount.incrementAndGet();
    msg.release();
}
 
 类方法
 同包方法