Class BroadcastProcessor<T>

  • All Implemented Interfaces:
    Multi<T>, java.util.concurrent.Flow.Processor<T,​T>, java.util.concurrent.Flow.Publisher<T>, java.util.concurrent.Flow.Subscriber<T>

    public class BroadcastProcessor<T>
    extends AbstractMulti<T>
    implements java.util.concurrent.Flow.Processor<T,​T>
    Implementation of Flow.Processor that broadcast all subsequently observed items to its current Flow.Subscribers.

    This processor does not coordinate back-pressure between different subscribers and between the upstream source and a subscriber. If an upstream item is received via onNext(Object), if a subscriber is not ready to receive that item, that subscriber is terminated via a BackPressureFailure.

    The BroadcastProcessor's Flow.Subscriber-side consumes items in an unbounded manner.

    When this BroadcastProcessor is terminated via onError(Throwable) or onComplete(), late Flow.Subscribers only receive the respective terminal event.

    Unlike the UnicastProcessor, a BroadcastProcessor doesn't retain/cache items, therefore, a new Subscriber won't receive any past items.

    Even though BroadcastProcessor implements the Flow.Subscriber interface, calling onSubscribe is not required if the processor is used as a standalone source. However, calling onSubscribe after the BroadcastProcessor has failed or reached completion results in the given Flow.Subscription being canceled immediately.

    • Method Detail

      • create

        public static <T> BroadcastProcessor<T> create()
        Creates a new BroadcastProcessor
        Type Parameters:
        T - the type of item
        Returns:
        the new BroadcastProcessor
      • onSubscribe

        public void onSubscribe​(java.util.concurrent.Flow.Subscription subscription)
        Specified by:
        onSubscribe in interface java.util.concurrent.Flow.Subscriber<T>
      • onNext

        public void onNext​(T item)
        Specified by:
        onNext in interface java.util.concurrent.Flow.Subscriber<T>
      • onError

        public void onError​(java.lang.Throwable failure)
        Specified by:
        onError in interface java.util.concurrent.Flow.Subscriber<T>
      • onComplete

        public void onComplete()
        Specified by:
        onComplete in interface java.util.concurrent.Flow.Subscriber<T>