Class EmittingPublisher<T>

  • Type Parameters:
    T - type of emitted item
    All Implemented Interfaces:
    Flow.Publisher<T>

    public class EmittingPublisher<T>
    extends Object
    implements Flow.Publisher<T>
    Emitting publisher for manual publishing on the same thread. EmittingPublisher doesn't have any buffering capability and propagates backpressure directly by returning false from emit(Object) in case there is no demand, or cancel signal has been received.

    For publishing with buffering in case of backpressure use BufferedEmittingPublisher.

    This publisher allows only a single subscriber.

    • Method Detail

      • create

        public static <T> EmittingPublisher<T> create()
        Create new EmittingPublisher.
        Type Parameters:
        T - type of emitted item
        Returns:
        brand new EmittingPublisher
      • fail

        public void fail​(Throwable throwable)
        Properly fail the stream, set publisher to cancelled state and send onError signal downstream. Signal onError is sent only once, any other call to this method is no-op.
        Parameters:
        throwable - Sent as onError signal
      • complete

        public void complete()
        Properly complete the stream, set publisher to completed state and send onComplete signal downstream. Signal onComplete is sent only once, any other call to this method is no-op.
      • emit

        public boolean emit​(T item)
        Emit one item to the stream, if there is enough requested and publisher is not cancelled, item is signaled to downstream as onNext and method returns true. If there is requested less than 1, nothing is sent and method returns false.
        Parameters:
        item - to be sent downstream
        Returns:
        true if item successfully sent, false if canceled or no demand
        Throws:
        IllegalStateException - if publisher is completed
      • isCompleted

        public boolean isCompleted()
        Check if publisher has been completed.
        Returns:
        true if so
      • isCancelled

        public boolean isCancelled()
        Check if publisher has been cancelled.
        Returns:
        true if so
      • isFailed

        public boolean isFailed()
        Check if publisher has been failed.
        Returns:
        true if so
      • hasRequests

        public boolean hasRequests()
        Check if demand is higher than 0. Returned value should be used as informative and can change asynchronously.
        Returns:
        true if so
      • isUnbounded

        public boolean isUnbounded()
        Check if downstream requested unbounded number of items, eg. there is no backpressure.
        Returns:
        true if so
      • failCause

        public Optional<Throwable> failCause()
        Return cause of fail, if publisher is in failed state.
        Returns:
        optional cause of fail
      • onCancel

        public void onCancel​(Runnable cancelCallback)
        Executed when cancel signal from downstream arrive.
        Parameters:
        cancelCallback - to be executed
      • onRequest

        public void onRequest​(BiConsumer<Long,​Long> requestCallback)
        Callback executed when request signal from downstream arrive.
        • param n the requested count.
        • param result the current total cumulative requested count, ranges between [0, Long.MAX_VALUE] where the max indicates that this publisher is unbounded.
        Parameters:
        requestCallback - to be executed