下面列出了怎么用 io.netty.handler.codec.http2.Http2ResetFrame 的API类实例代码及写法,或者点击链接到github查看源代码。
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();
}
@Override
public final void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
if (evt instanceof Http2ResetFrame) {
Http2ResetFrame resetFrame = (Http2ResetFrame) evt;
if (resetFrame.errorCode() == REFUSED_STREAM.code()) {
ctx.fireExceptionCaught(new H2StreamRefusedException("RST_STREAM received. stream refused"));
} else {
ctx.fireExceptionCaught(new H2StreamResetException("RST_STREAM received with error code: " +
resetFrame.errorCode()));
}
} else {
ctx.fireUserEventTriggered(evt);
}
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, Http2Frame frame) throws Exception {
if (frame instanceof Http2DataFrame) {
onDataRead((Http2DataFrame) frame, ctx);
} else if (frame instanceof Http2HeadersFrame) {
onHeadersRead((Http2HeadersFrame) frame, ctx);
ctx.channel().read();
} else if (frame instanceof Http2ResetFrame) {
onRstStreamRead((Http2ResetFrame) frame, ctx);
} else {
// TODO this is related to the inbound window update bug. Revisit
ctx.channel().parent().read();
}
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
{
if (msg instanceof Http2ResetFrame) {
// Inform zuul to cancel the request.
ctx.fireUserEventTriggered(new RequestCancelledEvent());
}
else {
super.channelRead(ctx, msg);
}
}
private void onRstStreamRead(Http2ResetFrame resetFrame, ChannelHandlerContext ctx) throws Http2Exception {
ctx.fireExceptionCaught(new Http2ResetException(resetFrame.errorCode()));
}