Class DefaultHttp2RemoteFlowController
- java.lang.Object
-
- io.netty5.handler.codec.http2.DefaultHttp2RemoteFlowController
-
- All Implemented Interfaces:
Http2FlowController
,Http2RemoteFlowController
@UnstableApi public class DefaultHttp2RemoteFlowController extends Object implements Http2RemoteFlowController
Basic implementation ofHttp2RemoteFlowController
.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty5.handler.codec.http2.Http2RemoteFlowController
Http2RemoteFlowController.FlowControlled, Http2RemoteFlowController.Listener
-
-
Constructor Summary
Constructors Constructor Description DefaultHttp2RemoteFlowController(Http2Connection connection)
DefaultHttp2RemoteFlowController(Http2Connection connection, Http2RemoteFlowController.Listener listener)
DefaultHttp2RemoteFlowController(Http2Connection connection, StreamByteDistributor streamByteDistributor)
DefaultHttp2RemoteFlowController(Http2Connection connection, StreamByteDistributor streamByteDistributor, Http2RemoteFlowController.Listener listener)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFlowControlled(Http2Stream stream, Http2RemoteFlowController.FlowControlled frame)
Queues a payload for transmission to the remote endpoint.ChannelHandlerContext
channelHandlerContext()
Get theChannelHandlerContext
for which to apply flow control on.void
channelHandlerContext(ChannelHandlerContext ctx)
Set theChannelHandlerContext
for which to apply flow control on.void
channelWritabilityChanged()
Notification that the writability ofHttp2RemoteFlowController.channelHandlerContext()
has changed.boolean
hasFlowControlled(Http2Stream stream)
Determine ifstream
has anyHttp2RemoteFlowController.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.boolean
isWritable(Http2Stream stream)
Determine if thestream
has bytes remaining for use in the flow control window.void
listener(Http2RemoteFlowController.Listener listener)
Set the active listener on the flow-controller.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.void
writePendingBytes()
Write all data pending in the flow controller up to the flow-control limits.
-
-
-
Constructor Detail
-
DefaultHttp2RemoteFlowController
public DefaultHttp2RemoteFlowController(Http2Connection connection)
-
DefaultHttp2RemoteFlowController
public DefaultHttp2RemoteFlowController(Http2Connection connection, StreamByteDistributor streamByteDistributor)
-
DefaultHttp2RemoteFlowController
public DefaultHttp2RemoteFlowController(Http2Connection connection, Http2RemoteFlowController.Listener listener)
-
DefaultHttp2RemoteFlowController
public DefaultHttp2RemoteFlowController(Http2Connection connection, StreamByteDistributor streamByteDistributor, Http2RemoteFlowController.Listener listener)
-
-
Method Detail
-
channelHandlerContext
public void channelHandlerContext(ChannelHandlerContext ctx) throws Http2Exception
Set theChannelHandlerContext
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
Http2RemoteFlowController.FlowControlled
objects will be sent.- Specified by:
channelHandlerContext
in interfaceHttp2FlowController
- Parameters:
ctx
- TheChannelHandlerContext
for which to apply flow control on.- Throws:
Http2Exception
- if any protocol-related error occurred.
-
channelHandlerContext
public ChannelHandlerContext channelHandlerContext()
Description copied from interface:Http2RemoteFlowController
Get theChannelHandlerContext
for which to apply flow control on.This is intended for us by
Http2RemoteFlowController.FlowControlled
implementations only. Use with caution.- Specified by:
channelHandlerContext
in interfaceHttp2RemoteFlowController
- Returns:
- The
ChannelHandlerContext
for which to apply flow control on.
-
initialWindowSize
public void initialWindowSize(int newWindowSize) throws Http2Exception
Description copied from interface:Http2FlowController
Sets the connection-wide initial flow control window and updates all stream windows (but not the connection stream window) by the delta.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.- Specified by:
initialWindowSize
in interfaceHttp2FlowController
- Parameters:
newWindowSize
- the new initial window size.- Throws:
Http2Exception
- thrown if any protocol-related error occurred.
-
initialWindowSize
public int initialWindowSize()
Description copied from interface:Http2FlowController
Gets the connection-wide initial flow control window size that is used as the basis for new stream flow control windows.Represents the value for SETTINGS_INITIAL_WINDOW_SIZE. The initial value returned by this method must be
Http2CodecUtil.DEFAULT_WINDOW_SIZE
.- Specified by:
initialWindowSize
in interfaceHttp2FlowController
-
windowSize
public int windowSize(Http2Stream stream)
Description copied from interface:Http2FlowController
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. This quantity is measured in number of bytes.- Specified by:
windowSize
in interfaceHttp2FlowController
-
isWritable
public boolean isWritable(Http2Stream stream)
Description copied from interface:Http2RemoteFlowController
Determine if thestream
has bytes remaining for use in the flow control window.Note that this method respects channel writability. The channel must be writable for this method to return
true
.- Specified by:
isWritable
in interfaceHttp2RemoteFlowController
- Parameters:
stream
- The stream to test.- Returns:
true
if thestream
has bytes remaining for use in the flow control window and the channel is writable,false
otherwise.
-
channelWritabilityChanged
public void channelWritabilityChanged() throws Http2Exception
Description copied from interface:Http2RemoteFlowController
Notification that the writability ofHttp2RemoteFlowController.channelHandlerContext()
has changed.- Specified by:
channelWritabilityChanged
in interfaceHttp2RemoteFlowController
- Throws:
Http2Exception
- If any writes occur as a result of this call and encounter errors.
-
updateDependencyTree
public void updateDependencyTree(int childStreamId, int parentStreamId, short weight, boolean exclusive)
Description copied from interface:Http2RemoteFlowController
Explicitly update the dependency tree. This method is called independently of stream state changes.- Specified by:
updateDependencyTree
in interfaceHttp2RemoteFlowController
- Parameters:
childStreamId
- The stream identifier associated with the child stream.parentStreamId
- The stream identifier associated with the parent stream. May be0
, to makechildStreamId
and immediate child of the connection.weight
- The weight which is used relative to other child streams forparentStreamId
. This value must be between 1 and 256 (inclusive).exclusive
- IfchildStreamId
should be the exclusive dependency ofparentStreamId
.
-
listener
public void listener(Http2RemoteFlowController.Listener listener)
Description copied from interface:Http2RemoteFlowController
Set the active listener on the flow-controller.- Specified by:
listener
in interfaceHttp2RemoteFlowController
- Parameters:
listener
- to notify when the a write occurs, can benull
.
-
incrementWindowSize
public void incrementWindowSize(Http2Stream stream, int delta) throws Http2Exception
Description copied from interface:Http2FlowController
Increments the size of the stream's flow control window by the given delta.In the case of a
Http2RemoteFlowController
this is called upon receipt of aWINDOW_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 aWINDOW_UPDATE
is actually sent.- Specified by:
incrementWindowSize
in interfaceHttp2FlowController
- Parameters:
stream
- The subject stream. UseHttp2Connection.connectionStream()
for requesting the size of the connection window.delta
- the change in size of the flow control window.- Throws:
Http2Exception
- thrown if a protocol-related error occurred.
-
addFlowControlled
public void addFlowControlled(Http2Stream stream, Http2RemoteFlowController.FlowControlled frame)
Description copied from interface:Http2RemoteFlowController
Queues a payload for transmission to the remote endpoint. There is no guarantee as to when the data will be written or how it will be assigned to frames. before sending.Writes do not actually occur until
Http2RemoteFlowController.writePendingBytes()
is called.- Specified by:
addFlowControlled
in interfaceHttp2RemoteFlowController
- Parameters:
stream
- the subject stream. Must not be the connection stream object.frame
- payload to write subject to flow-control accounting and ordering rules.
-
hasFlowControlled
public boolean hasFlowControlled(Http2Stream stream)
Description copied from interface:Http2RemoteFlowController
Determine ifstream
has anyHttp2RemoteFlowController.FlowControlled
frames currently queued.- Specified by:
hasFlowControlled
in interfaceHttp2RemoteFlowController
- Parameters:
stream
- the stream to check if it has flow controlled frames.- Returns:
true
ifstream
has anyHttp2RemoteFlowController.FlowControlled
frames currently queued.
-
writePendingBytes
public void writePendingBytes() throws Http2Exception
Description copied from interface:Http2RemoteFlowController
Write all data pending in the flow controller up to the flow-control limits.- Specified by:
writePendingBytes
in interfaceHttp2RemoteFlowController
- Throws:
Http2Exception
- throws if a protocol-related error occurred.
-
-