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
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordA pair of trackers, one for the total size and one for the buffered size. -
Method Summary
Modifier and TypeMethodDescription@Nullable Exceptionadd(long bytes) Add some bytes, with a check that there is enough room.static @NonNull SizeLimitTracker.TrackerPaircombine(@NonNull SizeLimitTracker.TrackerPair a, @NonNull SizeLimitTracker.TrackerPair b) Combine two trackers.@NonNull SizeLimitTrackerReturn a tracker that has the same properties and value, but is atomic.static @NonNull SizeLimitTracker.TrackerPairnotThreadSafe(@NonNull BodySizeLimits limits) Create a new tracker pair that is not thread safe.voidsubtract(long bytes) Subtract a number of bytes.
-
Method Details
-
add
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:
nulliff 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
Create a new tracker pair that is not thread safe.- Parameters:
limits- The size limits- Returns:
- The tracker
-
combine
static @NonNull SizeLimitTracker.TrackerPair combine(@NonNull SizeLimitTracker.TrackerPair a, @NonNull SizeLimitTracker.TrackerPair b) Combine two trackers.- Parameters:
a- The first trackerb- The second tracker- Returns:
- The combined tracker
-