Class StreamBufferingEncoder
- java.lang.Object
- 
- io.netty.handler.codec.http2.DecoratingHttp2FrameWriter
- 
- io.netty.handler.codec.http2.DecoratingHttp2ConnectionEncoder
- 
- io.netty.handler.codec.http2.StreamBufferingEncoder
 
 
 
- 
- All Implemented Interfaces:
- Http2ConnectionEncoder,- Http2DataWriter,- Http2FrameWriter,- Http2SettingsReceivedConsumer,- java.io.Closeable,- java.lang.AutoCloseable
 
 public class StreamBufferingEncoder extends DecoratingHttp2ConnectionEncoder Implementation of aHttp2ConnectionEncoderthat dispatches all method call to anotherHttp2ConnectionEncoder, untilSETTINGS_MAX_CONCURRENT_STREAMSis reached.When this limit is hit, instead of rejecting any new streams this implementation buffers newly created streams and their corresponding frames. Once an active stream gets closed or the maximum number of concurrent streams is increased, this encoder will automatically try to empty its buffer and create as many new streams as possible. If a GOAWAYframe is received from the remote endpoint, all buffered writes for streams with an ID less than the specifiedlastStreamIdwill immediately fail with aStreamBufferingEncoder.Http2GoAwayException.If the channel/encoder gets closed, all new and buffered writes will immediately fail with a StreamBufferingEncoder.Http2ChannelClosedException.This implementation makes the buffering mostly transparent and is expected to be used as a drop-in decorator of DefaultHttp2ConnectionEncoder.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classStreamBufferingEncoder.Http2ChannelClosedExceptionThrown if buffered streams are terminated due to this encoder being closed.static classStreamBufferingEncoder.Http2GoAwayExceptionThrown byStreamBufferingEncoderif buffered streams are terminated due to receipt of aGOAWAY.- 
Nested classes/interfaces inherited from interface io.netty.handler.codec.http2.Http2FrameWriterHttp2FrameWriter.Configuration
 
- 
 - 
Constructor SummaryConstructors Constructor Description StreamBufferingEncoder(Http2ConnectionEncoder delegate)StreamBufferingEncoder(Http2ConnectionEncoder delegate, int initialMaxConcurrentStreams)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this writer and frees any allocated resources.intnumBufferedStreams()Indicates the number of streams that are currently buffered, awaiting creation.voidremoteSettings(Http2Settings settings)Sets the settings for the remote endpoint of the HTTP/2 connection.ChannelFuturewriteData(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream, ChannelPromise promise)Writes aDATAframe to the remote endpoint.ChannelFuturewriteHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream, ChannelPromise promise)Writes a HEADERS frame to the remote endpoint.ChannelFuturewriteHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endOfStream, ChannelPromise promise)Writes a HEADERS frame with priority specified to the remote endpoint.ChannelFuturewriteRstStream(ChannelHandlerContext ctx, int streamId, long errorCode, ChannelPromise promise)Writes a RST_STREAM frame to the remote endpoint.ChannelFuturewriteSettingsAck(ChannelHandlerContext ctx, ChannelPromise promise)Writes a SETTINGS acknowledgment to the remote endpoint.- 
Methods inherited from class io.netty.handler.codec.http2.DecoratingHttp2ConnectionEncoderconnection, consumeReceivedSettings, flowController, frameWriter, lifecycleManager, pollSentSettings
 - 
Methods inherited from class io.netty.handler.codec.http2.DecoratingHttp2FrameWriterconfiguration, writeFrame, writeGoAway, writePing, writePriority, writePushPromise, writeSettings, writeWindowUpdate
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface io.netty.handler.codec.http2.Http2ConnectionEncoderwriteFrame
 - 
Methods inherited from interface io.netty.handler.codec.http2.Http2FrameWriterconfiguration, writeGoAway, writePing, writePriority, writePushPromise, writeSettings, writeWindowUpdate
 
- 
 
- 
- 
- 
Constructor Detail- 
StreamBufferingEncoderpublic StreamBufferingEncoder(Http2ConnectionEncoder delegate) 
 - 
StreamBufferingEncoderpublic StreamBufferingEncoder(Http2ConnectionEncoder delegate, int initialMaxConcurrentStreams) 
 
- 
 - 
Method Detail- 
numBufferedStreamspublic int numBufferedStreams() Indicates the number of streams that are currently buffered, awaiting creation.
 - 
writeHeaderspublic ChannelFuture writeHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream, ChannelPromise promise) Description copied from interface:Http2FrameWriterWrites a HEADERS frame to the remote endpoint.- Specified by:
- writeHeadersin interface- Http2FrameWriter
- Overrides:
- writeHeadersin class- DecoratingHttp2FrameWriter
- Parameters:
- ctx- the context to use for writing.
- streamId- the stream for which to send the frame.
- headers- the headers to be sent.
- padding- additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).
- endStream- indicates if this is the last frame to be sent for the stream.
- promise- the promise for the write.
- Returns:
- the future for the write.
 Section 10.5.1 states the following:
 The header block MUST be processed to ensure a consistent connection state, unless the connection is closed. If this call has modified the HPACK header state you MUST throw a connection error.If this call has NOT modified the HPACK header state you are free to throw a stream error. 
 
 - 
writeHeaderspublic ChannelFuture writeHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endOfStream, ChannelPromise promise) Description copied from interface:Http2FrameWriterWrites a HEADERS frame with priority specified to the remote endpoint.- Specified by:
- writeHeadersin interface- Http2FrameWriter
- Overrides:
- writeHeadersin class- DecoratingHttp2FrameWriter
- Parameters:
- ctx- the context to use for writing.
- streamId- the stream for which to send the frame.
- headers- the headers to be sent.
- streamDependency- the stream on which this stream should depend, or 0 if it should depend on the connection.
- weight- the weight for this stream.
- exclusive- whether this stream should be the exclusive dependant of its parent.
- padding- additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).
- endOfStream- indicates if this is the last frame to be sent for the stream.
- promise- the promise for the write.
- Returns:
- the future for the write.
 Section 10.5.1 states the following:
 The header block MUST be processed to ensure a consistent connection state, unless the connection is closed. If this call has modified the HPACK header state you MUST throw a connection error.If this call has NOT modified the HPACK header state you are free to throw a stream error. 
 
 - 
writeRstStreampublic ChannelFuture writeRstStream(ChannelHandlerContext ctx, int streamId, long errorCode, ChannelPromise promise) Description copied from interface:Http2FrameWriterWrites a RST_STREAM frame to the remote endpoint.- Specified by:
- writeRstStreamin interface- Http2FrameWriter
- Overrides:
- writeRstStreamin class- DecoratingHttp2FrameWriter
- Parameters:
- ctx- the context to use for writing.
- streamId- the stream for which to send the frame.
- errorCode- the error code indicating the nature of the failure.
- promise- the promise for the write.
- Returns:
- the future for the write.
 
 - 
writeDatapublic ChannelFuture writeData(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream, ChannelPromise promise) Description copied from interface:Http2DataWriterWrites aDATAframe to the remote endpoint. This will result in one or more frames being written to the context.- Specified by:
- writeDatain interface- Http2DataWriter
- Overrides:
- writeDatain class- DecoratingHttp2FrameWriter
- Parameters:
- ctx- the context to use for writing.
- streamId- the stream for which to send the frame.
- data- the payload of the frame. This will be released by this method.
- padding- additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive). A 1 byte padding is encoded as just the pad length field with value 0. A 256 byte padding is encoded as the pad length field with value 255 and 255 padding bytes appended to the end of the frame.
- endOfStream- indicates if this is the last frame to be sent for the stream.
- promise- the promise for the write.
- Returns:
- the future for the write.
 
 - 
writeSettingsAckpublic ChannelFuture writeSettingsAck(ChannelHandlerContext ctx, ChannelPromise promise) Description copied from interface:Http2FrameWriterWrites a SETTINGS acknowledgment to the remote endpoint.- Specified by:
- writeSettingsAckin interface- Http2FrameWriter
- Overrides:
- writeSettingsAckin class- DecoratingHttp2FrameWriter
- Parameters:
- ctx- the context to use for writing.
- promise- the promise for the write.
- Returns:
- the future for the write.
 
 - 
remoteSettingspublic void remoteSettings(Http2Settings settings) throws Http2Exception Description copied from interface:Http2ConnectionEncoderSets the settings for the remote endpoint of the HTTP/2 connection.- Specified by:
- remoteSettingsin interface- Http2ConnectionEncoder
- Overrides:
- remoteSettingsin class- DecoratingHttp2ConnectionEncoder
- Throws:
- Http2Exception
 
 - 
closepublic void close() Description copied from interface:Http2FrameWriterCloses this writer and frees any allocated resources.- Specified by:
- closein interface- java.lang.AutoCloseable
- Specified by:
- closein interface- java.io.Closeable
- Specified by:
- closein interface- Http2FrameWriter
- Overrides:
- closein class- DecoratingHttp2FrameWriter
 
 
- 
 
-