Search in sources :

Example 1 with PrimitiveEntry

use of io.netty.util.collection.IntObjectMap.PrimitiveEntry in project netty by netty.

the class Http2MultiplexCodec method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (!(msg instanceof Http2Frame)) {
        ctx.fireChannelRead(msg);
        return;
    }
    if (msg instanceof Http2StreamFrame) {
        Http2StreamFrame frame = (Http2StreamFrame) msg;
        int streamId = frame.streamId();
        Http2StreamChannel childChannel = childChannels.get(streamId);
        if (childChannel == null) {
            // TODO: Combine with DefaultHttp2ConnectionDecoder.shouldIgnoreHeadersOrDataFrame logic.
            ReferenceCountUtil.release(msg);
            throw new StreamException(streamId, STREAM_CLOSED, format("Received %s frame for an unknown stream %d", frame.name(), streamId));
        }
        fireChildReadAndRegister(childChannel, frame);
    } else if (msg instanceof Http2GoAwayFrame) {
        Http2GoAwayFrame goAwayFrame = (Http2GoAwayFrame) msg;
        for (PrimitiveEntry<Http2StreamChannel> entry : childChannels.entries()) {
            Http2StreamChannel childChannel = entry.value();
            int streamId = entry.key();
            if (streamId > goAwayFrame.lastStreamId() && isOutboundStream(server, streamId)) {
                childChannel.pipeline().fireUserEventTriggered(goAwayFrame.retainedDuplicate());
            }
        }
        goAwayFrame.release();
    } else {
        // It's safe to release, as UnsupportedMessageTypeException just calls msg.getClass()
        ReferenceCountUtil.release(msg);
        throw new UnsupportedMessageTypeException(msg);
    }
}
Also used : PrimitiveEntry(io.netty.util.collection.IntObjectMap.PrimitiveEntry) StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) UnsupportedMessageTypeException(io.netty.handler.codec.UnsupportedMessageTypeException)

Aggregations

UnsupportedMessageTypeException (io.netty.handler.codec.UnsupportedMessageTypeException)1 StreamException (io.netty.handler.codec.http2.Http2Exception.StreamException)1 PrimitiveEntry (io.netty.util.collection.IntObjectMap.PrimitiveEntry)1