@UnstableApi public class Http2ConnectionHandler extends io.netty.handler.codec.ByteToMessageDecoder implements Http2LifecycleManager, io.netty.channel.ChannelOutboundHandler
Http2FrameListener
This class will read HTTP/2 frames and delegate the events to a Http2FrameListener
This interface enforces inbound flow control functionality through
Http2LocalFlowController
Modifier | Constructor and Description |
---|---|
protected |
Http2ConnectionHandler(Http2ConnectionDecoder decoder,
Http2ConnectionEncoder encoder,
Http2Settings initialSettings) |
Modifier and Type | Method and Description |
---|---|
void |
bind(io.netty.channel.ChannelHandlerContext ctx,
SocketAddress localAddress,
io.netty.channel.ChannelPromise promise) |
void |
channelActive(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelInactive(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelReadComplete(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx) |
void |
close(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise) |
void |
closeStream(Http2Stream stream,
io.netty.channel.ChannelFuture future)
Closes and deactivates the given
stream . |
void |
closeStreamLocal(Http2Stream stream,
io.netty.channel.ChannelFuture future)
Closes the local side of the given stream.
|
void |
closeStreamRemote(Http2Stream stream,
io.netty.channel.ChannelFuture future)
Closes the remote side of the given stream.
|
void |
connect(io.netty.channel.ChannelHandlerContext ctx,
SocketAddress remoteAddress,
SocketAddress localAddress,
io.netty.channel.ChannelPromise promise) |
Http2Connection |
connection() |
protected void |
decode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
List<Object> out) |
Http2ConnectionDecoder |
decoder() |
void |
deregister(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise) |
void |
disconnect(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise) |
Http2ConnectionEncoder |
encoder() |
void |
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause)
Handles
Http2Exception objects that were thrown from other handlers. |
void |
flush(io.netty.channel.ChannelHandlerContext ctx) |
protected Http2FrameWriter |
frameWriter() |
io.netty.channel.ChannelFuture |
goAway(io.netty.channel.ChannelHandlerContext ctx,
int lastStreamId,
long errorCode,
io.netty.buffer.ByteBuf debugData,
io.netty.channel.ChannelPromise promise)
Prevents the peer from creating streams and close the connection if
errorCode is not
Http2Error.NO_ERROR . |
long |
gracefulShutdownTimeoutMillis()
Get the amount of time (in milliseconds) this endpoint will wait for all streams to be closed before closing
the connection during the graceful shutdown process.
|
void |
gracefulShutdownTimeoutMillis(long gracefulShutdownTimeoutMillis)
Set the amount of time (in milliseconds) this endpoint will wait for all streams to be closed before closing
the connection during the graceful shutdown process.
|
void |
handlerAdded(io.netty.channel.ChannelHandlerContext ctx) |
protected void |
handlerRemoved0(io.netty.channel.ChannelHandlerContext ctx) |
protected void |
handleServerHeaderDecodeSizeError(io.netty.channel.ChannelHandlerContext ctx,
Http2Stream stream)
Notifies client that this server has received headers that are larger than what it is
willing to accept.
|
protected boolean |
isGracefulShutdownComplete()
Called by the graceful shutdown logic to determine when it is safe to close the connection.
|
protected void |
onConnectionError(io.netty.channel.ChannelHandlerContext ctx,
boolean outbound,
Throwable cause,
Http2Exception http2Ex)
Handler for a connection error.
|
void |
onError(io.netty.channel.ChannelHandlerContext ctx,
boolean outbound,
Throwable cause)
Central handler for all exceptions caught during HTTP/2 processing.
|
void |
onHttpClientUpgrade()
Handles the client-side (cleartext) upgrade from HTTP to HTTP/2.
|
void |
onHttpServerUpgrade(Http2Settings settings)
Handles the server-side (cleartext) upgrade from HTTP to HTTP/2.
|
protected void |
onStreamError(io.netty.channel.ChannelHandlerContext ctx,
boolean outbound,
Throwable cause,
Http2Exception.StreamException http2Ex)
Handler for a stream error.
|
void |
read(io.netty.channel.ChannelHandlerContext ctx) |
io.netty.channel.ChannelFuture |
resetStream(io.netty.channel.ChannelHandlerContext ctx,
int streamId,
long errorCode,
io.netty.channel.ChannelPromise promise)
Ensure the stream identified by
streamId is reset. |
void |
write(io.netty.channel.ChannelHandlerContext ctx,
Object msg,
io.netty.channel.ChannelPromise promise) |
actualReadableBytes, callDecode, channelRead, decodeLast, discardSomeReadBytes, handlerRemoved, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggered
channelRegistered, channelUnregistered
protected Http2ConnectionHandler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder, Http2Settings initialSettings)
public long gracefulShutdownTimeoutMillis()
public void gracefulShutdownTimeoutMillis(long gracefulShutdownTimeoutMillis)
gracefulShutdownTimeoutMillis
- the amount of time (in milliseconds) this endpoint will wait for all
streams to be closed before closing the connection during the graceful shutdown process.public Http2Connection connection()
public Http2ConnectionDecoder decoder()
public Http2ConnectionEncoder encoder()
public void onHttpClientUpgrade() throws Http2Exception
Http2Exception
public void onHttpServerUpgrade(Http2Settings settings) throws Http2Exception
settings
- the settings for the remote endpoint.Http2Exception
public void flush(io.netty.channel.ChannelHandlerContext ctx)
flush
in interface io.netty.channel.ChannelOutboundHandler
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws Exception
handlerAdded
in interface io.netty.channel.ChannelHandler
handlerAdded
in class io.netty.channel.ChannelHandlerAdapter
Exception
protected void handlerRemoved0(io.netty.channel.ChannelHandlerContext ctx) throws Exception
handlerRemoved0
in class io.netty.handler.codec.ByteToMessageDecoder
Exception
public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
channelActive
in interface io.netty.channel.ChannelInboundHandler
channelActive
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
channelInactive
in interface io.netty.channel.ChannelInboundHandler
channelInactive
in class io.netty.handler.codec.ByteToMessageDecoder
Exception
public void channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx) throws Exception
channelWritabilityChanged
in interface io.netty.channel.ChannelInboundHandler
channelWritabilityChanged
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
protected void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, List<Object> out) throws Exception
decode
in class io.netty.handler.codec.ByteToMessageDecoder
Exception
public void bind(io.netty.channel.ChannelHandlerContext ctx, SocketAddress localAddress, io.netty.channel.ChannelPromise promise) throws Exception
bind
in interface io.netty.channel.ChannelOutboundHandler
Exception
public void connect(io.netty.channel.ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, io.netty.channel.ChannelPromise promise) throws Exception
connect
in interface io.netty.channel.ChannelOutboundHandler
Exception
public void disconnect(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception
disconnect
in interface io.netty.channel.ChannelOutboundHandler
Exception
public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception
close
in interface io.netty.channel.ChannelOutboundHandler
Exception
public void deregister(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception
deregister
in interface io.netty.channel.ChannelOutboundHandler
Exception
public void read(io.netty.channel.ChannelHandlerContext ctx) throws Exception
read
in interface io.netty.channel.ChannelOutboundHandler
Exception
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception
write
in interface io.netty.channel.ChannelOutboundHandler
Exception
public void channelReadComplete(io.netty.channel.ChannelHandlerContext ctx) throws Exception
channelReadComplete
in interface io.netty.channel.ChannelInboundHandler
channelReadComplete
in class io.netty.handler.codec.ByteToMessageDecoder
Exception
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception
Http2Exception
objects that were thrown from other handlers. Ignores all other exceptions.exceptionCaught
in interface io.netty.channel.ChannelHandler
exceptionCaught
in interface io.netty.channel.ChannelInboundHandler
exceptionCaught
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
public void closeStreamLocal(Http2Stream stream, io.netty.channel.ChannelFuture future)
closeStreamLocal
in interface Http2LifecycleManager
stream
- the stream to be half closed.future
- If closing, the future after which to close the channel.public void closeStreamRemote(Http2Stream stream, io.netty.channel.ChannelFuture future)
closeStreamRemote
in interface Http2LifecycleManager
stream
- the stream to be half closed.future
- If closing, the future after which to close the channel.public void closeStream(Http2Stream stream, io.netty.channel.ChannelFuture future)
Http2LifecycleManager
stream
. A listener is also attached to future
and upon
completion the underlying channel will be closed if Http2Connection.numActiveStreams()
is 0.closeStream
in interface Http2LifecycleManager
stream
- the stream to be closed and deactivated.future
- when completed if Http2Connection.numActiveStreams()
is 0 then the underlying channel
will be closed.public void onError(io.netty.channel.ChannelHandlerContext ctx, boolean outbound, Throwable cause)
onError
in interface Http2LifecycleManager
ctx
- The context used for communication and buffer allocation if necessary.outbound
- true
if the error was caused by an outbound operation and so the corresponding
ChannelPromise
was failed as well.cause
- the error.protected boolean isGracefulShutdownComplete()
true
if the graceful shutdown has completed and the connection can be safely closed. This implementation just
guarantees that there are no active streams. Subclasses may override to provide additional checks.protected void onConnectionError(io.netty.channel.ChannelHandlerContext ctx, boolean outbound, Throwable cause, Http2Exception http2Ex)
ctx
- the channel contextoutbound
- true
if the error was caused by an outbound operation.cause
- the exception that was caughthttp2Ex
- the Http2Exception
that is embedded in the causality chain. This may
be null
if it's an unknown exception.protected void onStreamError(io.netty.channel.ChannelHandlerContext ctx, boolean outbound, Throwable cause, Http2Exception.StreamException http2Ex)
RST_STREAM
frame to the remote endpoint and closes the
stream.ctx
- the channel contextoutbound
- true
if the error was caused by an outbound operation.cause
- the exception that was caughthttp2Ex
- the Http2Exception.StreamException
that is embedded in the causality chain.protected void handleServerHeaderDecodeSizeError(io.netty.channel.ChannelHandlerContext ctx, Http2Stream stream)
ctx
- the channel contextstream
- the Http2Stream on which the header was receivedprotected Http2FrameWriter frameWriter()
public io.netty.channel.ChannelFuture resetStream(io.netty.channel.ChannelHandlerContext ctx, int streamId, long errorCode, io.netty.channel.ChannelPromise promise)
Http2LifecycleManager
streamId
is reset. If our local state does not indicate the stream has
been reset yet then a RST_STREAM
will be sent to the peer. If our local state indicates the stream
has already been reset then the return status will indicate success without sending anything to the peer.resetStream
in interface Http2LifecycleManager
ctx
- The context used for communication and buffer allocation if necessary.streamId
- The identifier of the stream to reset.errorCode
- Justification as to why this stream is being reset. See Http2Error
.promise
- Used to indicate the return status of this operation.RST_STREAM
frame has been sent to the peer. If the stream state has already been updated and a
RST_STREAM
frame has been sent then the return status may indicate success immediately.public io.netty.channel.ChannelFuture goAway(io.netty.channel.ChannelHandlerContext ctx, int lastStreamId, long errorCode, io.netty.buffer.ByteBuf debugData, io.netty.channel.ChannelPromise promise)
Http2LifecycleManager
errorCode
is not
Http2Error.NO_ERROR
. After this call the peer is not allowed to create any new streams and the local
endpoint will be limited to creating streams with stream identifier <= lastStreamId
. This may result in
sending a GO_AWAY
frame (assuming we have not already sent one with
Last-Stream-ID <= lastStreamId
), or may just return success if a GO_AWAY
has previously been
sent.goAway
in interface Http2LifecycleManager
ctx
- The context used for communication and buffer allocation if necessary.lastStreamId
- The last stream that the local endpoint is claiming it will accept.errorCode
- The rational as to why the connection is being closed. See Http2Error
.debugData
- For diagnostic purposes (carries no semantic value).promise
- Used to indicate the return status of this operation.GO_AWAY
frame has been sent to the peer. If the stream state has already been updated and a
GO_AWAY
frame has been sent then the return status may indicate success immediately.Copyright © 2008–2019 The Netty Project. All rights reserved.