Record Class StreamBuffering

java.lang.Object
java.lang.Record
com.jsgalactic.axiom.test.StreamBuffering
Record Components:
highWaterBytes - unread bytes at which writers start to wait; positive
lowWaterBytes - unread bytes below which waiting writers continue; positive, at most the high water mark
pieceBytes - largest chunk queued by one step of a write; positive
stallTimeout - how long a writer waits for the reader to take anything before the client counts as gone; positive, or null for none (only the request deadline then ends the wait)

public record StreamBuffering(int highWaterBytes, int lowWaterBytes, int pieceBytes, Duration stallTimeout) extends Record
How TestClient.stream(com.jsgalactic.axiom.http.Request) models the buffering between a handler's writes and the client's reads. The queue holds unread chunks. A writer waits before queuing a piece while the channel is unwritable: it becomes unwritable when the unread bytes reach highWaterBytes and writable again when the reader brings them below lowWaterBytes. A write larger than pieceBytes is queued as several chunks of at most that size, which the reader receives one by one. A wait ends with a StreamAbortedException when the reader takes nothing for stallTimeout (CLIENT_DISCONNECTED) or at the request deadline (TIMEOUT).

HAND_OFF is the default: a writer is never more than one write ahead of the reader and writes are never split, which makes tests that read chunk by chunk fully deterministic. listener() uses the HTTP listener's numbers (32 and 128 KiB water marks, 16 KiB pieces, a 30 second stall bound), so that a test sees the same blocking points as a real socket would give, apart from the socket buffers of the operating system, which hold more.

  • Field Details

    • HAND_OFF

      public static final StreamBuffering HAND_OFF
      One chunk in flight, no splitting and no stall bound.
  • Constructor Details

    • StreamBuffering

      public StreamBuffering(int highWaterBytes, int lowWaterBytes, int pieceBytes, Duration stallTimeout)
      Creates a buffering model.
      Parameters:
      highWaterBytes - unread bytes at which writers start to wait; positive
      lowWaterBytes - unread bytes below which waiting writers continue; positive, at most the high water mark
      pieceBytes - largest chunk queued by one step of a write; positive
      stallTimeout - how long a writer waits for the reader before the client counts as gone, or null
  • Method Details

    • listener

      public static StreamBuffering listener()
      The numbers of the HTTP listener: 128 KiB high and 32 KiB low water marks, 16 KiB pieces and a 30 second stall bound.
      Returns:
      the listener's buffering
    • ofBytes

      public static StreamBuffering ofBytes(int highWaterBytes)
      A buffer of the given size: the low water mark is a quarter of it, pieces are at most 16 KiB and there is no stall bound.
      Parameters:
      highWaterBytes - unread bytes at which writers start to wait; positive
      Returns:
      the buffering
    • withStallTimeout

      public StreamBuffering withStallTimeout(Duration timeout)
      Returns a copy with another stall bound.
      Parameters:
      timeout - how long a writer waits for the reader before the client counts as gone, or null for none
      Returns:
      the buffering
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • highWaterBytes

      public int highWaterBytes()
      Returns the value of the highWaterBytes record component.
      Returns:
      the value of the highWaterBytes record component
    • lowWaterBytes

      public int lowWaterBytes()
      Returns the value of the lowWaterBytes record component.
      Returns:
      the value of the lowWaterBytes record component
    • pieceBytes

      public int pieceBytes()
      Returns the value of the pieceBytes record component.
      Returns:
      the value of the pieceBytes record component
    • stallTimeout

      public Duration stallTimeout()
      Returns the value of the stallTimeout record component.
      Returns:
      the value of the stallTimeout record component