Package io.netty.handler.codec.http2
Class DefaultHttp2RemoteFlowController.FlowState
- java.lang.Object
-
- io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController.FlowState
-
- All Implemented Interfaces:
StreamByteDistributor.StreamState
- Enclosing class:
- DefaultHttp2RemoteFlowController
private final class DefaultHttp2RemoteFlowController.FlowState extends java.lang.Object implements StreamByteDistributor.StreamState
The remote flow control state for a single stream.
-
-
Field Summary
Fields Modifier and Type Field Description private booleancancelledSet to true if cancel() was called.private booleanmarkedWritableprivate longpendingBytesprivate java.util.Deque<Http2RemoteFlowController.FlowControlled>pendingWriteQueueprivate Http2Streamstreamprivate intwindowprivate booleanwritingSet to true while a frame is being written, false otherwise.
-
Constructor Summary
Constructors Constructor Description FlowState(Http2Stream stream)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidcancel(Http2Error error, java.lang.Throwable cause)Clears the pending queue and writes errors for each remaining frame.private voiddecrementFlowControlWindow(int bytes)Decrement the per stream and connection flow control window bybytes.private voiddecrementPendingBytes(int bytes, boolean updateStreamableBytes)If this frame is in the pending queue, decrements the number of pending bytes for the stream.(package private) voidenqueueFrame(Http2RemoteFlowController.FlowControlled frame)Adds theframeto the pending queue and increments the pending byte count.private voidenqueueFrameWithoutMerge(Http2RemoteFlowController.FlowControlled frame)booleanhasFrame()Indicates whether or not there are frames pending for this stream.private voidincrementPendingBytes(int numBytes, boolean updateStreamableBytes)Increments the number of pending bytes for this node and optionally updates theStreamByteDistributor.(package private) intincrementStreamWindow(int delta)Increments the flow control window for this stream by the given delta and returns the new value.(package private) booleanisWritable()Determine if the stream associated with this object is writable.(package private) booleanmarkedWritability()Returns the parameter from the last call tomarkedWritability(boolean).(package private) voidmarkedWritability(boolean isWritable)Save the state of writability.private Http2RemoteFlowController.FlowControlledpeek()Returns the head of the pending queue, ornullif empty.longpendingBytes()Get the amount of bytes this stream has pending to send.Http2Streamstream()The stream this state is associated with.intwindowSize()The size (in bytes) of the stream's flow control window.(package private) voidwindowSize(int initialWindowSize)Reset the window size for this stream.private intwritableWindow()Returns the maximum writable window (minimum of the stream and connection windows).(package private) intwriteAllocatedBytes(int allocated)Write the allocated bytes for this stream.private voidwriteError(Http2RemoteFlowController.FlowControlled frame, Http2Exception cause)Discards thisHttp2RemoteFlowController.FlowControlled, writing an error.
-
-
-
Field Detail
-
stream
private final Http2Stream stream
-
pendingWriteQueue
private final java.util.Deque<Http2RemoteFlowController.FlowControlled> pendingWriteQueue
-
window
private int window
-
pendingBytes
private long pendingBytes
-
markedWritable
private boolean markedWritable
-
writing
private boolean writing
Set to true while a frame is being written, false otherwise.
-
cancelled
private boolean cancelled
Set to true if cancel() was called.
-
-
Constructor Detail
-
FlowState
FlowState(Http2Stream stream)
-
-
Method Detail
-
isWritable
boolean isWritable()
Determine if the stream associated with this object is writable.- Returns:
trueif the stream associated with this object is writable.
-
stream
public Http2Stream stream()
The stream this state is associated with.- Specified by:
streamin interfaceStreamByteDistributor.StreamState
-
markedWritability
boolean markedWritability()
Returns the parameter from the last call tomarkedWritability(boolean).
-
markedWritability
void markedWritability(boolean isWritable)
Save the state of writability.
-
windowSize
public int windowSize()
Description copied from interface:StreamByteDistributor.StreamStateThe size (in bytes) of the stream's flow control window. The amount written must not exceed this amount!A
StreamByteDistributorneeds to know the stream's window size in order to avoid allocating bytes if the window size is negative. The window size being0may also be significant to determine when if an stream has been given a chance to write an empty frame, and also enables optimizations like not writing empty frames in some situations (don't write headers until data can also be written).- Specified by:
windowSizein interfaceStreamByteDistributor.StreamState- Returns:
- the size of the stream's flow control window.
- See Also:
Http2CodecUtil.streamableBytes(StreamState)
-
windowSize
void windowSize(int initialWindowSize)
Reset the window size for this stream.
-
writeAllocatedBytes
int writeAllocatedBytes(int allocated)
Write the allocated bytes for this stream.- Returns:
- the number of bytes written for a stream or
-1if no write occurred.
-
incrementStreamWindow
int incrementStreamWindow(int delta) throws Http2ExceptionIncrements the flow control window for this stream by the given delta and returns the new value.- Throws:
Http2Exception
-
writableWindow
private int writableWindow()
Returns the maximum writable window (minimum of the stream and connection windows).
-
pendingBytes
public long pendingBytes()
Description copied from interface:StreamByteDistributor.StreamStateGet the amount of bytes this stream has pending to send. The actual amount written must not exceedStreamByteDistributor.StreamState.windowSize()!- Specified by:
pendingBytesin interfaceStreamByteDistributor.StreamState- Returns:
- The amount of bytes this stream has pending to send.
- See Also:
Http2CodecUtil.streamableBytes(StreamState)
-
enqueueFrame
void enqueueFrame(Http2RemoteFlowController.FlowControlled frame)
Adds theframeto the pending queue and increments the pending byte count.
-
enqueueFrameWithoutMerge
private void enqueueFrameWithoutMerge(Http2RemoteFlowController.FlowControlled frame)
-
hasFrame
public boolean hasFrame()
Description copied from interface:StreamByteDistributor.StreamStateIndicates whether or not there are frames pending for this stream.- Specified by:
hasFramein interfaceStreamByteDistributor.StreamState
-
peek
private Http2RemoteFlowController.FlowControlled peek()
Returns the head of the pending queue, ornullif empty.
-
cancel
void cancel(Http2Error error, java.lang.Throwable cause)
Clears the pending queue and writes errors for each remaining frame.- Parameters:
error- theHttp2Errorto use.cause- theThrowablethat caused this method to be invoked.
-
incrementPendingBytes
private void incrementPendingBytes(int numBytes, boolean updateStreamableBytes)Increments the number of pending bytes for this node and optionally updates theStreamByteDistributor.
-
decrementPendingBytes
private void decrementPendingBytes(int bytes, boolean updateStreamableBytes)If this frame is in the pending queue, decrements the number of pending bytes for the stream.
-
decrementFlowControlWindow
private void decrementFlowControlWindow(int bytes)
Decrement the per stream and connection flow control window bybytes.
-
writeError
private void writeError(Http2RemoteFlowController.FlowControlled frame, Http2Exception cause)
Discards thisHttp2RemoteFlowController.FlowControlled, writing an error. If this frame is in the pending queue, the unwritten bytes are removed from this branch of the priority tree.
-
-