Class Http2MultiplexHandler
- All Implemented Interfaces:
ChannelHandler
,ChannelInboundHandler
,ChannelOutboundHandler
Http2FrameCodec
.
When a new stream is created, a new Http2StreamChannel
is created for it. Applications send and
receive Http2StreamFrame
s on the created channel. ByteBuf
s cannot be processed by the channel;
all writes that reach the head of the pipeline must be an instance of Http2StreamFrame
. Writes that reach
the head of the pipeline are processed directly by this handler and cannot be intercepted.
The child channel will be notified of user events that impact the stream, such as Http2GoAwayFrame
and Http2ResetFrame
, as soon as they occur. Although
Http2GoAwayFrame
and Http2ResetFrame
signify that the remote is ignoring further
communication, closing of the channel is delayed until any inbound queue is drained with Channel.read()
, which follows the default behavior of channels in Netty. Applications are
free to close the channel in response to such events if they don't have use for any queued
messages. Any connection level events like Http2SettingsFrame
and Http2GoAwayFrame
will be processed internally and also propagated down the pipeline for other handlers to act on.
Outbound streams are supported via the Http2StreamChannelBootstrap
.
ChannelConfig.setMaxMessagesPerRead(int)
and ChannelConfig.setAutoRead(boolean)
are supported.
Reference Counting
SomeHttp2StreamFrame
s implement the ReferenceCounted
interface, as they carry
reference counted objects (e.g. ByteBuf
s). The multiplex codec will call ReferenceCounted.retain()
before propagating a reference counted object through the pipeline, and thus an application handler needs to release
such an object after having consumed it. For more information on reference counting take a look at
the reference counted docs.
Channel Events
A child channel becomes active as soon as it is registered to anEventLoop
. Therefore, an active channel
does not map to an active HTTP/2 stream immediately. Only once a Http2HeadersFrame
has been successfully sent
or received, does the channel map to an active HTTP/2 stream. In case it is not possible to open a new HTTP/2 stream
(i.e. due to the maximum number of active streams being exceeded), the child channel receives an exception
indicating the cause and is closed immediately thereafter.
Writability and Flow Control
A child channel observes outbound/remote flow control via the channel's writability. A channel only becomes writable when it maps to an active HTTP/2 stream . A child channel does not know about the connection-level flow control window.ChannelHandler
s are free to ignore the channel's writability, in which case the excessive writes will
be buffered by the parent channel. It's important to note that only Http2DataFrame
s are subject to
HTTP/2 flow control.
Closing a Http2StreamChannel
Once you close a Http2StreamChannel
a Http2ResetFrame
will be sent to the remote peer with
Http2Error.CANCEL
if needed. If you want to close the stream with another Http2Error
(due
errors / limits) you should propagate a Http2FrameStreamException
through the ChannelPipeline
.
Once it reaches the end of the ChannelPipeline
it will automatically close the Http2StreamChannel
and send a Http2ResetFrame
with the unwrapped Http2Error
set. Another possibility is to just
directly write a Http2ResetFrame
to the Http2StreamChannel
l.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final ChannelFutureListener
private ChannelHandlerContext
private int
private final ChannelHandler
private boolean
private final Queue
<AbstractHttp2StreamChannel> private final ChannelHandler
-
Constructor Summary
ConstructorsConstructorDescriptionHttp2MultiplexHandler
(ChannelHandler inboundStreamHandler) Creates a new instanceHttp2MultiplexHandler
(ChannelHandler inboundStreamHandler, ChannelHandler upgradeStreamHandler) Creates a new instance -
Method Summary
Modifier and TypeMethodDescriptionvoid
channelRead
(ChannelHandlerContext ctx, Object msg) CallsChannelHandlerContext.fireChannelRead(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
.void
Notifies any child streams of the read completion.void
CallsChannelHandlerContext.fireChannelWritabilityChanged()
to forward to the nextChannelInboundHandler
in theChannelPipeline
.void
exceptionCaught
(ChannelHandlerContext ctx, Throwable cause) CallsChannelHandlerContext.fireExceptionCaught(Throwable)
to forward to the nextChannelHandler
in theChannelPipeline
.private void
protected void
protected void
private static boolean
(package private) Http2StreamChannel
private void
onHttp2GoAwayFrame
(ChannelHandlerContext ctx, Http2GoAwayFrame goAwayFrame) private void
(package private) static void
registerDone
(ChannelFuture future) void
userEventTriggered
(ChannelHandlerContext ctx, Object evt) CallsChannelHandlerContext.fireUserEventTriggered(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
.Methods inherited from class io.netty.handler.codec.http2.Http2ChannelDuplexHandler
forEachActiveStream, handlerAdded, handlerRemoved, newStream
Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, read, write
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelRegistered, channelUnregistered
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharable
-
Field Details
-
CHILD_CHANNEL_REGISTRATION_LISTENER
-
inboundStreamHandler
-
upgradeStreamHandler
-
readCompletePendingQueue
-
parentReadInProgress
private boolean parentReadInProgress -
idCount
private int idCount -
ctx
-
-
Constructor Details
-
Http2MultiplexHandler
Creates a new instance- Parameters:
inboundStreamHandler
- theChannelHandler
that will be added to theChannelPipeline
of theChannel
s created for new inbound streams.
-
Http2MultiplexHandler
public Http2MultiplexHandler(ChannelHandler inboundStreamHandler, ChannelHandler upgradeStreamHandler) Creates a new instance- Parameters:
inboundStreamHandler
- theChannelHandler
that will be added to theChannelPipeline
of theChannel
s created for new inbound streams.upgradeStreamHandler
- theChannelHandler
that will be added to theChannelPipeline
of the upgradedChannel
.
-
-
Method Details
-
registerDone
-
handlerAdded0
- Overrides:
handlerAdded0
in classHttp2ChannelDuplexHandler
-
handlerRemoved0
- Overrides:
handlerRemoved0
in classHttp2ChannelDuplexHandler
-
channelRead
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelRead(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelRead
in interfaceChannelInboundHandler
- Overrides:
channelRead
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
channelWritabilityChanged
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelWritabilityChanged()
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelWritabilityChanged
in interfaceChannelInboundHandler
- Overrides:
channelWritabilityChanged
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
userEventTriggered
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireUserEventTriggered(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
userEventTriggered
in interfaceChannelInboundHandler
- Overrides:
userEventTriggered
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
newOutboundStream
Http2StreamChannel newOutboundStream() -
exceptionCaught
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireExceptionCaught(Throwable)
to forward to the nextChannelHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
exceptionCaught
in interfaceChannelHandler
- Specified by:
exceptionCaught
in interfaceChannelInboundHandler
- Overrides:
exceptionCaught
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
fireExceptionCaughtForActiveStream
- Throws:
Http2Exception
-
isServer
-
onHttp2GoAwayFrame
-
channelReadComplete
Notifies any child streams of the read completion.- Specified by:
channelReadComplete
in interfaceChannelInboundHandler
- Overrides:
channelReadComplete
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
processPendingReadCompleteQueue
private void processPendingReadCompleteQueue()
-