@UnstableApi public final class Http2MultiplexCodec extends ChannelDuplexHandler
When a new stream is created, a new Channel
is created for it. Applications send and
receive Http2StreamFrame
s on the created channel. ByteBuf
s 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, write
channelActive, channelInactive, channelRegistered, channelUnregistered, channelWritabilityChanged
ensureNotSharable, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handlerRemoved
private 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)
ChannelHandlerAdapter
handlerAdded
in interface ChannelHandler
handlerAdded
in class ChannelHandlerAdapter
public void exceptionCaught(ChannelHandlerContext ctx, java.lang.Throwable cause)
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireExceptionCaught(Throwable)
to forward
to the next ChannelHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.exceptionCaught
in interface ChannelHandler
exceptionCaught
in interface ChannelInboundHandler
exceptionCaught
in class ChannelInboundHandlerAdapter
public void flush(ChannelHandlerContext ctx)
ChannelDuplexHandler
ChannelHandlerContext.flush()
to forward
to the next ChannelOutboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.flush
in interface ChannelOutboundHandler
flush
in class ChannelDuplexHandler
ctx
- the ChannelHandlerContext
for which the flush operation is madepublic void channelRead(ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelRead(Object)
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelRead
in interface ChannelInboundHandler
channelRead
in class ChannelInboundHandlerAdapter
java.lang.Exception
private void fireChildReadAndRegister(Http2MultiplexCodec.Http2StreamChannel childChannel, Http2StreamFrame frame)
public void userEventTriggered(ChannelHandlerContext ctx, java.lang.Object evt) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireUserEventTriggered(Object)
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.userEventTriggered
in interface ChannelInboundHandler
userEventTriggered
in class ChannelInboundHandlerAdapter
java.lang.Exception
private 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 ChannelInboundHandler
channelReadComplete
in class ChannelInboundHandlerAdapter
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)
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)