Class FlowControlWindow

java.lang.Object
io.github.mahmoudimus.http2.FlowControlWindow

public final class FlowControlWindow extends Object
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

    Constructors
    Constructor
    Description
    FlowControlWindow(int streamId, int initialSize)
    Creates a flow-control window.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    adjust(long delta)
    Applies a change of SETTINGS_INITIAL_WINDOW_SIZE (delta = new - old) to a stream window (§6.9.2).
    int
    How much may be sent now: the size, or 0 if it is negative.
    void
    increment(int increment)
    Credits the window, as a WINDOW_UPDATE does.
    void
    receive(int length)
    Debits the window for a received flow-controlled frame.
    void
    send(int length)
    Debits the window for a frame about to be sent.
    long
    The space left; negative if a SETTINGS change shrank the window below what was in flight.
    int
    Identifies the scope of this window.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • FlowControlWindow

      public FlowControlWindow(int streamId, int initialSize)
      Creates a flow-control window.
      Parameters:
      streamId - the stream identifier, or 0 for the connection
      initialSize - 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

      public void increment(int increment) throws Http2Exception
      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

      public void receive(int length) throws Http2Exception
      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

      public void adjust(long delta) throws Http2Exception
      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

      public String toString()
      Overrides:
      toString in class Object