Interface SizeLimitTracker


@Internal public sealed interface SizeLimitTracker
A counter for bytes that ensures we don't exceed a configured buffer limit. May be thread safe or not thread safe depending on implementation.
Since:
5.0.0
  • Method Details

    • add

      @Nullable Exception add(long bytes)
      Add some bytes, with a check that there is enough room. If the limit is exceeded, this method returns an exception and the counter remains unchanged.
      Parameters:
      bytes - The number of bytes
      Returns:
      null iff the bytes were added to the counter
    • subtract

      void subtract(long bytes)
      Subtract a number of bytes.
      Parameters:
      bytes - The number of bytes
    • makeAtomic

      @NonNull SizeLimitTracker makeAtomic()
      Return a tracker that has the same properties and value, but is atomic. If this tracker is already atomic, return the same tracker.
      Returns:
      The atomic tracker
    • notThreadSafe

      static @NonNull SizeLimitTracker.TrackerPair notThreadSafe(@NonNull BodySizeLimits limits)
      Create a new tracker pair that is not thread safe.
      Parameters:
      limits - The size limits
      Returns:
      The tracker
    • combine

      Combine two trackers.
      Parameters:
      a - The first tracker
      b - The second tracker
      Returns:
      The combined tracker