Class InflightLimiter

java.lang.Object
org.apache.pulsar.reactive.client.internal.api.InflightLimiter
All Implemented Interfaces:
PublisherTransformer, reactor.core.Disposable

public class InflightLimiter extends Object implements PublisherTransformer
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

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Default limit for pending Reactive Stream subscriptions.
  • Constructor Summary

    Constructors
    Constructor
    Description
    InflightLimiter(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

    Modifier and Type
    Method
    Description
    void
     
    boolean
     
    <T> org.reactivestreams.Publisher<T>
    transform(org.reactivestreams.Publisher<T> publisher)
    Transforms a Publisher to another Publisher.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_MAX_PENDING_SUBSCRIPTIONS

      public static final int DEFAULT_MAX_PENDING_SUBSCRIPTIONS
      Default 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 messages
      expectedSubscriptionsInflight - 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 more
      maxPendingSubscriptions - 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 a Publisher to another Publisher.
      Specified by:
      transform in interface PublisherTransformer
      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 interface reactor.core.Disposable
    • isDisposed

      public boolean isDisposed()
      Specified by:
      isDisposed in interface reactor.core.Disposable