Top Description Fields Constructors Methods
io.netty5.handler.codec.http2

public final Class Http2MultiplexHandler

extends Http2ChannelDuplexHandler
Class Inheritance
Annotations
@UnstableApi
Imports
io.netty5.buffer.Buffer, io.netty5.channel.Channel, .ChannelHandler, .ChannelHandlerContext, .ChannelOption, .ChannelOutboundInvoker, .ChannelPipeline, .EventLoop, .ReadBufferAllocator, .ServerChannel, io.netty5.handler.codec.http2.Http2FrameCodec.DefaultHttp2FrameStream, io.netty5.util.Resource, io.netty5.util.concurrent.Future, .FutureContextListener, io.netty5.util.internal.UnstableApi, javax.net.ssl.SSLException, java.util.ArrayDeque, .Objects, .Queue

An HTTP/2 handler that creates child channels for each stream. This handler must be used in combination with Http2FrameCodec.

When a new stream is created, a new Channel is created for it. Applications send and receive Http2StreamFrames on the created channel. Buffers 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 ChannelOutboundInvoker#read(ReadBufferAllocator), 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.

ChannelOption#AUTO_READ is supported.

Resources

Some Http2StreamFrames implement the Resource interface, as they carry resource objects (e.g. Buffers). 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 an 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.

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 only Http2DataFrames are subject to HTTP/2 flow control.

Field Summary

Modifier and TypeField and Description
private static final FutureContextListener<Channel, Void>
private volatile ChannelHandlerContext
private int
private final ChannelHandler
private boolean
private final Queue<DefaultHttp2StreamChannel>
private final ChannelHandler

Constructor Summary

AccessConstructor and Description
public
Http2MultiplexHandler(ChannelHandler
the ChannelHandler that will be added to the ChannelPipeline of the Channels created for new inbound streams.
inboundStreamHandler
)

Creates a new instance

public
Http2MultiplexHandler(ChannelHandler
the ChannelHandler that will be added to the ChannelPipeline of the Channels created for new inbound streams.
inboundStreamHandler
,
ChannelHandler
the ChannelHandler that will be added to the ChannelPipeline of the upgraded Channel.
upgradeStreamHandler
)

Creates a new instance

Method Summary

Modifier and TypeMethod and Description
pack-priv void
public void
channelExceptionCaught(ChannelHandlerContext ctx, final Throwable cause)

Overrides default io.netty5.channel.ChannelHandler.channelExceptionCaught.

Gets called if a Throwable was thrown when handling inbound events.
public void
channelInboundEvent(ChannelHandlerContext ctx, Object evt)

Overrides default io.netty5.channel.ChannelHandler.channelInboundEvent.

Gets called if a custom inbound event happened.
public void
channelRead(ChannelHandlerContext ctx, Object msg)

Overrides default io.netty5.channel.ChannelHandler.channelRead.

Invoked when the current Channel has read a message from the peer.
public void
channelReadComplete(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.channelReadComplete.

Notifies any child streams of the read completion.
public void
channelWritabilityChanged(final ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.channelWritabilityChanged.

Gets called once the writable state of a Channel changed.
private void
protected void
protected void
pack-priv boolean
private static boolean
pack-priv Http2StreamChannel
private void
pack-priv ChannelHandlerContext
private void
private static void
registerDone(Channel childChannel, Future<?> future)

Inherited from io.netty5.handler.codec.http2.Http2ChannelDuplexHandler:
forEachActiveStreamhandlerAddedhandlerRemovednewStream

Field Detail

CHILD_CHANNEL_REGISTRATION_LISTENERback to summary
private static final FutureContextListener<Channel, Void> CHILD_CHANNEL_REGISTRATION_LISTENER
ctxback to summary
private volatile ChannelHandlerContext ctx
idCountback to summary
private int idCount
inboundStreamHandlerback to summary
private final ChannelHandler inboundStreamHandler
parentReadInProgressback to summary
private boolean parentReadInProgress
readCompletePendingQueueback to summary
private final Queue<DefaultHttp2StreamChannel> readCompletePendingQueue
upgradeStreamHandlerback to summary
private final ChannelHandler upgradeStreamHandler

Constructor Detail

Http2MultiplexHandlerback to summary
public Http2MultiplexHandler(ChannelHandler inboundStreamHandler)

Creates a new instance

Parameters
inboundStreamHandler:ChannelHandler

the ChannelHandler that will be added to the ChannelPipeline of the Channels created for new inbound streams.

Http2MultiplexHandlerback to summary
public Http2MultiplexHandler(ChannelHandler inboundStreamHandler, ChannelHandler upgradeStreamHandler)

Creates a new instance

Parameters
inboundStreamHandler:ChannelHandler

the ChannelHandler that will be added to the ChannelPipeline of the Channels created for new inbound streams.

upgradeStreamHandler:ChannelHandler

the ChannelHandler that will be added to the ChannelPipeline of the upgraded Channel.

Method Detail

addChannelToReadCompletePendingQueueback to summary
pack-priv void addChannelToReadCompletePendingQueue(DefaultHttp2StreamChannel channel)
channelExceptionCaughtback to summary
public void channelExceptionCaught(ChannelHandlerContext ctx, final Throwable cause) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelExceptionCaught.

Doc from io.netty5.channel.ChannelHandler.channelExceptionCaught.

Gets called if a Throwable was thrown when handling inbound events.

Annotations
@Override
channelInboundEventback to summary
public void channelInboundEvent(ChannelHandlerContext ctx, Object evt) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelInboundEvent.

Doc from io.netty5.channel.ChannelHandler.channelInboundEvent.

Gets called if a custom inbound event happened.

Annotations
@Override
channelReadback to summary
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelRead.

Doc from io.netty5.channel.ChannelHandler.channelRead.

Invoked when the current Channel has read a message from the peer.

Annotations
@Override
channelReadCompleteback to summary
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelReadComplete.

Notifies any child streams of the read completion.

Annotations
@Override
channelWritabilityChangedback to summary
public void channelWritabilityChanged(final ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelWritabilityChanged.

Doc from io.netty5.channel.ChannelHandler.channelWritabilityChanged.

Gets called once the writable state of a Channel changed. You can check the state with Channel#writableBytes() or Channel#isWritable().

Annotations
@Override
createStreamChannelIfNeededback to summary
private void createStreamChannelIfNeeded(Http2FrameCodec.DefaultHttp2FrameStream stream) throws Http2Exception
handlerAdded0back to summary
protected void handlerAdded0(ChannelHandlerContext ctx)

Overrides io.netty5.handler.codec.http2.Http2ChannelDuplexHandler.handlerAdded0.

Annotations
@Override
handlerRemoved0back to summary
protected void handlerRemoved0(ChannelHandlerContext ctx)

Overrides io.netty5.handler.codec.http2.Http2ChannelDuplexHandler.handlerRemoved0.

Annotations
@Override
isParentReadInProgressback to summary
pack-priv boolean isParentReadInProgress()
isServerback to summary
private static boolean isServer(ChannelHandlerContext ctx)
newOutboundStreamback to summary
pack-priv Http2StreamChannel newOutboundStream()
onHttp2GoAwayFrameback to summary
private void onHttp2GoAwayFrame(ChannelHandlerContext ctx, final Http2GoAwayFrame goAwayFrame)
parentContextback to summary
pack-priv ChannelHandlerContext parentContext()
processPendingReadCompleteQueueback to summary
private void processPendingReadCompleteQueue()
registerDoneback to summary
private static void registerDone(Channel childChannel, Future<?> future)