Top Description Inners Fields Constructors Methods
io.netty5.handler.codec.http2

public Class StreamBufferingEncoder

extends DecoratingHttp2ConnectionEncoder
Class Inheritance
Annotations
@UnstableApi
Imports
io.netty5.buffer.BufferUtil, .Buffer, io.netty5.channel.ChannelHandlerContext, io.netty5.handler.codec.http2.headers.Http2Headers, io.netty5.util.concurrent.Future, .Promise, io.netty5.util.internal.SilentDispose, .UnstableApi, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.util.ArrayDeque, .Iterator, .Map, .Queue, .TreeMap

Implementation of a Http2ConnectionEncoder that dispatches all method call to another Http2ConnectionEncoder, until SETTINGS_MAX_CONCURRENT_STREAMS is 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 GOAWAY frame is received from the remote endpoint, all buffered writes for streams with an ID less than the specified lastStreamId will immediately fail with a Http2GoAwayException.

If the channel/encoder gets closed, all new and buffered writes will immediately fail with a Http2ChannelClosedException.

This implementation makes the buffering mostly transparent and is expected to be used as a drop-in decorator of DefaultHttp2ConnectionEncoder.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private abstract static class
private static class
private class
public static class
StreamBufferingEncoder.Http2ChannelClosedException

Thrown if buffered streams are terminated due to this encoder being closed.

public static class
StreamBufferingEncoder.Http2GoAwayException

Thrown by StreamBufferingEncoder if buffered streams are terminated due to receipt of a GOAWAY.

private static class

Field Summary

Modifier and TypeField and Description
private boolean
private StreamBufferingEncoder.GoAwayDetail
private static final InternalLogger
private int
private final TreeMap<Integer, StreamBufferingEncoder.PendingStream>
pendingStreams

Buffer for any streams and corresponding frames that could not be created due to the maximum concurrent stream limit being hit.

Constructor Summary

AccessConstructor and Description
public
public
StreamBufferingEncoder(Http2ConnectionEncoder delegate, int initialMaxConcurrentStreams)

Method Summary

Modifier and TypeMethod and Description
private void
private boolean
canCreateStream()

Determines whether or not we're allowed to create a new stream right now.

public void
close()

Overrides io.netty5.handler.codec.http2.DecoratingHttp2FrameWriter.close.

Implements io.netty5.handler.codec.http2.Http2FrameWriter.close.

Closes this writer and frees any allocated resources.
private boolean
isExistingStream(int streamId)

public int
numBufferedStreams()

Indicates the number of streams that are currently buffered, awaiting creation.

public void
private void
public Future<Void>
writeData(ChannelHandlerContext
the context to use for writing.
ctx
,
int
the stream for which to send the frame.
streamId
,
Buffer
the payload of the frame. This will be released by this method.
data
,
int
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.
padding
,
boolean
indicates if this is the last frame to be sent for the stream.
endOfStream
)

Overrides io.netty5.handler.codec.http2.DecoratingHttp2FrameWriter.writeData.

Implements io.netty5.handler.codec.http2.Http2DataWriter.writeData.

Writes a DATA frame to the remote endpoint.
public Future<Void>
writeHeaders(ChannelHandlerContext
the context to use for writing.
ctx
,
int
the stream for which to send the frame.
streamId
,
Http2Headers
the headers to be sent.
headers
,
int
additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).
padding
,
boolean
indicates if this is the last frame to be sent for the stream.
endStream
)

Overrides io.netty5.handler.codec.http2.DecoratingHttp2FrameWriter.writeHeaders.

Implements io.netty5.handler.codec.http2.Http2FrameWriter.writeHeaders.

Writes a HEADERS frame to the remote endpoint.
public Future<Void>
writeHeaders(ChannelHandlerContext
the context to use for writing.
ctx
,
int
the stream for which to send the frame.
streamId
,
Http2Headers
the headers to be sent.
headers
,
int
the stream on which this stream should depend, or 0 if it should depend on the connection.
streamDependency
,
short
the weight for this stream.
weight
,
boolean
whether this stream should be the exclusive dependant of its parent.
exclusive
,
int
additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).
padding
,
boolean
indicates if this is the last frame to be sent for the stream.
endOfStream
)

Overrides io.netty5.handler.codec.http2.DecoratingHttp2FrameWriter.writeHeaders.

Implements io.netty5.handler.codec.http2.Http2FrameWriter.writeHeaders.

Writes a HEADERS frame with priority specified to the remote endpoint.
public Future<Void>
writeRstStream(ChannelHandlerContext
the context to use for writing.
ctx
,
int
the stream for which to send the frame.
streamId
,
long
the error code indicating the nature of the failure.
errorCode
)

Overrides io.netty5.handler.codec.http2.DecoratingHttp2FrameWriter.writeRstStream.

Implements io.netty5.handler.codec.http2.Http2FrameWriter.writeRstStream.

Writes a RST_STREAM frame to the remote endpoint.
Inherited from io.netty5.handler.codec.http2.DecoratingHttp2ConnectionEncoder:
connectionconsumeReceivedSettingsflowControllerframeWriterlifecycleManagerpollSentSettings

Field Detail

closedback to summary
private boolean closed
goAwayDetailback to summary
private StreamBufferingEncoder.GoAwayDetail goAwayDetail
loggerback to summary
private static final InternalLogger logger
maxConcurrentStreamsback to summary
private int maxConcurrentStreams
pendingStreamsback to summary
private final TreeMap<Integer, StreamBufferingEncoder.PendingStream> pendingStreams

Buffer for any streams and corresponding frames that could not be created due to the maximum concurrent stream limit being hit.

Constructor Detail

StreamBufferingEncoderback to summary
public StreamBufferingEncoder(Http2ConnectionEncoder delegate)
StreamBufferingEncoderback to summary
public StreamBufferingEncoder(Http2ConnectionEncoder delegate, int initialMaxConcurrentStreams)

Method Detail

cancelGoAwayStreamsback to summary
private void cancelGoAwayStreams(StreamBufferingEncoder.GoAwayDetail goAwayDetail)
canCreateStreamback to summary
private boolean canCreateStream()

Determines whether or not we're allowed to create a new stream right now.

closeback to summary
public void close()

Overrides io.netty5.handler.codec.http2.DecoratingHttp2FrameWriter.close.

Implements io.netty5.handler.codec.http2.Http2FrameWriter.close.

Doc from io.netty5.handler.codec.http2.Http2FrameWriter.close.

Closes this writer and frees any allocated resources.

Annotations
@Override
isExistingStreamback to summary
private boolean isExistingStream(int streamId)
numBufferedStreamsback to summary
public int numBufferedStreams()

Indicates the number of streams that are currently buffered, awaiting creation.

remoteSettingsback to summary
public void remoteSettings(Http2Settings settings) throws Http2Exception

Overrides io.netty5.handler.codec.http2.DecoratingHttp2ConnectionEncoder.remoteSettings.

Implements io.netty5.handler.codec.http2.Http2ConnectionEncoder.remoteSettings.

Doc from io.netty5.handler.codec.http2.Http2ConnectionEncoder.remoteSettings.

Sets the settings for the remote endpoint of the HTTP/2 connection.

Annotations
@Override
tryCreatePendingStreamsback to summary
private void tryCreatePendingStreams()
writeDataback to summary
public Future<Void> writeData(ChannelHandlerContext ctx, int streamId, Buffer data, int padding, boolean endOfStream)

Overrides io.netty5.handler.codec.http2.DecoratingHttp2FrameWriter.writeData.

Implements io.netty5.handler.codec.http2.Http2DataWriter.writeData.

Doc from io.netty5.handler.codec.http2.Http2DataWriter.writeData.

Writes a DATA frame to the remote endpoint. This will result in one or more frames being written to the context.

Parameters
ctx:ChannelHandlerContext

the context to use for writing.

streamId:int

the stream for which to send the frame.

data:Buffer

the payload of the frame. This will be released by this method.

padding:int

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:boolean

indicates if this is the last frame to be sent for the stream.

Returns:Future<Void>

the future for the write.

Annotations
@Override
writeHeadersback to summary
public Future<Void> writeHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream)

Overrides io.netty5.handler.codec.http2.DecoratingHttp2FrameWriter.writeHeaders.

Implements io.netty5.handler.codec.http2.Http2FrameWriter.writeHeaders.

Doc from io.netty5.handler.codec.http2.Http2FrameWriter.writeHeaders.

Writes a HEADERS frame to the remote endpoint.

Parameters
ctx:ChannelHandlerContext

the context to use for writing.

streamId:int

the stream for which to send the frame.

headers:Http2Headers

the headers to be sent.

padding:int

additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).

endStream:boolean

indicates if this is the last frame to be sent for the stream.

Returns:Future<Void>

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.

Annotations
@Override
writeHeadersback to summary
public Future<Void> writeHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endOfStream)

Overrides io.netty5.handler.codec.http2.DecoratingHttp2FrameWriter.writeHeaders.

Implements io.netty5.handler.codec.http2.Http2FrameWriter.writeHeaders.

Doc from io.netty5.handler.codec.http2.Http2FrameWriter.writeHeaders.

Writes a HEADERS frame with priority specified to the remote endpoint.

Parameters
ctx:ChannelHandlerContext

the context to use for writing.

streamId:int

the stream for which to send the frame.

headers:Http2Headers

the headers to be sent.

streamDependency:int

the stream on which this stream should depend, or 0 if it should depend on the connection.

weight:short

the weight for this stream.

exclusive:boolean

whether this stream should be the exclusive dependant of its parent.

padding:int

additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).

endOfStream:boolean

indicates if this is the last frame to be sent for the stream.

Returns:Future<Void>

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.

Annotations
@Override
writeRstStreamback to summary
public Future<Void> writeRstStream(ChannelHandlerContext ctx, int streamId, long errorCode)

Overrides io.netty5.handler.codec.http2.DecoratingHttp2FrameWriter.writeRstStream.

Implements io.netty5.handler.codec.http2.Http2FrameWriter.writeRstStream.

Doc from io.netty5.handler.codec.http2.Http2FrameWriter.writeRstStream.

Writes a RST_STREAM frame to the remote endpoint.

Parameters
ctx:ChannelHandlerContext

the context to use for writing.

streamId:int

the stream for which to send the frame.

errorCode:long

the error code indicating the nature of the failure.

Returns:Future<Void>

the future for the write.

Annotations
@Override
io.netty5.handler.codec.http2 back to summary

private final Class StreamBufferingEncoder.DataFrame

extends Frame
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final Buffer
pack-priv final boolean
pack-priv final int
Inherited from io.netty5.handler.codec.http2.StreamBufferingEncoder.Frame:
promise

Constructor Summary

AccessConstructor and Description
pack-priv
DataFrame(Buffer data, int padding, boolean endOfStream, Promise<Void> promise)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
release(Throwable t)

Overrides io.netty5.handler.codec.http2.StreamBufferingEncoder.Frame.release.

Release any resources (features, buffers, ...) associated with the frame.
pack-priv void

Field Detail

databack to summary
pack-priv final Buffer data
endOfStreamback to summary
pack-priv final boolean endOfStream
paddingback to summary
pack-priv final int padding

Constructor Detail

DataFrameback to summary
pack-priv DataFrame(Buffer data, int padding, boolean endOfStream, Promise<Void> promise)

Method Detail

releaseback to summary
pack-priv void release(Throwable t)

Overrides io.netty5.handler.codec.http2.StreamBufferingEncoder.Frame.release.

Doc from io.netty5.handler.codec.http2.StreamBufferingEncoder.Frame.release.

Release any resources (features, buffers, ...) associated with the frame.

Annotations
@Override
sendback to summary
pack-priv void send(ChannelHandlerContext ctx, int streamId)

Implements abstract io.netty5.handler.codec.http2.StreamBufferingEncoder.Frame.send.

Annotations
@Override
io.netty5.handler.codec.http2 back to summary

private abstract Class StreamBufferingEncoder.Frame

extends Object
Class Inheritance
Known Direct Subclasses
io.netty5.handler.codec.http2.StreamBufferingEncoder.HeadersFrame, io.netty5.handler.codec.http2.StreamBufferingEncoder.DataFrame

Field Summary

Modifier and TypeField and Description
pack-priv final Promise<Void>

Constructor Summary

AccessConstructor and Description
pack-priv
Frame(Promise<Void> promise)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
release(Throwable t)

Release any resources (features, buffers, ...) associated with the frame.

pack-priv abstract void
send(ChannelHandlerContext ctx, int streamId)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

promiseback to summary
pack-priv final Promise<Void> promise

Constructor Detail

Frameback to summary
pack-priv Frame(Promise<Void> promise)

Method Detail

releaseback to summary
pack-priv void release(Throwable t)

Release any resources (features, buffers, ...) associated with the frame.

sendback to summary
pack-priv abstract void send(ChannelHandlerContext ctx, int streamId)
io.netty5.handler.codec.http2 back to summary

private final Class StreamBufferingEncoder.GoAwayDetail

extends Object
Class Inheritance
  • java.lang.Object
  • io.netty5.handler.codec.http2.StreamBufferingEncoder.GoAwayDetail

Field Summary

Modifier and TypeField and Description
private final byte[]
private final long
private final int

Constructor Summary

AccessConstructor and Description
pack-priv
GoAwayDetail(int lastStreamId, long errorCode, byte[] debugData)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

debugDataback to summary
private final byte[] debugData
errorCodeback to summary
private final long errorCode
lastStreamIdback to summary
private final int lastStreamId

Constructor Detail

GoAwayDetailback to summary
pack-priv GoAwayDetail(int lastStreamId, long errorCode, byte[] debugData)
io.netty5.handler.codec.http2 back to summary

private final Class StreamBufferingEncoder.HeadersFrame

extends Frame
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final boolean
pack-priv final boolean
pack-priv final Http2Headers
pack-priv final int
pack-priv final int
pack-priv final short
Inherited from io.netty5.handler.codec.http2.StreamBufferingEncoder.Frame:
promise

Constructor Summary

AccessConstructor and Description
pack-priv
HeadersFrame(Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endOfStream, Promise<Void> promise)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
Inherited from io.netty5.handler.codec.http2.StreamBufferingEncoder.Frame:
release

Field Detail

endOfStreamback to summary
pack-priv final boolean endOfStream
exclusiveback to summary
pack-priv final boolean exclusive
headersback to summary
pack-priv final Http2Headers headers
paddingback to summary
pack-priv final int padding
streamDependencyback to summary
pack-priv final int streamDependency
weightback to summary
pack-priv final short weight

Constructor Detail

HeadersFrameback to summary
pack-priv HeadersFrame(Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endOfStream, Promise<Void> promise)

Method Detail

sendback to summary
pack-priv void send(ChannelHandlerContext ctx, int streamId)

Implements abstract io.netty5.handler.codec.http2.StreamBufferingEncoder.Frame.send.

Annotations
@Override
io.netty5.handler.codec.http2 back to summary

public final Class StreamBufferingEncoder.Http2ChannelClosedException

extends Http2Exception
Class Inheritance

Thrown if buffered streams are terminated due to this encoder being closed.

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from io.netty5.handler.codec.http2.Http2Exception:
closedStreamErrorconnectionErrorconnectionErrorerrorheaderListSizeErrorisStreamErrornewStaticshutdownHintstreamErrorstreamErrorstreamId

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides io.netty5.handler.codec.http2.Http2Exception.serialVersionUID.

Constructor Detail

Http2ChannelClosedExceptionback to summary
public Http2ChannelClosedException()
io.netty5.handler.codec.http2 back to summary

public final Class StreamBufferingEncoder.Http2GoAwayException

extends Http2Exception
Class Inheritance

Thrown by StreamBufferingEncoder if buffered streams are terminated due to receipt of a GOAWAY.

Field Summary

Modifier and TypeField and Description
private final StreamBufferingEncoder.GoAwayDetail
private static final long

Constructor Summary

AccessConstructor and Description
public
Http2GoAwayException(int lastStreamId, long errorCode, byte[] debugData)

pack-priv

Method Summary

Modifier and TypeMethod and Description
public byte[]
public long
public int
Inherited from io.netty5.handler.codec.http2.Http2Exception:
closedStreamErrorconnectionErrorconnectionErrorerrorheaderListSizeErrorisStreamErrornewStaticshutdownHintstreamErrorstreamErrorstreamId

Field Detail

goAwayDetailback to summary
private final StreamBufferingEncoder.GoAwayDetail goAwayDetail
serialVersionUIDback to summary
private static final long serialVersionUID

Hides io.netty5.handler.codec.http2.Http2Exception.serialVersionUID.

Constructor Detail

Http2GoAwayExceptionback to summary
public Http2GoAwayException(int lastStreamId, long errorCode, byte[] debugData)
Http2GoAwayExceptionback to summary
pack-priv Http2GoAwayException(StreamBufferingEncoder.GoAwayDetail goAwayDetail)

Method Detail

debugDataback to summary
public byte[] debugData()
errorCodeback to summary
public long errorCode()
lastStreamIdback to summary
public int lastStreamId()
io.netty5.handler.codec.http2 back to summary

private final Class StreamBufferingEncoder.PendingStream

extends Object
Class Inheritance
  • java.lang.Object
  • io.netty5.handler.codec.http2.StreamBufferingEncoder.PendingStream

Field Summary

Modifier and TypeField and Description
pack-priv final ChannelHandlerContext
pack-priv final Queue<StreamBufferingEncoder.Frame>
pack-priv final int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ctxback to summary
pack-priv final ChannelHandlerContext ctx
framesback to summary
pack-priv final Queue<StreamBufferingEncoder.Frame> frames
streamIdback to summary
pack-priv final int streamId

Constructor Detail

PendingStreamback to summary
pack-priv PendingStream(ChannelHandlerContext ctx, int streamId)

Method Detail

closeback to summary
pack-priv void close(Throwable t)
sendFramesback to summary
pack-priv void sendFrames()