public final class Http2MultiplexHandler extends Http2ChannelDuplexHandler
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.
Http2StreamFrame
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.
EventLoop
. 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.
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.
Http2StreamChannel
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.ChannelHandler.Sharable
Constructor and Description |
---|
Http2MultiplexHandler(ChannelHandler inboundStreamHandler)
Creates a new instance
|
Http2MultiplexHandler(ChannelHandler inboundStreamHandler,
ChannelHandler upgradeStreamHandler)
Creates a new instance
|
forEachActiveStream, handlerAdded, handlerRemoved, newStream
bind, close, connect, deregister, disconnect, flush, read, write
channelActive, channelInactive, channelRegistered, channelUnregistered
ensureNotSharable, isSharable
public Http2MultiplexHandler(ChannelHandler inboundStreamHandler)
inboundStreamHandler
- the ChannelHandler
that will be added to the ChannelPipeline
of
the Channel
s created for new inbound streams.public Http2MultiplexHandler(ChannelHandler inboundStreamHandler, ChannelHandler upgradeStreamHandler)
inboundStreamHandler
- the ChannelHandler
that will be added to the ChannelPipeline
of
the Channel
s created for new inbound streams.upgradeStreamHandler
- the ChannelHandler
that will be added to the ChannelPipeline
of the
upgraded Channel
.protected void handlerAdded0(ChannelHandlerContext ctx)
handlerAdded0
in class Http2ChannelDuplexHandler
protected void handlerRemoved0(ChannelHandlerContext ctx)
handlerRemoved0
in class Http2ChannelDuplexHandler
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelRead(Object)
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelRead
in interface ChannelInboundHandler
channelRead
in class ChannelInboundHandlerAdapter
Exception
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelWritabilityChanged()
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelWritabilityChanged
in interface ChannelInboundHandler
channelWritabilityChanged
in class ChannelInboundHandlerAdapter
Exception
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireUserEventTriggered(Object)
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.userEventTriggered
in interface ChannelInboundHandler
userEventTriggered
in class ChannelInboundHandlerAdapter
Exception
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireExceptionCaught(Throwable)
to forward
to the next ChannelHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.exceptionCaught
in interface ChannelHandler
exceptionCaught
in interface ChannelInboundHandler
exceptionCaught
in class ChannelInboundHandlerAdapter
Exception
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception
channelReadComplete
in interface ChannelInboundHandler
channelReadComplete
in class ChannelInboundHandlerAdapter
Exception
Copyright © 2008–2024 The Netty Project. All rights reserved.