Class ConnectableMulti<T>

  • Type Parameters:
    T - the type of item
    All Implemented Interfaces:
    Multi<T>, org.reactivestreams.Publisher<T>
    Direct Known Subclasses:
    MultiPublishOp

    public abstract class ConnectableMulti<T>
    extends AbstractMulti<T>
    A ConnectableMulti is similar to a regular Multi, except that it does not begin emitting items (from upstream to downstream) when it is subscribed to, but only when its connect(io.smallrye.mutiny.operators.multi.multicast.ConnectableMultiConnection) method is called. This allows deferring the dispatching of events. For example, it can wait until a set number of subscribers have subscribed.
    • Field Detail

      • upstream

        protected final Multi<T> upstream
    • Constructor Detail

      • ConnectableMulti

        protected ConnectableMulti​(Multi<T> upstream)
    • Method Detail

      • referenceCount

        public Multi<T> referenceCount()
        Returns a Multi that stays connected to this ConnectableMulti as long as there is at least one active subscription.
        Returns:
        a Multi
      • referenceCount

        public Multi<T> referenceCount​(int count,
                                       java.time.Duration duration)
        Connects to the upstream ConnectableMulti if the number of subscribers reaches the specified amount and disconnect after the specified duration after all subscribers have unsubscribed (cancelled their subscriptions).
        Parameters:
        count - the number of subscribers that trigger the emissions
        duration - the duration, can be null, if set must be positive
        Returns:
        the new Multi instance
      • connectAfter

        public Multi<T> connectAfter​(int numberOfSubscribers)
        Returns a Multi that connect to the upstream as soon as the numberOfSubscribers subscribers subscribe. The connection stays opens even if the subscribers cancelled the subscription. Other subscribers can subscribe, it would not re-subscribe to the upstream.
        Parameters:
        numberOfSubscribers - the number of subscribe to reach before subscribing to upstream.
        Returns:
        the multi