@UnstableApi public class DefaultHttp2RemoteFlowController extends java.lang.Object implements Http2RemoteFlowController
Http2RemoteFlowController
.
This class is NOT thread safe. The assumption is all methods must be invoked from a single thread.
Typically this thread is the event loop thread for the ChannelHandlerContext
managed by this class.
Modifier and Type | Class and Description |
---|---|
private class |
DefaultHttp2RemoteFlowController.FlowState
The remote flow control state for a single stream.
|
private class |
DefaultHttp2RemoteFlowController.ListenerWritabilityMonitor
Writability of a
stream is calculated using the following: |
private class |
DefaultHttp2RemoteFlowController.WritabilityMonitor
Abstract class which provides common functionality for writability monitor implementations.
|
Http2RemoteFlowController.FlowControlled, Http2RemoteFlowController.Listener
Modifier and Type | Field and Description |
---|---|
private Http2Connection |
connection |
private DefaultHttp2RemoteFlowController.FlowState |
connectionState |
private ChannelHandlerContext |
ctx |
private int |
initialWindowSize |
private static InternalLogger |
logger |
private static int |
MIN_WRITABLE_CHUNK |
private DefaultHttp2RemoteFlowController.WritabilityMonitor |
monitor |
private Http2Connection.PropertyKey |
stateKey |
private StreamByteDistributor |
streamByteDistributor |
Constructor and Description |
---|
DefaultHttp2RemoteFlowController(Http2Connection connection) |
DefaultHttp2RemoteFlowController(Http2Connection connection,
Http2RemoteFlowController.Listener listener) |
DefaultHttp2RemoteFlowController(Http2Connection connection,
StreamByteDistributor streamByteDistributor) |
DefaultHttp2RemoteFlowController(Http2Connection connection,
StreamByteDistributor streamByteDistributor,
Http2RemoteFlowController.Listener listener) |
Modifier and Type | Method and Description |
---|---|
void |
addFlowControlled(Http2Stream stream,
Http2RemoteFlowController.FlowControlled frame)
Queues a payload for transmission to the remote endpoint.
|
ChannelHandlerContext |
channelHandlerContext()
Get the
ChannelHandlerContext for which to apply flow control on. |
void |
channelHandlerContext(ChannelHandlerContext ctx)
Set the
ChannelHandlerContext for which to apply flow control on. |
void |
channelWritabilityChanged()
Notification that the writability of
Http2RemoteFlowController.channelHandlerContext() has changed. |
private int |
connectionWindowSize()
Returns the flow control window for the entire connection.
|
boolean |
hasFlowControlled(Http2Stream stream)
Determine if
stream has any Http2RemoteFlowController.FlowControlled frames currently queued. |
void |
incrementWindowSize(Http2Stream stream,
int delta)
Increments the size of the stream's flow control window by the given delta.
|
int |
initialWindowSize()
Gets the connection-wide initial flow control window size that is used as the basis for new stream flow
control windows.
|
void |
initialWindowSize(int newWindowSize)
Sets the connection-wide initial flow control window and updates all stream windows (but not the connection
stream window) by the delta.
|
private boolean |
isChannelWritable() |
private boolean |
isChannelWritable0() |
boolean |
isWritable(Http2Stream stream)
Determine if the
stream has bytes remaining for use in the flow control window. |
void |
listener(Http2RemoteFlowController.Listener listener)
Set the active listener on the flow-controller.
|
private int |
maxUsableChannelBytes() |
private int |
minUsableChannelBytes() |
private DefaultHttp2RemoteFlowController.FlowState |
state(Http2Stream stream) |
void |
updateDependencyTree(int childStreamId,
int parentStreamId,
short weight,
boolean exclusive)
Explicitly update the dependency tree.
|
int |
windowSize(Http2Stream stream)
Get the portion of the flow control window for the given stream that is currently available for sending/receiving
frames which are subject to flow control.
|
private int |
writableBytes()
The amount of bytes that can be supported by underlying
Channel without
queuing "too-much". |
void |
writePendingBytes()
Write all data pending in the flow controller up to the flow-control limits.
|
private static final InternalLogger logger
private static final int MIN_WRITABLE_CHUNK
private final Http2Connection connection
private final Http2Connection.PropertyKey stateKey
private final StreamByteDistributor streamByteDistributor
private final DefaultHttp2RemoteFlowController.FlowState connectionState
private int initialWindowSize
private DefaultHttp2RemoteFlowController.WritabilityMonitor monitor
private ChannelHandlerContext ctx
public DefaultHttp2RemoteFlowController(Http2Connection connection)
public DefaultHttp2RemoteFlowController(Http2Connection connection, StreamByteDistributor streamByteDistributor)
public DefaultHttp2RemoteFlowController(Http2Connection connection, Http2RemoteFlowController.Listener listener)
public DefaultHttp2RemoteFlowController(Http2Connection connection, StreamByteDistributor streamByteDistributor, Http2RemoteFlowController.Listener listener)
public void channelHandlerContext(ChannelHandlerContext ctx) throws Http2Exception
ChannelHandlerContext
for which to apply flow control on.
This must be called to properly initialize the Http2FlowController
.
Not calling this is considered a programming error.
Any queued FlowControlled
objects will be sent.
channelHandlerContext
in interface Http2FlowController
ctx
- The ChannelHandlerContext
for which to apply flow control on.Http2Exception
- if any protocol-related error occurred.public ChannelHandlerContext channelHandlerContext()
Http2RemoteFlowController
ChannelHandlerContext
for which to apply flow control on.
This is intended for us by Http2RemoteFlowController.FlowControlled
implementations only. Use with caution.
channelHandlerContext
in interface Http2RemoteFlowController
ChannelHandlerContext
for which to apply flow control on.public void initialWindowSize(int newWindowSize) throws Http2Exception
Http2FlowController
Represents the value for
SETTINGS_INITIAL_WINDOW_SIZE. This method should
only be called by Netty (not users) as a result of a receiving a SETTINGS
frame.
initialWindowSize
in interface Http2FlowController
newWindowSize
- the new initial window size.Http2Exception
- thrown if any protocol-related error occurred.public int initialWindowSize()
Http2FlowController
Represents the value for
SETTINGS_INITIAL_WINDOW_SIZE. The initial value
returned by this method must be Http2CodecUtil.DEFAULT_WINDOW_SIZE
.
initialWindowSize
in interface Http2FlowController
public int windowSize(Http2Stream stream)
Http2FlowController
windowSize
in interface Http2FlowController
public boolean isWritable(Http2Stream stream)
Http2RemoteFlowController
stream
has bytes remaining for use in the flow control window.
Note that this only takes into account HTTP/2 flow control. It does not take into account
the underlying Channel.isWritable()
.
isWritable
in interface Http2RemoteFlowController
stream
- The stream to test.true
if if the stream
has bytes remaining for use in the flow control window.
false
otherwise.public void channelWritabilityChanged() throws Http2Exception
Http2RemoteFlowController
Http2RemoteFlowController.channelHandlerContext()
has changed.channelWritabilityChanged
in interface Http2RemoteFlowController
Http2Exception
- If any writes occur as a result of this call and encounter errors.public void updateDependencyTree(int childStreamId, int parentStreamId, short weight, boolean exclusive)
Http2RemoteFlowController
updateDependencyTree
in interface Http2RemoteFlowController
childStreamId
- The stream identifier associated with the child stream.parentStreamId
- The stream identifier associated with the parent stream. May be 0
,
to make childStreamId
and immediate child of the connection.weight
- The weight which is used relative to other child streams for parentStreamId
. This value
must be between 1 and 256 (inclusive).exclusive
- If childStreamId
should be the exclusive dependency of parentStreamId
.private boolean isChannelWritable()
private boolean isChannelWritable0()
public void listener(Http2RemoteFlowController.Listener listener)
Http2RemoteFlowController
listener
in interface Http2RemoteFlowController
listener
- to notify when the a write occurs, can be null
.public void incrementWindowSize(Http2Stream stream, int delta) throws Http2Exception
Http2FlowController
In the case of a Http2RemoteFlowController
this is called upon receipt of a
WINDOW_UPDATE
frame from the remote endpoint to mirror the changes to the window
size.
For a Http2LocalFlowController
this can be called to request the expansion of the
window size published by this endpoint. It is up to the implementation, however, as to when a
WINDOW_UPDATE
is actually sent.
incrementWindowSize
in interface Http2FlowController
stream
- The subject stream. Use Http2Connection.connectionStream()
for
requesting the size of the connection window.delta
- the change in size of the flow control window.Http2Exception
- thrown if a protocol-related error occurred.public void addFlowControlled(Http2Stream stream, Http2RemoteFlowController.FlowControlled frame)
Http2RemoteFlowController
Writes do not actually occur until Http2RemoteFlowController.writePendingBytes()
is called.
addFlowControlled
in interface Http2RemoteFlowController
stream
- the subject stream. Must not be the connection stream object.frame
- payload to write subject to flow-control accounting and ordering rules.public boolean hasFlowControlled(Http2Stream stream)
Http2RemoteFlowController
stream
has any Http2RemoteFlowController.FlowControlled
frames currently queued.hasFlowControlled
in interface Http2RemoteFlowController
stream
- the stream to check if it has flow controlled frames.true
if stream
has any Http2RemoteFlowController.FlowControlled
frames currently queued.private DefaultHttp2RemoteFlowController.FlowState state(Http2Stream stream)
private int connectionWindowSize()
private int minUsableChannelBytes()
private int maxUsableChannelBytes()
private int writableBytes()
Channel
without
queuing "too-much".public void writePendingBytes() throws Http2Exception
Http2RemoteFlowController
writePendingBytes
in interface Http2RemoteFlowController
Http2Exception
- throws if a protocol-related error occurred.