Class Http2EventAdapter
- java.lang.Object
-
- io.netty.handler.codec.http2.Http2EventAdapter
-
- All Implemented Interfaces:
Http2Connection.Listener,Http2FrameListener
- Direct Known Subclasses:
InboundHttp2ToHttpAdapter
public class Http2EventAdapter extends java.lang.Object implements Http2Connection.Listener, Http2FrameListener
This class bringsHttp2Connection.ListenerandHttp2FrameListenertogether to provide NOOP implementation so inheriting classes can selectively choose which methods to override.
-
-
Constructor Summary
Constructors Constructor Description Http2EventAdapter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intonDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream)Handles an inboundDATAframe.voidonGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData)Handles an inboundGO_AWAYframe.voidonGoAwayReceived(int lastStreamId, long errorCode, ByteBuf debugData)Called when aGOAWAYwas received from the remote endpoint.voidonGoAwaySent(int lastStreamId, long errorCode, ByteBuf debugData)Called when aGOAWAYframe was sent for the connection.voidonHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream)Handles an inboundHEADERSframe.voidonHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream)Handles an inboundHEADERSframe with priority information specified.voidonPingAckRead(ChannelHandlerContext ctx, long data)Handles an inboundPINGacknowledgment.voidonPingRead(ChannelHandlerContext ctx, long data)Handles an inboundPINGframe.voidonPriorityRead(ChannelHandlerContext ctx, int streamId, int streamDependency, short weight, boolean exclusive)Handles an inboundPRIORITYframe.voidonPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding)Handles an inboundPUSH_PROMISEframe.voidonRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode)Handles an inboundRST_STREAMframe.voidonSettingsAckRead(ChannelHandlerContext ctx)Handles an inboundSETTINGSacknowledgment frame.voidonSettingsRead(ChannelHandlerContext ctx, Http2Settings settings)Handles an inboundSETTINGSframe.voidonStreamActive(Http2Stream stream)Notifies the listener that the given stream was made active (i.e.voidonStreamAdded(Http2Stream stream)Notifies the listener that the given stream was added to the connection.voidonStreamClosed(Http2Stream stream)Notifies the listener that the given stream is nowCLOSEDin both directions and will no longer be accessible viaHttp2Connection.forEachActiveStream(Http2StreamVisitor).voidonStreamHalfClosed(Http2Stream stream)Notifies the listener that the given stream has transitioned fromOPENtoHALF CLOSED.voidonStreamRemoved(Http2Stream stream)Notifies the listener that the given stream has now been removed from the connection and will no longer be returned viaHttp2Connection.stream(int).voidonUnknownFrame(ChannelHandlerContext ctx, byte frameType, int streamId, Http2Flags flags, ByteBuf payload)Handler for a frame not defined by the HTTP/2 spec.voidonWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement)Handles an inboundWINDOW_UPDATEframe.
-
-
-
Method Detail
-
onDataRead
public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundDATAframe.- Specified by:
onDataReadin interfaceHttp2FrameListener- Parameters:
ctx- the context from the handler where the frame was read.streamId- the subject stream for the frame.data- payload buffer for the frame. This buffer will be released by the codec.padding- additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).endOfStream- Indicates whether this is the last frame to be sent from the remote endpoint for this stream.- Returns:
- the number of bytes that have been processed by the application. The returned bytes are used by the
inbound flow controller to determine the appropriate time to expand the inbound flow control window (i.e. send
WINDOW_UPDATE). Returning a value equal to the length ofdata+paddingwill effectively opt-out of application-level flow control for this frame. Returning a value less than the length ofdata+paddingwill defer the returning of the processed bytes, which the application must later return viaHttp2LocalFlowController.consumeBytes(Http2Stream, int). The returned value must be >=0and <=data.readableBytes()+padding. - Throws:
Http2Exception
-
onHeadersRead
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundHEADERSframe.Only one of the following methods will be called for each
HEADERSframe sequence. One will be called when theEND_HEADERSflag has been received.Http2FrameListener.onHeadersRead(ChannelHandlerContext, int, Http2Headers, int, boolean)Http2FrameListener.onHeadersRead(ChannelHandlerContext, int, Http2Headers, int, short, boolean, int, boolean)Http2FrameListener.onPushPromiseRead(ChannelHandlerContext, int, int, Http2Headers, int)
To say it another way; the
Http2Headerswill contain all of the headers for the current message exchange step (additional queuing is not necessary).- Specified by:
onHeadersReadin interfaceHttp2FrameListener- Parameters:
ctx- the context from the handler where the frame was read.streamId- the subject stream for the frame.headers- the received headers.padding- additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).endStream- Indicates whether this is the last frame to be sent from the remote endpoint for this stream.- Throws:
Http2Exception
-
onHeadersRead
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundHEADERSframe with priority information specified. Only called ifEND_HEADERSencountered.Only one of the following methods will be called for each
HEADERSframe sequence. One will be called when theEND_HEADERSflag has been received.Http2FrameListener.onHeadersRead(ChannelHandlerContext, int, Http2Headers, int, boolean)Http2FrameListener.onHeadersRead(ChannelHandlerContext, int, Http2Headers, int, short, boolean, int, boolean)Http2FrameListener.onPushPromiseRead(ChannelHandlerContext, int, int, Http2Headers, int)
To say it another way; the
Http2Headerswill contain all of the headers for the current message exchange step (additional queuing is not necessary).- Specified by:
onHeadersReadin interfaceHttp2FrameListener- Parameters:
ctx- the context from the handler where the frame was read.streamId- the subject stream for the frame.headers- the received headers.streamDependency- the stream on which this stream depends, or 0 if dependent on the connection.weight- the new weight for the stream.exclusive- whether or not the stream should be the exclusive dependent of its parent.padding- additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).endStream- Indicates whether this is the last frame to be sent from the remote endpoint for this stream.- Throws:
Http2Exception
-
onPriorityRead
public void onPriorityRead(ChannelHandlerContext ctx, int streamId, int streamDependency, short weight, boolean exclusive) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundPRIORITYframe.Note that is it possible to have this method called and no stream object exist for either
streamId,streamDependency, or both. This is because thePRIORITYframe can be sent/received when streams are in theCLOSEDstate.- Specified by:
onPriorityReadin interfaceHttp2FrameListener- Parameters:
ctx- the context from the handler where the frame was read.streamId- the subject stream for the frame.streamDependency- the stream on which this stream depends, or 0 if dependent on the connection.weight- the new weight for the stream.exclusive- whether or not the stream should be the exclusive dependent of its parent.- Throws:
Http2Exception
-
onRstStreamRead
public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundRST_STREAMframe.- Specified by:
onRstStreamReadin interfaceHttp2FrameListener- Parameters:
ctx- the context from the handler where the frame was read.streamId- the stream that is terminating.errorCode- the error code identifying the type of failure.- Throws:
Http2Exception
-
onSettingsAckRead
public void onSettingsAckRead(ChannelHandlerContext ctx) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundSETTINGSacknowledgment frame.- Specified by:
onSettingsAckReadin interfaceHttp2FrameListener- Parameters:
ctx- the context from the handler where the frame was read.- Throws:
Http2Exception
-
onSettingsRead
public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundSETTINGSframe.- Specified by:
onSettingsReadin interfaceHttp2FrameListener- Parameters:
ctx- the context from the handler where the frame was read.settings- the settings received from the remote endpoint.- Throws:
Http2Exception
-
onPingRead
public void onPingRead(ChannelHandlerContext ctx, long data) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundPINGframe.- Specified by:
onPingReadin interfaceHttp2FrameListener- Parameters:
ctx- the context from the handler where the frame was read.data- the payload of the frame.- Throws:
Http2Exception
-
onPingAckRead
public void onPingAckRead(ChannelHandlerContext ctx, long data) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundPINGacknowledgment.- Specified by:
onPingAckReadin interfaceHttp2FrameListener- Parameters:
ctx- the context from the handler where the frame was read.data- the payload of the frame.- Throws:
Http2Exception
-
onPushPromiseRead
public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundPUSH_PROMISEframe. Only called ifEND_HEADERSencountered.Promised requests MUST be authoritative, cacheable, and safe. See [RFC 7540], Section 8.2.
Only one of the following methods will be called for each
HEADERSframe sequence. One will be called when theEND_HEADERSflag has been received.Http2FrameListener.onHeadersRead(ChannelHandlerContext, int, Http2Headers, int, boolean)Http2FrameListener.onHeadersRead(ChannelHandlerContext, int, Http2Headers, int, short, boolean, int, boolean)Http2FrameListener.onPushPromiseRead(ChannelHandlerContext, int, int, Http2Headers, int)
To say it another way; the
Http2Headerswill contain all of the headers for the current message exchange step (additional queuing is not necessary).- Specified by:
onPushPromiseReadin interfaceHttp2FrameListener- Parameters:
ctx- the context from the handler where the frame was read.streamId- the stream the frame was sent on.promisedStreamId- the ID of the promised stream.headers- the received headers.padding- additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).- Throws:
Http2Exception
-
onGoAwayRead
public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundGO_AWAYframe.- Specified by:
onGoAwayReadin interfaceHttp2FrameListener- Parameters:
ctx- the context from the handler where the frame was read.lastStreamId- the last known stream of the remote endpoint.errorCode- the error code, if abnormal closure.debugData- application-defined debug data. If this buffer needs to be retained by the listener they must make a copy.- Throws:
Http2Exception
-
onWindowUpdateRead
public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundWINDOW_UPDATEframe.- Specified by:
onWindowUpdateReadin interfaceHttp2FrameListener- Parameters:
ctx- the context from the handler where the frame was read.streamId- the stream the frame was sent on.windowSizeIncrement- the increased number of bytes of the remote endpoint's flow control window.- Throws:
Http2Exception
-
onUnknownFrame
public void onUnknownFrame(ChannelHandlerContext ctx, byte frameType, int streamId, Http2Flags flags, ByteBuf payload) throws Http2Exception
Description copied from interface:Http2FrameListenerHandler for a frame not defined by the HTTP/2 spec.- Specified by:
onUnknownFramein interfaceHttp2FrameListener- Parameters:
ctx- the context from the handler where the frame was read.frameType- the frame type from the HTTP/2 header.streamId- the stream the frame was sent on.flags- the flags in the frame header.payload- the payload of the frame.- Throws:
Http2Exception
-
onStreamAdded
public void onStreamAdded(Http2Stream stream)
Description copied from interface:Http2Connection.ListenerNotifies the listener that the given stream was added to the connection. This stream may not yet be active (i.e.OPENorHALF CLOSED).If a
RuntimeExceptionis thrown it will be logged and not propagated. Throwing from this method is not supported and is considered a programming error.- Specified by:
onStreamAddedin interfaceHttp2Connection.Listener
-
onStreamActive
public void onStreamActive(Http2Stream stream)
Description copied from interface:Http2Connection.ListenerNotifies the listener that the given stream was made active (i.e.OPENorHALF CLOSED).If a
RuntimeExceptionis thrown it will be logged and not propagated. Throwing from this method is not supported and is considered a programming error.- Specified by:
onStreamActivein interfaceHttp2Connection.Listener
-
onStreamHalfClosed
public void onStreamHalfClosed(Http2Stream stream)
Description copied from interface:Http2Connection.ListenerNotifies the listener that the given stream has transitioned fromOPENtoHALF CLOSED. This method will not be called until a state transition occurs from whenHttp2Connection.Listener.onStreamActive(Http2Stream)was called. The stream can be inspected to determine which side isHALF CLOSED.If a
RuntimeExceptionis thrown it will be logged and not propagated. Throwing from this method is not supported and is considered a programming error.- Specified by:
onStreamHalfClosedin interfaceHttp2Connection.Listener
-
onStreamClosed
public void onStreamClosed(Http2Stream stream)
Description copied from interface:Http2Connection.ListenerNotifies the listener that the given stream is nowCLOSEDin both directions and will no longer be accessible viaHttp2Connection.forEachActiveStream(Http2StreamVisitor).If a
RuntimeExceptionis thrown it will be logged and not propagated. Throwing from this method is not supported and is considered a programming error.- Specified by:
onStreamClosedin interfaceHttp2Connection.Listener
-
onStreamRemoved
public void onStreamRemoved(Http2Stream stream)
Description copied from interface:Http2Connection.ListenerNotifies the listener that the given stream has now been removed from the connection and will no longer be returned viaHttp2Connection.stream(int). The connection may maintain inactive streams for some time before removing them.If a
RuntimeExceptionis thrown it will be logged and not propagated. Throwing from this method is not supported and is considered a programming error.- Specified by:
onStreamRemovedin interfaceHttp2Connection.Listener
-
onGoAwaySent
public void onGoAwaySent(int lastStreamId, long errorCode, ByteBuf debugData)Description copied from interface:Http2Connection.ListenerCalled when aGOAWAYframe was sent for the connection.If a
RuntimeExceptionis thrown it will be logged and not propagated. Throwing from this method is not supported and is considered a programming error.- Specified by:
onGoAwaySentin interfaceHttp2Connection.Listener- Parameters:
lastStreamId- the last known stream of the remote endpoint.errorCode- the error code, if abnormal closure.debugData- application-defined debug data.
-
onGoAwayReceived
public void onGoAwayReceived(int lastStreamId, long errorCode, ByteBuf debugData)Description copied from interface:Http2Connection.ListenerCalled when aGOAWAYwas received from the remote endpoint. This event handler duplicatesHttp2FrameListener.onGoAwayRead(io.netty.channel.ChannelHandlerContext, int, long, ByteBuf)but is added here in order to simplify application logic for handlingGOAWAYin a uniform way. An application should generally not handle both events, but if it does this method is called second, after notifying theHttp2FrameListener.If a
RuntimeExceptionis thrown it will be logged and not propagated. Throwing from this method is not supported and is considered a programming error.- Specified by:
onGoAwayReceivedin interfaceHttp2Connection.Listener- Parameters:
lastStreamId- the last known stream of the remote endpoint.errorCode- the error code, if abnormal closure.debugData- application-defined debug data.
-
-