Top Description Constructors Methods
io.reactivex.rxjava3.internal.util

public final Class BackpressureHelper

extends Object
Class Inheritance
Imports
java.util.concurrent.atomic.AtomicLong, io.reactivex.rxjava3.annotations.NonNull, io.reactivex.rxjava3.plugins.RxJavaPlugins

Utility class to help with backpressure-related operations such as request aggregation.

Constructor Summary

AccessConstructor and Description
private
BackpressureHelper()

Utility class.

Method Summary

Modifier and TypeMethod and Description
public static long

Returns:

the original value before the add
add
(@NonNull AtomicLong
the AtomicLong holding the current requested value
requested
,
long
the value to add, must be positive (not verified)
n
)

Atomically adds the positive value n to the requested value in the AtomicLong and caps the result at Long#MAX_VALUE and returns the previous value.

public static long

Returns:

the original value before the add
addCancel
(@NonNull AtomicLong
the AtomicLong holding the current requested value
requested
,
long
the value to add, must be positive (not verified)
n
)

Atomically adds the positive value n to the requested value in the AtomicLong and caps the result at Long#MAX_VALUE and returns the previous value and considers Long#MIN_VALUE as a cancel indication (no addition then).

public static long

Returns:

the sum capped at Long#MAX_VALUE
addCap
(long
the first value
a
,
long
the second value
b
)

Adds two long values and caps the sum at Long#MAX_VALUE.

public static long

Returns:

the product capped at Long#MAX_VALUE
multiplyCap
(long
the first value
a
,
long
the second value
b
)

Multiplies two long values and caps the product at Long#MAX_VALUE.

public static long

Returns:

the new amount
produced
(@NonNull AtomicLong
the target field holding the current requested amount
requested
,
long
the produced element count, positive (not validated)
n
)

Atomically subtract the given number (positive, not validated) from the target field unless it contains Long#MAX_VALUE.

public static long

Returns:

the new amount
producedCancel
(@NonNull AtomicLong
the target field holding the current requested amount
requested
,
long
the produced element count, positive (not validated)
n
)

Atomically subtract the given number (positive, not validated) from the target field if it doesn't contain Long#MIN_VALUE (indicating some cancelled state) or Long#MAX_VALUE (unbounded mode).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

BackpressureHelperback to summary
private BackpressureHelper()

Utility class.

Method Detail

addback to summary
public static long add(@NonNull AtomicLong requested, long n)

Atomically adds the positive value n to the requested value in the AtomicLong and caps the result at Long#MAX_VALUE and returns the previous value.

Parameters
requested:@NonNull AtomicLong

the AtomicLong holding the current requested value

n:long

the value to add, must be positive (not verified)

Returns:long

the original value before the add

addCancelback to summary
public static long addCancel(@NonNull AtomicLong requested, long n)

Atomically adds the positive value n to the requested value in the AtomicLong and caps the result at Long#MAX_VALUE and returns the previous value and considers Long#MIN_VALUE as a cancel indication (no addition then).

Parameters
requested:@NonNull AtomicLong

the AtomicLong holding the current requested value

n:long

the value to add, must be positive (not verified)

Returns:long

the original value before the add

addCapback to summary
public static long addCap(long a, long b)

Adds two long values and caps the sum at Long#MAX_VALUE.

Parameters
a:long

the first value

b:long

the second value

Returns:long

the sum capped at Long#MAX_VALUE

multiplyCapback to summary
public static long multiplyCap(long a, long b)

Multiplies two long values and caps the product at Long#MAX_VALUE.

Parameters
a:long

the first value

b:long

the second value

Returns:long

the product capped at Long#MAX_VALUE

producedback to summary
public static long produced(@NonNull AtomicLong requested, long n)

Atomically subtract the given number (positive, not validated) from the target field unless it contains Long#MAX_VALUE.

Parameters
requested:@NonNull AtomicLong

the target field holding the current requested amount

n:long

the produced element count, positive (not validated)

Returns:long

the new amount

producedCancelback to summary
public static long producedCancel(@NonNull AtomicLong requested, long n)

Atomically subtract the given number (positive, not validated) from the target field if it doesn't contain Long#MIN_VALUE (indicating some cancelled state) or Long#MAX_VALUE (unbounded mode).

Parameters
requested:@NonNull AtomicLong

the target field holding the current requested amount

n:long

the produced element count, positive (not validated)

Returns:long

the new amount