Class InflightLimiter
java.lang.Object
org.apache.pulsar.reactive.client.internal.api.InflightLimiter
- All Implemented Interfaces:
PublisherTransformer
,reactor.core.Disposable
Transformer class that limits the number of reactive streams subscription requests to
keep the number of pending messages under a defined limit.
Subscribing to upstream is postponed if the max inflight limit is reached since
subscribing to a CompletableFuture is eager. The CompetableFuture will be created at
subscription time and this demand cannot be controlled with Reactive Stream's requests.
The solution for this is to acquire one slot at subscription time and return this slot
when request is made to the subscription. Since it's not possible to backpressure the
subscription requests, there's a configurable limit for the total number of pending
subscriptions. Exceeding the limit will cause IllegalStateException at runtime.
-
Nested Class Summary
Nested classes/interfaces inherited from interface reactor.core.Disposable
reactor.core.Disposable.Composite, reactor.core.Disposable.Swap
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Default limit for pending Reactive Stream subscriptions. -
Constructor Summary
ConstructorsConstructorDescriptionInflightLimiter
(int maxInflight) Constructs an InflightLimiter with a maximum number of in-flight messages.InflightLimiter
(int maxInflight, int expectedSubscriptionsInflight, reactor.core.scheduler.Scheduler triggerNextScheduler, int maxPendingSubscriptions) Constructs an InflightLimiter. -
Method Summary
-
Field Details
-
DEFAULT_MAX_PENDING_SUBSCRIPTIONS
public static final int DEFAULT_MAX_PENDING_SUBSCRIPTIONSDefault limit for pending Reactive Stream subscriptions.- See Also:
-
-
Constructor Details
-
InflightLimiter
public InflightLimiter(int maxInflight) Constructs an InflightLimiter with a maximum number of in-flight messages.- Parameters:
maxInflight
- the maximum number of in-flight messages
-
InflightLimiter
public InflightLimiter(int maxInflight, int expectedSubscriptionsInflight, reactor.core.scheduler.Scheduler triggerNextScheduler, int maxPendingSubscriptions) Constructs an InflightLimiter.- Parameters:
maxInflight
- the maximum number of in-flight messagesexpectedSubscriptionsInflight
- the expected number of in-flight subscriptions. Will limit the per-subscription requests to maxInflight / max(active subscriptions, expectedSubscriptionsInflight). Set to 0 to use active subscriptions in the calculation.triggerNextScheduler
- the scheduler on which it will be checked if the subscriber can request moremaxPendingSubscriptions
- the maximum number of pending subscriptions
-
-
Method Details
-
transform
public <T> org.reactivestreams.Publisher<T> transform(org.reactivestreams.Publisher<T> publisher) Description copied from interface:PublisherTransformer
Transforms aPublisher
to anotherPublisher
.- Specified by:
transform
in interfacePublisherTransformer
- Type Parameters:
T
- the type of the publisher- Parameters:
publisher
- the publisher to transform- Returns:
- the transformed publisher
-
dispose
public void dispose()- Specified by:
dispose
in interfacereactor.core.Disposable
-
isDisposed
public boolean isDisposed()- Specified by:
isDisposed
in interfacereactor.core.Disposable
-