Interface Subscribable<T>

Type Parameters:
T - item type
All Superinterfaces:
Flow.Publisher<T>
All Known Subinterfaces:
Content, Multi<T>, Single<T>
All Known Implementing Classes:
CompletionSingle, ConcatPublisher, MessageBodyReadableContent, MultiFromOutputStream, MultiTappedPublisher, OutputStreamMulti

public interface Subscribable<T> extends Flow.Publisher<T>
Decorated publisher that allows subscribing to individual events with java functions.
  • Method Details

    • subscribe

      default void subscribe(Consumer<? super T> consumer)
      Subscribe to this Single instance with the given delegate functions.
      Parameters:
      consumer - onNext delegate function
    • subscribe

      default void subscribe(Consumer<? super T> consumer, Consumer<? super Throwable> errorConsumer)
      Subscribe to this Single instance with the given delegate functions.
      Parameters:
      consumer - onNext delegate function
      errorConsumer - onError delegate function
    • subscribe

      default void subscribe(Consumer<? super T> consumer, Consumer<? super Throwable> errorConsumer, Runnable completeConsumer)
      Subscribe to this Single instance with the given delegate functions.
      Parameters:
      consumer - onNext delegate function
      errorConsumer - onError delegate function
      completeConsumer - onComplete delegate function
    • subscribe

      default void subscribe(Consumer<? super T> consumer, Consumer<? super Throwable> errorConsumer, Runnable completeConsumer, Consumer<? super Flow.Subscription> subscriptionConsumer)
      Subscribe to this Single instance with the given delegate functions.
      Parameters:
      consumer - onNext delegate function
      errorConsumer - onError delegate function
      completeConsumer - onComplete delegate function
      subscriptionConsumer - onSusbcribe delegate function
    • defaultIfEmpty

      Subscribable<T> defaultIfEmpty(T defaultItem)
      Signals the default item if the upstream is empty.
      Parameters:
      defaultItem - the item to signal if the upstream is empty
      Returns:
      Subscribable
      Throws:
      NullPointerException - if defaultItem is null
    • defaultIfEmpty

      Subscribable<T> defaultIfEmpty(Supplier<? extends T> supplier)
      Signals the default item supplied by specified supplier if the upstream is empty.
      Parameters:
      supplier - of the default value
      Returns:
      Multi
      Throws:
      NullPointerException - if supplier is null
    • flatMap

      <U> Subscribable<U> flatMap(Function<? super T,? extends Flow.Publisher<? extends U>> mapper)
      Transform item with supplied function and flatten resulting Flow.Publisher to downstream.
      Type Parameters:
      U - output item type
      Parameters:
      mapper - Function receiving item as parameter and returning Flow.Publisher
      Returns:
      Subscribable
    • flatMapIterable

      <U> Subscribable<U> flatMapIterable(Function<? super T,? extends Iterable<? extends U>> mapper)
      Transform item with supplied function and flatten resulting Iterable to downstream.
      Type Parameters:
      U - output item type
      Parameters:
      mapper - Function receiving item as parameter and returning Iterable
      Returns:
      Subscribable
    • map

      <U> Subscribable<U> map(Function<? super T,? extends U> mapper)
      Map this Subscribable instance to a new Subscribable of another type using the given Function.
      Type Parameters:
      U - mapped item type
      Parameters:
      mapper - mapper
      Returns:
      Subscribable
      Throws:
      NullPointerException - if mapper is null
    • observeOn

      Subscribable<T> observeOn(Executor executor)
      Re-emit the upstream's signals to the downstream on the given executor's thread.
      Parameters:
      executor - the executor to signal the downstream from.
      Returns:
      Subscribable
      Throws:
      NullPointerException - if executor is null
    • onCancel

      Subscribable<T> onCancel(Runnable onCancel)
      Executes given Runnable when a cancel signal is received.
      Parameters:
      onCancel - Runnable to be executed.
      Returns:
      Subscribable
    • onComplete

      Subscribable<T> onComplete(Runnable onComplete)
      Executes given Runnable when onComplete signal is received.
      Parameters:
      onComplete - Runnable to be executed.
      Returns:
      Subscribable
    • onError

      Subscribable<T> onError(Consumer<? super Throwable> onErrorConsumer)
      Executes given Runnable when onError signal is received.
      Parameters:
      onErrorConsumer - Consumer to be executed.
      Returns:
      Subscribable
    • onErrorResumeWith

      Subscribable<T> onErrorResumeWith(Function<? super Throwable,? extends Flow.Publisher<? extends T>> onError)
      Resume stream from supplied publisher if onError signal is intercepted.
      Parameters:
      onError - supplier of new stream publisher
      Returns:
      Subscribable
    • onErrorResume

      Subscribable<T> onErrorResume(Function<? super Throwable,? extends T> onError)
      Function providing one item to be submitted as onNext in case of onError signal is received.
      Parameters:
      onError - Function receiving Throwable as argument and producing one item to resume stream with.
      Returns:
      Subscribable
    • onCompleteResume

      Subscribable<T> onCompleteResume(T item)
      Resume stream from single item if onComplete signal is intercepted. Effectively do an append to the stream.
      Parameters:
      item - one item to resume stream with
      Returns:
      Subscribable
    • onCompleteResumeWith

      Subscribable<T> onCompleteResumeWith(Flow.Publisher<? extends T> publisher)
      Resume stream from supplied publisher if onComplete signal is intercepted.
      Parameters:
      publisher - new stream publisher
      Returns:
      Subscribable
    • onTerminate

      Subscribable<T> onTerminate(Runnable onTerminate)
      Executes given Runnable when any of signals onComplete, onCancel or onError is received.
      Parameters:
      onTerminate - Runnable to be executed.
      Returns:
      Subscribable
    • peek

      Subscribable<T> peek(Consumer<? super T> consumer)
      Invoke provided consumer for every item in stream.
      Parameters:
      consumer - consumer to be invoked
      Returns:
      Subscribable
    • retry

      Subscribable<T> retry(long count)
      Retry a failing upstream at most the given number of times before giving up.
      Parameters:
      count - the number of times to retry; 0 means no retry at all
      Returns:
      Subscribable
      Throws:
      IllegalArgumentException - if count is negative
      See Also:
    • retry

      Subscribable<T> retry(BiPredicate<? super Throwable,? super Long> predicate)
      Retry a failing upstream if the predicate returns true.
      Parameters:
      predicate - the predicate that receives the latest failure Throwable the number of times the retry happened so far (0-based) and should return true to retry the upstream again or false to signal the latest failure
      Returns:
      Subscribable
      Throws:
      NullPointerException - if predicate is null
      See Also:
    • retryWhen

      <U> Subscribable<T> retryWhen(BiFunction<? super Throwable,? super Long,? extends Flow.Publisher<U>> whenFunction)
      Retry a failing upstream when the given function returns a publisher that signals an item.

      If the publisher returned by the function completes, the repetition stops and this Subscribable is completed. If the publisher signals an error, the repetition stops and this Subscribable will signal this error.

      Type Parameters:
      U - the element type of the retry-signal sequence
      Parameters:
      whenFunction - the function that receives the latest failure Throwable the number of times the retry happened so far (0-based) and should return a Flow.Publisher that should signal an item to retry again, complete to stop and complete this Subscribable or signal an error to have this Subscribable emit that error as well.
      Returns:
      Subscribable
      Throws:
      NullPointerException - if whenFunction is null
    • takeUntil

      <U> Subscribable<T> takeUntil(Flow.Publisher<U> other)
      Relay upstream items until the other source signals an item or completes.
      Type Parameters:
      U - the element type of the other sequence
      Parameters:
      other - the other sequence to signal the end of the main sequence
      Returns:
      Subscribable
      Throws:
      NullPointerException - if other is null
    • timeout

      Subscribable<T> timeout(long timeout, TimeUnit unit, ScheduledExecutorService executor)
      Signals a TimeoutException if the upstream doesn't signal the next item, error or completion within the specified time.
      Parameters:
      timeout - the time to wait for the upstream to signal
      unit - the time unit
      executor - the executor to use for waiting for the upstream signal
      Returns:
      Subscribable
      Throws:
      NullPointerException - if unit or executor is null