Class UnicastProcessor<T>

  • Type Parameters:
    T - the type of item
    All Implemented Interfaces:
    Multi<T>, org.reactivestreams.Processor<T,​T>, org.reactivestreams.Publisher<T>, org.reactivestreams.Subscriber<T>, org.reactivestreams.Subscription

    public class UnicastProcessor<T>
    extends AbstractMulti<T>
    implements org.reactivestreams.Processor<T,​T>, org.reactivestreams.Subscription
    Implementation of a processor using a queue to store items and allows a single subscriber to receive these items.

    The back pressure model is not using the request protocol but the queue used to store the items. If the queue gets full, an BackPressureFailure exception is propagated downstream.

    This processor must not be re-subscribed: it expects exactly 1 subscriber. If you expect multiple subscribers then you should look at creating a Multi from an emitter, see MultiCreate.emitter(Consumer, BackPressureStrategy).

    • Method Detail

      • create

        public static <I> UnicastProcessor<I> create()
        Creates a new UnicastProcessor using a new unbounded queue.
        Type Parameters:
        I - the type of item
        Returns:
        the unicast processor
      • create

        public static <I> UnicastProcessor<I> create​(java.util.Queue<I> queue,
                                                     java.lang.Runnable onTermination)
        Creates a new UnicastProcessor using the given queue.
        Type Parameters:
        I - the type of item
        Parameters:
        queue - the queue, must not be null
        onTermination - the termination callback, can be null
        Returns:
        the unicast processor
      • onSubscribe

        public void onSubscribe​(org.reactivestreams.Subscription upstream)
        Specified by:
        onSubscribe in interface org.reactivestreams.Subscriber<T>
      • onNext

        public void onNext​(T t)
        Specified by:
        onNext in interface org.reactivestreams.Subscriber<T>
      • onError

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

        public void onComplete()
        Specified by:
        onComplete in interface org.reactivestreams.Subscriber<T>
      • request

        public void request​(long n)
        Specified by:
        request in interface org.reactivestreams.Subscription
      • cancel

        public void cancel()
        Specified by:
        cancel in interface org.reactivestreams.Subscription
      • hasSubscriber

        public boolean hasSubscriber()
        Checks whether there is a subscriber listening for the emitted events. Mostly for testing purpose.
        Returns:
        true if there is a subscriber, false otherwise