Package io.github.mahmoudimus.http2
Class FlowControlWindow
java.lang.Object
io.github.mahmoudimus.http2.FlowControlWindow
One HTTP/2 flow-control window (RFC 9113 §5.2, §6.9): of a stream, or of the connection when
streamId() is 0. A window can go negative after SETTINGS_INITIAL_WINDOW_SIZE shrinks,
and never exceeds 2^31-1.
Plain data with no locking: callers that share a window between threads must guard it themselves (typically with the connection's lock).
-
Constructor Summary
ConstructorsConstructorDescriptionFlowControlWindow(int streamId, int initialSize) Creates a flow-control window. -
Method Summary
Modifier and TypeMethodDescriptionvoidadjust(long delta) Applies a change of SETTINGS_INITIAL_WINDOW_SIZE (delta = new - old) to a stream window (§6.9.2).intHow much may be sent now: the size, or 0 if it is negative.voidincrement(int increment) Credits the window, as a WINDOW_UPDATE does.voidreceive(int length) Debits the window for a received flow-controlled frame.voidsend(int length) Debits the window for a frame about to be sent.longsize()The space left; negative if a SETTINGS change shrank the window below what was in flight.intstreamId()Identifies the scope of this window.toString()
-
Constructor Details
-
FlowControlWindow
public FlowControlWindow(int streamId, int initialSize) Creates a flow-control window.- Parameters:
streamId- the stream identifier, or 0 for the connectioninitialSize- the nonnegative initial credit in octets
-
-
Method Details
-
streamId
public int streamId()Identifies the scope of this window.- Returns:
- the stream identifier, or 0 for the connection
-
size
public long size()The space left; negative if a SETTINGS change shrank the window below what was in flight.- Returns:
- the signed window size in octets
-
available
public int available()How much may be sent now: the size, or 0 if it is negative.- Returns:
- the nonnegative available octet count
-
increment
Credits the window, as a WINDOW_UPDATE does.- Parameters:
increment- the positive number of octets to credit- Throws:
Http2Exception- FLOW_CONTROL_ERROR if the window would exceed 2^31-1: a connection error for the connection window, a stream error for a stream's
-
receive
Debits the window for a received flow-controlled frame.- Parameters:
length- the nonnegative flow-controlled octet count received- Throws:
Http2Exception- FLOW_CONTROL_ERROR if the peer sent more than the window allowed (connection error for the connection window, stream error for a stream's)
-
send
public void send(int length) Debits the window for a frame about to be sent.- Parameters:
length- the nonnegative flow-controlled octet count being sent- Throws:
IllegalStateException- if the window does not allow it: a bug in the caller
-
adjust
Applies a change of SETTINGS_INITIAL_WINDOW_SIZE (delta = new - old) to a stream window (§6.9.2). The result may be negative.- Parameters:
delta- the new initial window size minus the old size, in octets- Throws:
Http2Exception- a connection error FLOW_CONTROL_ERROR if the window would exceed 2^31-1
-
toString
-