- java.lang.Object
-
- io.netty5.handler.codec.http2.Http2ChannelDuplexHandler
-
- io.netty5.handler.codec.http2.Http2MultiplexHandler
-
- All Implemented Interfaces:
ChannelHandler
@UnstableApi public final class Http2MultiplexHandler extends Http2ChannelDuplexHandler
An HTTP/2 handler that creates child channels for each stream. This handler must be used in combination withHttp2FrameCodec
.When a new stream is created, a new
Channel
is created for it. Applications send and receiveHttp2StreamFrame
s on the created channel.Buffer
s cannot be processed by the channel; all writes that reach the head of the pipeline must be an instance ofHttp2StreamFrame
. 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
andHttp2ResetFrame
, as soon as they occur. AlthoughHttp2GoAwayFrame
andHttp2ResetFrame
signify that the remote is ignoring further communication, closing of the channel is delayed until any inbound queue is drained withChannel.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 likeHttp2SettingsFrame
andHttp2GoAwayFrame
will be processed internally and also propagated down the pipeline for other handlers to act on.Outbound streams are supported via the
Http2StreamChannelBootstrap
.ChannelOption.MAX_MESSAGES_PER_READ
andChannelOption.AUTO_READ
are supported.Resources
SomeHttp2StreamFrame
s implement theResource
interface, as they carry resource objects (e.g.Buffer
s). An application handler needs to close or dispose of such objects after having consumed them.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 aHttp2HeadersFrame
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 onlyHttp2DataFrame
s are subject to HTTP/2 flow control.
-
-
Constructor Summary
Constructors Constructor Description Http2MultiplexHandler(ChannelHandler inboundStreamHandler)
Creates a new instanceHttp2MultiplexHandler(ChannelHandler inboundStreamHandler, ChannelHandler upgradeStreamHandler)
Creates a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause)
Gets called if aThrowable
was thrown when handling inbound events.void
channelInboundEvent(ChannelHandlerContext ctx, Object evt)
Gets called if a custom inbound event happened.void
channelRead(ChannelHandlerContext ctx, Object msg)
Invoked when the currentChannel
has read a message from the peer.void
channelReadComplete(ChannelHandlerContext ctx)
Notifies any child streams of the read completion.void
channelWritabilityChanged(ChannelHandlerContext ctx)
Gets called once the writable state of aChannel
changed.protected void
handlerAdded0(ChannelHandlerContext ctx)
protected void
handlerRemoved0(ChannelHandlerContext ctx)
-
Methods inherited from class io.netty5.handler.codec.http2.Http2ChannelDuplexHandler
forEachActiveStream, handlerAdded, handlerRemoved, newStream
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelActive, channelInactive, channelRegistered, channelShutdown, channelUnregistered, close, connect, deregister, disconnect, flush, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown, write
-
-
-
-
Constructor Detail
-
Http2MultiplexHandler
public Http2MultiplexHandler(ChannelHandler inboundStreamHandler)
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 Detail
-
handlerAdded0
protected void handlerAdded0(ChannelHandlerContext ctx)
- Overrides:
handlerAdded0
in classHttp2ChannelDuplexHandler
-
handlerRemoved0
protected void handlerRemoved0(ChannelHandlerContext ctx)
- Overrides:
handlerRemoved0
in classHttp2ChannelDuplexHandler
-
channelRead
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
Description copied from interface:ChannelHandler
Invoked when the currentChannel
has read a message from the peer.- Throws:
Exception
-
channelWritabilityChanged
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
Gets called once the writable state of aChannel
changed. You can check the state withChannel.writableBytes()
orChannel.isWritable()
.- Throws:
Exception
-
channelInboundEvent
public void channelInboundEvent(ChannelHandlerContext ctx, Object evt) throws Exception
Description copied from interface:ChannelHandler
Gets called if a custom inbound event happened.- Throws:
Exception
-
channelExceptionCaught
public void channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
Description copied from interface:ChannelHandler
Gets called if aThrowable
was thrown when handling inbound events.- Throws:
Exception
-
channelReadComplete
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception
Notifies any child streams of the read completion.- Throws:
Exception
-
-