Top Description Inners Fields Constructors Methods
io.netty.handler.codec.http2

public final Class Http2MultiplexHandler

extends Http2ChannelDuplexHandler
Class Inheritance
Annotations
@UnstableApi
Imports
io.netty.buffer.ByteBuf, io.netty.channel.Channel, .ChannelConfig, .ChannelFuture, .ChannelFutureListener, .ChannelHandler, .ChannelHandlerContext, .ChannelPipeline, .EventLoop, .ServerChannel, io.netty.channel.socket.ChannelInputShutdownReadComplete, .ChannelOutputShutdownEvent, io.netty.handler.codec.http2.Http2FrameCodec.DefaultHttp2FrameStream, io.netty.handler.ssl.SslCloseCompletionEvent, io.netty.util.ReferenceCounted, io.netty.util.internal.ObjectUtil, .UnstableApi, java.util.ArrayDeque, .Queue, javax.net.ssl.SSLException

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 Http2StreamChannel is created for it. Applications send and receive Http2StreamFrames on the created channel. ByteBufs 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

Some Http2StreamFrames implement the ReferenceCounted interface, as they carry reference counted objects (e.g. ByteBufs). 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 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.

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 Http2StreamChannell.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
pack-priv static final ChannelFutureListener
private volatile ChannelHandlerContext
private int
private final ChannelHandler
private boolean
private final Queue<AbstractHttp2StreamChannel>
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
public void
public void
public void
public void
private void
protected void
protected void
private static boolean
pack-priv Http2StreamChannel
private void
private void
pack-priv static void
public void
Inherited from io.netty.handler.codec.http2.Http2ChannelDuplexHandler:
forEachActiveStreamhandlerAddedhandlerRemovednewStream

Field Detail

CHILD_CHANNEL_REGISTRATION_LISTENERback to summary
pack-priv static final ChannelFutureListener 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<AbstractHttp2StreamChannel> 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

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

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelRead.

Implements io.netty.channel.ChannelInboundHandler.channelRead.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelRead.

Calls ChannelHandlerContext#fireChannelRead(Object) to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

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

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete.

Implements io.netty.channel.ChannelInboundHandler.channelReadComplete.

Notifies any child streams of the read completion.

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

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelWritabilityChanged.

Implements io.netty.channel.ChannelInboundHandler.channelWritabilityChanged.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelWritabilityChanged.

Calls ChannelHandlerContext#fireChannelWritabilityChanged() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
exceptionCaughtback to summary
public void exceptionCaught(ChannelHandlerContext ctx, final Throwable cause) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught.

Implements io.netty.channel.ChannelHandler.exceptionCaught, io.netty.channel.ChannelInboundHandler.exceptionCaught.

Doc from io.netty.channel.ChannelHandler.exceptionCaught.

Gets called if a Throwable was thrown.

Annotations
@Override
fireExceptionCaughtForActiveStreamback to summary
private void fireExceptionCaughtForActiveStream(final Throwable cause) throws Http2Exception
handlerAdded0back to summary
protected void handlerAdded0(ChannelHandlerContext ctx)

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

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

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

Annotations
@Override
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)
processPendingReadCompleteQueueback to summary
private void processPendingReadCompleteQueue()
registerDoneback to summary
pack-priv static void registerDone(ChannelFuture future)
userEventTriggeredback to summary
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.userEventTriggered.

Implements io.netty.channel.ChannelInboundHandler.userEventTriggered.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.userEventTriggered.

Calls ChannelHandlerContext#fireUserEventTriggered(Object) to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
io.netty.handler.codec.http2 back to summary

private final Class Http2MultiplexHandler.Http2MultiplexHandlerStreamChannel

extends AbstractHttp2StreamChannel
Class Inheritance

Field Summary

Inherited from io.netty.handler.codec.http2.AbstractHttp2StreamChannel:
CHANNEL_INPUT_SHUTDOWN_READ_COMPLETE_VISITORCHANNEL_OUTPUT_SHUTDOWN_EVENT_VISITORSSL_CLOSE_COMPLETION_EVENT_VISITORWRITABLE_VISITOR

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
protected boolean
protected ChannelHandlerContext
Inherited from io.netty.handler.codec.http2.AbstractHttp2StreamChannel:
allocbindbindbytesBeforeUnwritablebytesBeforeWritablecloseclosecloseFuturecloseOutboundcloseWithErrorcompareToconfigconnectconnectconnectconnectderegisterderegisterdisconnectdisconnectequalseventLoopfireChildReadfireChildReadCompleteflushflush0hashCodeidisActiveisOpenisRegisteredisWritablelocalAddressmetadatanewFailedFuturenewProgressivePromisenewPromisenewSucceededFutureparentpipelinereadremoteAddressstreamstreamClosedtoStringtrySetWritableunsafevoidPromisewritewritewrite0writeAndFlushwriteAndFlush

Constructor Detail

Http2MultiplexHandlerStreamChannelback to summary
pack-priv Http2MultiplexHandlerStreamChannel(Http2FrameCodec.DefaultHttp2FrameStream stream, ChannelHandler inboundHandler)

Method Detail

addChannelToReadCompletePendingQueueback to summary
protected void addChannelToReadCompletePendingQueue()

Implements abstract io.netty.handler.codec.http2.AbstractHttp2StreamChannel.addChannelToReadCompletePendingQueue.

Annotations
@Override
isParentReadInProgressback to summary
protected boolean isParentReadInProgress()

Implements abstract io.netty.handler.codec.http2.AbstractHttp2StreamChannel.isParentReadInProgress.

Annotations
@Override
parentContextback to summary
protected ChannelHandlerContext parentContext()

Implements abstract io.netty.handler.codec.http2.AbstractHttp2StreamChannel.parentContext.

Annotations
@Override