@UnstableApi public final class Http2MultiplexCodec extends ChannelDuplexHandler
When a new stream is created, a new Channel 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.
Outbound streams are supported via the Http2StreamChannelBootstrap.
ChannelConfig.setMaxMessagesPerRead(int) and ChannelConfig.setAutoRead(boolean) are supported.
| Modifier and Type | Class and Description |
|---|---|
private static class |
Http2MultiplexCodec.ChannelCarryingHeadersFrame
Wraps the first
Http2HeadersFrame of local/outbound stream. |
(package private) class |
Http2MultiplexCodec.Http2StreamChannel |
ChannelHandler.Sharable| Modifier and Type | Field and Description |
|---|---|
private Http2StreamChannelBootstrap |
bootstrap |
private java.util.List<Http2MultiplexCodec.Http2StreamChannel> |
channelsToFireChildReadComplete |
private IntObjectMap<Http2MultiplexCodec.Http2StreamChannel> |
childChannels |
private ChannelHandlerContext |
ctx |
private java.lang.Runnable |
flushTask |
private static InternalLogger |
logger |
private boolean |
server |
| Constructor and Description |
|---|
Http2MultiplexCodec(boolean server,
Http2StreamChannelBootstrap bootstrap)
Construct a new handler whose child channels run in a different event loop.
|
| Modifier and Type | Method and Description |
|---|---|
void |
channelRead(ChannelHandlerContext ctx,
java.lang.Object msg)
Calls
ChannelHandlerContext.fireChannelRead(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline. |
void |
channelReadComplete(ChannelHandlerContext ctx)
Notifies any child streams of the read completion.
|
(package private) ChannelFuture |
createStreamChannel(Channel parentChannel,
EventLoopGroup group,
ChannelHandler handler,
java.util.Map<ChannelOption<?>,java.lang.Object> options,
java.util.Map<AttributeKey<?>,java.lang.Object> attrs,
int streamId) |
void |
exceptionCaught(ChannelHandlerContext ctx,
java.lang.Throwable cause)
Calls
ChannelHandlerContext.fireExceptionCaught(Throwable) to forward
to the next ChannelHandler in the ChannelPipeline. |
private void |
fireChildReadAndRegister(Http2MultiplexCodec.Http2StreamChannel childChannel,
Http2StreamFrame frame) |
void |
flush(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.flush() to forward
to the next ChannelOutboundHandler in the ChannelPipeline. |
(package private) void |
flushFromStreamChannel() |
void |
handlerAdded(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
private static void |
initAttrs(Channel channel,
java.util.Map<AttributeKey<?>,java.lang.Object> attrs) |
private static void |
initOpts(Channel channel,
java.util.Map<ChannelOption<?>,java.lang.Object> opts) |
private void |
onStreamActive(int streamId,
Http2HeadersFrame headersFrame) |
private void |
onStreamClosed(int streamId) |
private void |
onStreamClosed0(Http2MultiplexCodec.Http2StreamChannel childChannel) |
void |
userEventTriggered(ChannelHandlerContext ctx,
java.lang.Object evt)
Calls
ChannelHandlerContext.fireUserEventTriggered(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline. |
(package private) void |
writeFromStreamChannel(java.lang.Object msg,
boolean flush) |
(package private) void |
writeFromStreamChannel(java.lang.Object msg,
ChannelPromise promise,
boolean flush) |
private void |
writeFromStreamChannel0(java.lang.Object msg,
boolean flush,
ChannelPromise promise) |
bind, close, connect, deregister, disconnect, read, writechannelActive, channelInactive, channelRegistered, channelUnregistered, channelWritabilityChangedensureNotSharable, handlerRemoved, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithandlerRemovedprivate static final InternalLogger logger
private final Http2StreamChannelBootstrap bootstrap
private final java.util.List<Http2MultiplexCodec.Http2StreamChannel> channelsToFireChildReadComplete
private final boolean server
private ChannelHandlerContext ctx
private volatile java.lang.Runnable flushTask
private final IntObjectMap<Http2MultiplexCodec.Http2StreamChannel> childChannels
public Http2MultiplexCodec(boolean server,
Http2StreamChannelBootstrap bootstrap)
server - true this is a serverbootstrap - bootstrap used to instantiate child channels for remotely-created streams.public void handlerAdded(ChannelHandlerContext ctx)
ChannelHandlerAdapterhandlerAdded in interface ChannelHandlerhandlerAdded in class ChannelHandlerAdapterpublic void exceptionCaught(ChannelHandlerContext ctx, java.lang.Throwable cause)
ChannelInboundHandlerAdapterChannelHandlerContext.fireExceptionCaught(Throwable) to forward
to the next ChannelHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.exceptionCaught in interface ChannelHandlerexceptionCaught in interface ChannelInboundHandlerexceptionCaught in class ChannelInboundHandlerAdapterpublic void flush(ChannelHandlerContext ctx)
ChannelDuplexHandlerChannelHandlerContext.flush() to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.flush in interface ChannelOutboundHandlerflush in class ChannelDuplexHandlerctx - the ChannelHandlerContext for which the flush operation is madepublic void channelRead(ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
ChannelInboundHandlerAdapterChannelHandlerContext.fireChannelRead(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.channelRead in interface ChannelInboundHandlerchannelRead in class ChannelInboundHandlerAdapterjava.lang.Exceptionprivate void fireChildReadAndRegister(Http2MultiplexCodec.Http2StreamChannel childChannel, Http2StreamFrame frame)
public void userEventTriggered(ChannelHandlerContext ctx, java.lang.Object evt) throws java.lang.Exception
ChannelInboundHandlerAdapterChannelHandlerContext.fireUserEventTriggered(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.userEventTriggered in interface ChannelInboundHandleruserEventTriggered in class ChannelInboundHandlerAdapterjava.lang.Exceptionprivate void onStreamActive(int streamId,
Http2HeadersFrame headersFrame)
private void onStreamClosed(int streamId)
private void onStreamClosed0(Http2MultiplexCodec.Http2StreamChannel childChannel)
void flushFromStreamChannel()
void writeFromStreamChannel(java.lang.Object msg,
boolean flush)
void writeFromStreamChannel(java.lang.Object msg,
ChannelPromise promise,
boolean flush)
private void writeFromStreamChannel0(java.lang.Object msg,
boolean flush,
ChannelPromise promise)
public void channelReadComplete(ChannelHandlerContext ctx)
channelReadComplete in interface ChannelInboundHandlerchannelReadComplete in class ChannelInboundHandlerAdapterChannelFuture createStreamChannel(Channel parentChannel, EventLoopGroup group, ChannelHandler handler, java.util.Map<ChannelOption<?>,java.lang.Object> options, java.util.Map<AttributeKey<?>,java.lang.Object> attrs, int streamId)
private static void initOpts(Channel channel, java.util.Map<ChannelOption<?>,java.lang.Object> opts)
private static void initAttrs(Channel channel, java.util.Map<AttributeKey<?>,java.lang.Object> attrs)