Class DefaultHttp2RemoteFlowController
- java.lang.Object
-
- io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController
-
- All Implemented Interfaces:
Http2FlowController,Http2RemoteFlowController
public class DefaultHttp2RemoteFlowController extends java.lang.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
ChannelHandlerContextmanaged by this class.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty.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 voidaddFlowControlled(Http2Stream stream, Http2RemoteFlowController.FlowControlled frame)Queues a payload for transmission to the remote endpoint.ChannelHandlerContextchannelHandlerContext()Get theChannelHandlerContextfor which to apply flow control on.voidchannelHandlerContext(ChannelHandlerContext ctx)Set theChannelHandlerContextfor which to apply flow control on.voidchannelWritabilityChanged()Notification that the writability ofHttp2RemoteFlowController.channelHandlerContext()has changed.booleanhasFlowControlled(Http2Stream stream)Determine ifstreamhas anyHttp2RemoteFlowController.FlowControlledframes currently queued.voidincrementWindowSize(Http2Stream stream, int delta)Increments the size of the stream's flow control window by the given delta.intinitialWindowSize()Gets the connection-wide initial flow control window size that is used as the basis for new stream flow control windows.voidinitialWindowSize(int newWindowSize)Sets the connection-wide initial flow control window and updates all stream windows (but not the connection stream window) by the delta.booleanisWritable(Http2Stream stream)Determine if thestreamhas bytes remaining for use in the flow control window.voidlistener(Http2RemoteFlowController.Listener listener)Set the active listener on the flow-controller.voidupdateDependencyTree(int childStreamId, int parentStreamId, short weight, boolean exclusive)Explicitly update the dependency tree.intwindowSize(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.voidwritePendingBytes()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 theChannelHandlerContextfor 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.FlowControlledobjects will be sent.- Specified by:
channelHandlerContextin interfaceHttp2FlowController- Parameters:
ctx- TheChannelHandlerContextfor which to apply flow control on.- Throws:
Http2Exception- if any protocol-related error occurred.
-
channelHandlerContext
public ChannelHandlerContext channelHandlerContext()
Description copied from interface:Http2RemoteFlowControllerGet theChannelHandlerContextfor which to apply flow control on.This is intended for us by
Http2RemoteFlowController.FlowControlledimplementations only. Use with caution.- Specified by:
channelHandlerContextin interfaceHttp2RemoteFlowController- Returns:
- The
ChannelHandlerContextfor which to apply flow control on.
-
initialWindowSize
public void initialWindowSize(int newWindowSize) throws Http2ExceptionDescription copied from interface:Http2FlowControllerSets 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
SETTINGSframe.- Specified by:
initialWindowSizein 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:Http2FlowControllerGets 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:
initialWindowSizein interfaceHttp2FlowController
-
windowSize
public int windowSize(Http2Stream stream)
Description copied from interface:Http2FlowControllerGet 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:
windowSizein interfaceHttp2FlowController
-
isWritable
public boolean isWritable(Http2Stream stream)
Description copied from interface:Http2RemoteFlowControllerDetermine if thestreamhas 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:
isWritablein interfaceHttp2RemoteFlowController- Parameters:
stream- The stream to test.- Returns:
trueif thestreamhas bytes remaining for use in the flow control window and the channel is writable,falseotherwise.
-
channelWritabilityChanged
public void channelWritabilityChanged() throws Http2ExceptionDescription copied from interface:Http2RemoteFlowControllerNotification that the writability ofHttp2RemoteFlowController.channelHandlerContext()has changed.- Specified by:
channelWritabilityChangedin 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:Http2RemoteFlowControllerExplicitly update the dependency tree. This method is called independently of stream state changes.- Specified by:
updateDependencyTreein interfaceHttp2RemoteFlowController- Parameters:
childStreamId- The stream identifier associated with the child stream.parentStreamId- The stream identifier associated with the parent stream. May be0, to makechildStreamIdand 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- IfchildStreamIdshould be the exclusive dependency ofparentStreamId.
-
listener
public void listener(Http2RemoteFlowController.Listener listener)
Description copied from interface:Http2RemoteFlowControllerSet the active listener on the flow-controller.- Specified by:
listenerin 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:Http2FlowControllerIncrements the size of the stream's flow control window by the given delta.In the case of a
Http2RemoteFlowControllerthis is called upon receipt of aWINDOW_UPDATEframe from the remote endpoint to mirror the changes to the window size.For a
Http2LocalFlowControllerthis 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_UPDATEis actually sent.- Specified by:
incrementWindowSizein 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:Http2RemoteFlowControllerQueues 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:
addFlowControlledin 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:Http2RemoteFlowControllerDetermine ifstreamhas anyHttp2RemoteFlowController.FlowControlledframes currently queued.- Specified by:
hasFlowControlledin interfaceHttp2RemoteFlowController- Parameters:
stream- the stream to check if it has flow controlled frames.- Returns:
trueifstreamhas anyHttp2RemoteFlowController.FlowControlledframes currently queued.
-
writePendingBytes
public void writePendingBytes() throws Http2ExceptionDescription copied from interface:Http2RemoteFlowControllerWrite all data pending in the flow controller up to the flow-control limits.- Specified by:
writePendingBytesin interfaceHttp2RemoteFlowController- Throws:
Http2Exception- throws if a protocol-related error occurred.
-
-