Class Http2MultiplexHandler
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.channel.ChannelDuplexHandler
-
- io.netty.handler.codec.http2.Http2ChannelDuplexHandler
-
- io.netty.handler.codec.http2.Http2MultiplexHandler
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler,io.netty.channel.ChannelOutboundHandler
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
Http2StreamChannelis created for it. Applications send and receiveHttp2StreamFrames on the created channel.ByteBufs 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
Http2GoAwayFrameandHttp2ResetFrame, as soon as they occur. AlthoughHttp2GoAwayFrameandHttp2ResetFramesignify 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 likeHttp2SettingsFrameandHttp2GoAwayFramewill 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)andChannelConfig.setAutoRead(boolean)are supported.Reference Counting
SomeHttp2StreamFrames implement theReferenceCountedinterface, as they carry reference counted objects (e.g.ByteBufs). The multiplex codec will callReferenceCounted.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 aHttp2HeadersFramehas 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.ChannelHandlers 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 onlyHttp2DataFrames are subject to HTTP/2 flow control.Closing a
Once you close aHttp2StreamChannelHttp2StreamChannelaHttp2ResetFramewill be sent to the remote peer withHttp2Error.CANCELif needed. If you want to close the stream with anotherHttp2Error(due errors / limits) you should propagate aHttp2FrameStreamExceptionthrough theChannelPipeline. Once it reaches the end of theChannelPipelineit will automatically close theHttp2StreamChanneland send aHttp2ResetFramewith the unwrappedHttp2Errorset. Another possibility is to just directly write aHttp2ResetFrameto theHttp2StreamChannell.
-
-
Constructor Summary
Constructors Constructor Description Http2MultiplexHandler(io.netty.channel.ChannelHandler inboundStreamHandler)Creates a new instanceHttp2MultiplexHandler(io.netty.channel.ChannelHandler inboundStreamHandler, io.netty.channel.ChannelHandler upgradeStreamHandler)Creates a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidchannelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)voidchannelReadComplete(io.netty.channel.ChannelHandlerContext ctx)Notifies any child streams of the read completion.voidchannelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx)voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)protected voidhandlerAdded0(io.netty.channel.ChannelHandlerContext ctx)protected voidhandlerRemoved0(io.netty.channel.ChannelHandlerContext ctx)voiduserEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object evt)-
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
-
-
-
-
Constructor Detail
-
Http2MultiplexHandler
public Http2MultiplexHandler(io.netty.channel.ChannelHandler inboundStreamHandler)
Creates a new instance- Parameters:
inboundStreamHandler- theChannelHandlerthat will be added to theChannelPipelineof theChannels created for new inbound streams.
-
Http2MultiplexHandler
public Http2MultiplexHandler(io.netty.channel.ChannelHandler inboundStreamHandler, io.netty.channel.ChannelHandler upgradeStreamHandler)Creates a new instance- Parameters:
inboundStreamHandler- theChannelHandlerthat will be added to theChannelPipelineof theChannels created for new inbound streams.upgradeStreamHandler- theChannelHandlerthat will be added to theChannelPipelineof the upgradedChannel.
-
-
Method Detail
-
handlerAdded0
protected void handlerAdded0(io.netty.channel.ChannelHandlerContext ctx)
- Overrides:
handlerAdded0in classHttp2ChannelDuplexHandler
-
handlerRemoved0
protected void handlerRemoved0(io.netty.channel.ChannelHandlerContext ctx)
- Overrides:
handlerRemoved0in classHttp2ChannelDuplexHandler
-
channelRead
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception- Specified by:
channelReadin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelWritabilityChanged
public void channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelWritabilityChangedin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelWritabilityChangedin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
userEventTriggered
public void userEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object evt) throws Exception- Specified by:
userEventTriggeredin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
userEventTriggeredin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
exceptionCaught
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelHandler- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
exceptionCaughtin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelReadComplete
public void channelReadComplete(io.netty.channel.ChannelHandlerContext ctx) throws ExceptionNotifies any child streams of the read completion.- Specified by:
channelReadCompletein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadCompletein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
-