Class ConnectableFlux<T>

java.lang.Object
reactor.core.publisher.Flux<T>
reactor.core.publisher.ConnectableFlux<T>
Type Parameters:
T - the input and output value type
All Implemented Interfaces:
Publisher<T>, CorePublisher<T>

public abstract class ConnectableFlux<T> extends Flux<T>
The abstract base class for connectable publishers that let subscribers pile up before they connect to their data source.
See Also:
  • Constructor Details

    • ConnectableFlux

      public ConnectableFlux()
  • Method Details

    • autoConnect

      public final Flux<T> autoConnect()
      Connects this ConnectableFlux to the upstream source when the first Subscriber subscribes.

      Returns:
      a Flux that connects to the upstream source when the first Subscriber subscribes
    • autoConnect

      public final Flux<T> autoConnect(int minSubscribers)
      Connects this ConnectableFlux to the upstream source when the specified amount of Subscriber subscribes.

      Subscribing and immediately unsubscribing still contributes to the counter that triggers the connection.

      Parameters:
      minSubscribers - the minimum number of subscribers
      Returns:
      a Flux that connects to the upstream source when the given amount of Subscribers subscribed
    • autoConnect

      public final Flux<T> autoConnect(int minSubscribers, Consumer<? super Disposable> cancelSupport)
      Connects this ConnectableFlux to the upstream source when the specified amount of Subscriber subscribes and calls the supplied consumer with a Disposable that allows disconnecting.

      Parameters:
      minSubscribers - the minimum number of subscribers
      cancelSupport - the consumer that will receive the Disposable that allows disconnecting
      Returns:
      a Flux that connects to the upstream source when the given amount of subscribers subscribed
    • connect

      public final Disposable connect()
      Connect this ConnectableFlux to its source and return a Disposable that can be used for disconnecting.
      Returns:
      the Disposable that allows disconnecting the connection after.
    • connect

      public abstract void connect(Consumer<? super Disposable> cancelSupport)
      Connects this ConnectableFlux to its source and sends a Disposable to a callback that can be used for disconnecting.

      The call should be idempotent in respect of connecting the first and subsequent times. In addition, the disconnection should be tied to a particular connection (so two different connections can't disconnect the other).

      Parameters:
      cancelSupport - the callback is called with a Disposable instance that can be called to disconnect the source, even synchronously.
    • hide

      public final ConnectableFlux<T> hide()
      Description copied from class: Flux
      Hides the identities of this Flux instance.

      The main purpose of this operator is to prevent certain identity-based optimizations from happening, mostly for diagnostic purposes.

      Overrides:
      hide in class Flux<T>
      Returns:
      a new Flux preventing Publisher / Subscription based Reactor optimizations
    • refCount

      public final Flux<T> refCount()
      Connects to the upstream source when the first Subscriber subscribes and disconnects when all Subscribers cancelled or the upstream source completed.

      Returns:
      a reference counting Flux
    • refCount

      public final Flux<T> refCount(int minSubscribers)
      Connects to the upstream source when the given number of Subscriber subscribes and disconnects when all Subscribers cancelled or the upstream source completed.

      Parameters:
      minSubscribers - the number of subscribers expected to subscribe before connection
      Returns:
      a reference counting Flux
    • refCount

      public final Flux<T> refCount(int minSubscribers, Duration gracePeriod)
      Connects to the upstream source when the given number of Subscriber subscribes. Disconnection can happen in two scenarios: when the upstream source completes (or errors) then there is an immediate disconnection. However, when all subscribers have cancelled, a deferred disconnection is scheduled. If any new subscriber comes in during the gracePeriod that follows, the disconnection is cancelled.

      Parameters:
      minSubscribers - the number of subscribers expected to subscribe before connection
      gracePeriod - the Duration for which to wait for new subscribers before actually disconnecting when all subscribers have cancelled.
      Returns:
      a reference counting Flux with a grace period for disconnection
    • refCount

      public final Flux<T> refCount(int minSubscribers, Duration gracePeriod, Scheduler scheduler)
      Connects to the upstream source when the given number of Subscriber subscribes. Disconnection can happen in two scenarios: when the upstream source completes (or errors) then there is an immediate disconnection. However, when all subscribers have cancelled, a deferred disconnection is scheduled. If any new subscriber comes in during the gracePeriod that follows, the disconnection is cancelled.

      Parameters:
      minSubscribers - the number of subscribers expected to subscribe before connection
      gracePeriod - the Duration for which to wait for new subscribers before actually disconnecting when all subscribers have cancelled.
      scheduler - the Scheduler on which to run timeouts
      Returns:
      a reference counting Flux with a grace period for disconnection