-
- Type Parameters:
T- item type
- All Superinterfaces:
Flow.Publisher<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 Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Subscribable<T>defaultIfEmpty(Supplier<? extends T> supplier)Signals the default item supplied by specified supplier if the upstream is empty.Subscribable<T>defaultIfEmpty(T defaultItem)Signals the default item if the upstream is empty.<U> Subscribable<U>flatMap(Function<? super T,? extends Flow.Publisher<? extends U>> mapper)Transform item with supplied function and flatten resultingFlow.Publisherto downstream.<U> Subscribable<U>flatMapIterable(Function<? super T,? extends Iterable<? extends U>> mapper)Transform item with supplied function and flatten resultingIterableto downstream.<U> Subscribable<U>map(Function<? super T,? extends U> mapper)Subscribable<T>observeOn(Executor executor)Re-emit the upstream's signals to the downstream on the given executor's thread.Subscribable<T>onCancel(Runnable onCancel)Executes givenRunnablewhen a cancel signal is received.Subscribable<T>onComplete(Runnable onComplete)Executes givenRunnablewhen onComplete signal is received.Subscribable<T>onCompleteResume(T item)Resume stream from single item if onComplete signal is intercepted.Subscribable<T>onCompleteResumeWith(Flow.Publisher<? extends T> publisher)Resume stream from supplied publisher if onComplete signal is intercepted.Subscribable<T>onError(Consumer<? super Throwable> onErrorConsumer)Executes givenRunnablewhen onError signal is received.Subscribable<T>onErrorResume(Function<? super Throwable,? extends T> onError)Functionproviding one item to be submitted as onNext in case of onError signal is received.Subscribable<T>onErrorResumeWith(Function<? super Throwable,? extends Flow.Publisher<? extends T>> onError)Resume stream from supplied publisher if onError signal is intercepted.Subscribable<T>onTerminate(Runnable onTerminate)Executes givenRunnablewhen any of signals onComplete, onCancel or onError is received.Subscribable<T>peek(Consumer<? super T> consumer)Invoke provided consumer for every item in stream.Subscribable<T>retry(long count)Retry a failing upstream at most the given number of times before giving up.Subscribable<T>retry(BiPredicate<? super Throwable,? super Long> predicate)Retry a failing upstream if the predicate returns true.<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.default voidsubscribe(Consumer<? super T> consumer)Subscribe to thisSingleinstance with the given delegate functions.default voidsubscribe(Consumer<? super T> consumer, Consumer<? super Throwable> errorConsumer)Subscribe to thisSingleinstance with the given delegate functions.default voidsubscribe(Consumer<? super T> consumer, Consumer<? super Throwable> errorConsumer, Runnable completeConsumer)Subscribe to thisSingleinstance with the given delegate functions.default voidsubscribe(Consumer<? super T> consumer, Consumer<? super Throwable> errorConsumer, Runnable completeConsumer, Consumer<? super Flow.Subscription> subscriptionConsumer)Subscribe to thisSingleinstance with the given delegate functions.<U> Subscribable<T>takeUntil(Flow.Publisher<U> other)Relay upstream items until the other source signals an item or completes.Subscribable<T>timeout(long timeout, TimeUnit unit, ScheduledExecutorService executor)Signals aTimeoutExceptionif the upstream doesn't signal the next item, error or completion within the specified time.-
Methods inherited from interface java.util.concurrent.Flow.Publisher
subscribe
-
-
-
-
Method Detail
-
subscribe
default void subscribe(Consumer<? super T> consumer)
Subscribe to thisSingleinstance with the given delegate functions.- Parameters:
consumer- onNext delegate function
-
subscribe
default void subscribe(Consumer<? super T> consumer, Consumer<? super Throwable> errorConsumer)
Subscribe to thisSingleinstance with the given delegate functions.- Parameters:
consumer- onNext delegate functionerrorConsumer- onError delegate function
-
subscribe
default void subscribe(Consumer<? super T> consumer, Consumer<? super Throwable> errorConsumer, Runnable completeConsumer)
Subscribe to thisSingleinstance with the given delegate functions.- Parameters:
consumer- onNext delegate functionerrorConsumer- onError delegate functioncompleteConsumer- onComplete delegate function
-
subscribe
default void subscribe(Consumer<? super T> consumer, Consumer<? super Throwable> errorConsumer, Runnable completeConsumer, Consumer<? super Flow.Subscription> subscriptionConsumer)
Subscribe to thisSingleinstance with the given delegate functions.- Parameters:
consumer- onNext delegate functionerrorConsumer- onError delegate functioncompleteConsumer- onComplete delegate functionsubscriptionConsumer- 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- ifdefaultItemisnull
-
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- ifsupplierisnull
-
flatMap
<U> Subscribable<U> flatMap(Function<? super T,? extends Flow.Publisher<? extends U>> mapper)
Transform item with supplied function and flatten resultingFlow.Publisherto downstream.- Type Parameters:
U- output item type- Parameters:
mapper-Functionreceiving item as parameter and returningFlow.Publisher- Returns:
- Subscribable
-
flatMapIterable
<U> Subscribable<U> flatMapIterable(Function<? super T,? extends Iterable<? extends U>> mapper)
Transform item with supplied function and flatten resultingIterableto downstream.
-
map
<U> Subscribable<U> map(Function<? super T,? extends U> mapper)
- Type Parameters:
U- mapped item type- Parameters:
mapper- mapper- Returns:
- Subscribable
- Throws:
NullPointerException- if mapper isnull
-
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- ifexecutorisnull
-
onCancel
Subscribable<T> onCancel(Runnable onCancel)
Executes givenRunnablewhen a cancel signal is received.- Parameters:
onCancel-Runnableto be executed.- Returns:
- Subscribable
-
onComplete
Subscribable<T> onComplete(Runnable onComplete)
Executes givenRunnablewhen onComplete signal is received.- Parameters:
onComplete-Runnableto be executed.- Returns:
- Subscribable
-
onError
Subscribable<T> onError(Consumer<? super Throwable> onErrorConsumer)
Executes givenRunnablewhen onError signal is received.- Parameters:
onErrorConsumer-Consumerto 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)
Functionproviding one item to be submitted as onNext in case of onError signal is received.- Parameters:
onError- Function receivingThrowableas 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 anappendto 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 givenRunnablewhen any of signals onComplete, onCancel or onError is received.- Parameters:
onTerminate-Runnableto 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- ifcountis negative- See Also:
retryWhen(BiFunction)
-
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 failureThrowablethe number of times the retry happened so far (0-based) and should returntrueto retry the upstream again orfalseto signal the latest failure- Returns:
- Subscribable
- Throws:
NullPointerException- ifpredicateisnull- See Also:
retryWhen(BiFunction)
-
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 failureThrowablethe number of times the retry happened so far (0-based) and should return aFlow.Publisherthat 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- ifwhenFunctionisnull
-
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- ifotherisnull
-
timeout
Subscribable<T> timeout(long timeout, TimeUnit unit, ScheduledExecutorService executor)
Signals aTimeoutExceptionif 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 signalunit- the time unitexecutor- the executor to use for waiting for the upstream signal- Returns:
- Subscribable
- Throws:
NullPointerException- ifunitorexecutorisnull
-
-