Class DispatchStreamProcessor<T>
java.lang.Object
io.reactivex.rxjava4.processors.DispatchStreamProcessor<T>
- Type Parameters:
T- the element type of the input and output values
- All Implemented Interfaces:
Streamable<T>, StreamProcessor<T,T>, StreamSink<T>
Signals the various
next(Object) and finish(Throwable) events to one or more
downstream Streamers.
This is equivalent with to a PublishProcessor or MulticastProcessor, adapted to
the Streamable world.
- Since:
- 4.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionOffer the final, terminal event.Returns the terminalThrowableif thisStreamProcessorwas completed with aThrowableviaStreamSink.finish(Throwable).booleanbooleanbooleanReturnstrueif thisStreamProcessorwas completed with aThrowableviaStreamSink.finish(Throwable).Offer the next item.stream(@NonNull StreamerCancellation cancellation) Realizes the stream and returns an interface that lets one consume it.intReturns the current number ofStreamers subscribed to thisStreamProcessorMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Streamable
blockingFirst, blockingLast, collect, delay, doOnError, doOnNext, filter, flatMap, forEach, forEach, forEach, forEach, forEach, groupBy, hide, ignoreElements, intercept, last, lastOrError, lift, map, mapOptional, onErrorResumeNext, repeat, repeatWhen, retry, retry, retry, retryWhen, skip, subscribe, subscribe, subscribe, subscribe, take, takeUntil, takeWhile, test, test, timeout, to, toFlowable, toFlowable, toObservable, transform, transformModifier and TypeMethodDescriptiondefault TBlocks the current thread until thisStreamableproduces one item, which is then returned.default TBlocks the current thread until thisStreamableproduces all of its items and the very last is then returned.default <A,R> @NonNull Streamable <R> Collects all upstream values via the use of aCollectorconfiguration and emits its resulting value as a single item of the returnedStreamable.default @NonNull Streamable<T> Delays the delivery of each upstream item by the given time amount.default @NonNull Streamable<T> Calls the specificConsumerif there is an error from the upstream.default @NonNull Streamable<T> Calls the given consumer whenever an upstream item becomes available.default @NonNull Streamable<T> Filters out the upstream items that do not pass the given predicate.default <R> @NonNull Streamable<R> flatMap(@NonNull Function<? super T, ? extends Streamable<? extends R>> mapper, @NonNull StandardConcurrentConfig config) Maps each upstream item onto aStreamableand runs them concurrently while relaying inner items as first-come-first-served manner.default @NonNull CompletionStageDisposable<Void> forEach(@NonNull BiConsumer<? super T, ? super Disposable> consumer, @NonNull DisposableStreamerCancellation canceller, @NonNull ExecutorService executor) Consumes elements from thisStreamablevia the provided executor service.default @NonNull CompletionStageDisposable<Void> Consumes elements from thisStreamablevia the provided executor service.default @NonNull CompletionStageDisposable<Void> Consumes elements from thisStreamablevia the provided executor service.default @NonNull CompletionStageDisposable<Void> forEach(@NonNull Consumer<? super T> consumer, @NonNull DisposableStreamerCancellation canceller, @NonNull ExecutorService executor) Consumes elements from thisStreamablevia the provided executor service.default @NonNull CompletionStageDisposable<Void> Consumes elements from thisStreamablevia the provided executor service.default <@Nullable K>
@NonNull Streamable<GroupedStreamable<K, T>> Maps each upstream item into aGroupedStreamablegroup, emits those groups and keeps relaying the upstream items into those groups.default @NonNull Streamable<T> hide()Hides the identity of thisStreamableand itsStreamer.default @NonNull Streamable<T> Ignores all elements from the currentStreamableand completes.default @NonNull Streamable<T> intercept(StreamableInterceptConfig<T> config) Intercepts the lifecycle method calls ofStreamableandStreamerand allows the modification of them via Function callbacks.Signals the last item from the upstreamStreamableor the provideddefaultItemif the upstream is empty, as aSingleinstance.Signals the last item from the upstreamStreamableor aNoSuchElementExceptionif the upstream is empty, as aSingleinstance.default <@NonNull R>
@NonNull Streamable<R> lift(@NonNull StreamableOperator<? super T, ? extends @NonNull R> lifter) This method requires advanced knowledge about building operators, please consider other standard composition methods first; Returns aStreamableinstance which when itsStreamable.stream(StreamerCancellation)is invoked, applies the specified operator callback to the upstreamStreamerto produce an actualStreamerinstance to be handed downstream.default <@NonNull R>
@NonNull Streamable<R> Maps each upstream item into another item via a mapper function.default <@NonNull R>
@NonNull Streamable<R> Maps each upstream item into another, optional item via a mapper function that skips the empty optionals.default @NonNull Streamable<T> onErrorResumeNext(@NonNull Function<? super Throwable, ? extends Streamable<? extends T>> fallbackMapper) When the upstream fails, the sequence is resumed by theStreamablethat is returned for the failureThrowable.default @NonNull Streamable<T> repeat(long count) Runs the upstream at most the givencounttimes while it succeeds.default @NonNull Streamable<T> repeatWhen(Function<? super Long, ? extends CompletionStage<Boolean>> whenFunction) Repeats the upstream when the given function signalstruevia theCompletionStagefor the count how many times the upstream was streamed.default @NonNull Streamable<T> retry(long count) Retries at most the givencounttimes the upstream if it fails with any error.default @NonNull Streamable<T> retry(BiPredicate<? super Long, ? super Throwable> predicate) Retries the upstream if the given predicate returnstruefor the failure count andThrowableof the last streaming of the upstream.default @NonNull Streamable<T> Retries the upstream if the given predicate returnstruefor the failureThrowableof the last streaming of the upstream.default @NonNull Streamable<T> retryWhen(BiFunction<? super Long, ? super Throwable, ? extends CompletionStage<Boolean>> whenFunction) Retries the upstream when the given predicate signalstruevia theCompletionStagefor the failure count andThrowableof the last streaming of the upstream.default @NonNull Streamable<T> skip(long count) Skips the firstcountitems and relays the rest to the downstream.default @NonNull CompletionStage<Void> subscribe(@NonNull StreamSink<? super T> consumer) Relays the events of the upstream into aStreamSinkconsumer via the help of the standardExecutors.newVirtualThreadPerTaskExecutor()as a mediator for pull-to-push.default @NonNull CompletionStage<Void> subscribe(@NonNull StreamSink<? super T> consumer, ExecutorService executor) Relays the events of the upstream into aStreamSinkconsumer via the help of the givenExecutorServiceas a mediator for pull-to-push.default voidsubscribe(Flow.Subscriber<? super T> subscriber) Consume thisStreamablevia the given flow-reactive-streams subscriber on a virtual thread backed executor service.default voidsubscribe(Flow.Subscriber<? super T> subscriber, @NonNull ExecutorService executor) Consume thisStreamablevia the given flow-reactive-streams subscriber.default @NonNull Streamable<T> take(long count) Takes at most the given number of items from the upstream and relays it to the downstream, then cancels the rest of the sequence.default <U> @NonNull Streamable<T> takeUntil(@NonNull Streamable<U> other) Relays items from thisStreamableuntil the otherStreamablesignals an item or completes.default @NonNull Streamable<T> Relays items from thisStreamablewhile the predicate returnstruedefault @NonNull TestSubscriber<T> test()Creates a newTestSubscriberand subscribes it to thisStreamable.default @NonNull TestSubscriber<T> test(@NonNull ExecutorService executor) Creates a newTestSubscriberand subscribes it to thisStreamable.default @NonNull Streamable<T> timeout(long timeout, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, @NonNull Streamable<T> fallback) Applies a timeout to each upstream item and switches to the fallbackStreamableif the upstream doesn't produce an item within the given timeout period.default <@NonNull R>
Rto(@NonNull StreamableConverter<T, ? extends @NonNull R> converter) Calls the specified converter function during assembly time and returns its resulting value.Converts the streamable into a Flowable representation, running on the default Executors.newVirtualThreadPerTaskExecutor() virtual thread.toFlowable(@NonNull ExecutorService executor) Converts thisStreamableinto aFlowablerepresentation, running on the provided executor service.default @NonNull Observable<T> Converts thisStreamableinto aObservablerepresentation, emitting items on whatever thread produces items in the currentStreamable.default <@NonNull R>
@NonNull Streamable<R> transform(@NonNull VirtualTransformer<T, @NonNull R> transformer) Transforms the upstream sequence into zero or more elements for the downstream.default <@NonNull R>
@NonNull Streamable<R> transform(@NonNull VirtualTransformer<T, @NonNull R> transformer, @NonNull ExecutorService executor) Transforms the upstream sequence into zero or more elements for the downstream.Methods inherited from interface StreamSink
awaitFinish, awaitNext, cancellation, withCancellationModifier and TypeMethodDescriptiondefault voidawaitFinish(Throwable throwable) Offer the final, terminal event and then awaits its consumption in a blocking fashion.default booleanOffers the given item and then awaits its consumption in a blocking fashion.Returns theDisposableContainerto use to detect if the consumer has indicated no more items it is willing to accept.default @NonNull StreamSink<T> withCancellation(DisposableStreamerCancellation cancellation) Returns a newStreamSinkthat returns the givenDisposableStreamerCancellationin itsStreamSink.cancellation(), allowing overriding the cancellation management of thisStreamSink
-
Constructor Details
-
DispatchStreamProcessor
public DispatchStreamProcessor()
-
-
Method Details
-
stream
@NonNull public @NonNull Streamer<@NonNull T> stream(@NonNull @NonNull StreamerCancellation cancellation) Description copied from interface:StreamableRealizes the stream and returns an interface that lets one consume it.Implementations are not meant to dispose the
cancellationas it is the privilege of whatever calls thestreammethod. If you need to talk to otherStreamables, use theStreamerCancellation.derive()to gain access to a fully fledgedDisposableStreamerCancellationwhere you can dispose it without disposing the parentcancellationinstance by accident.It is recommened you
StreamerCancellation.remove(Disposable)orStreamerCancellation.delete(Disposable)any extra resources you added viaStreamerCancellation.add(Disposable)when your operator reaches theStreamer.finish()call.- Specified by:
streamin interfaceStreamable<T>- Parameters:
cancellation- where to register, check and listen for cancellation calls via itsStreamerCancellation.isDisposed()- Returns:
- the Streamer instance to consume.
-
next
Description copied from interface:StreamSinkOffer the next item.- Specified by:
nextin interfaceStreamSink<T>- Parameters:
item- the item being offered- Returns:
- a
CompletionStagethat completes withtrueif the value was successfully consumed,falseif the value was rejected or exceptionally on error
-
finish
Description copied from interface:StreamSinkOffer the final, terminal event.- Specified by:
finishin interfaceStreamSink<T>- Parameters:
throwable- the optional throwable to signal error,nullto signal normal completion- Returns:
- a
CompletionStagethat completes withnullif the call succeeded or exceptionally on error
-
hasStreamers
public boolean hasStreamers()Description copied from interface:StreamProcessor- Specified by:
hasStreamersin interfaceStreamProcessor<T,T> - Returns:
trueif thisStreamProcessorhasStreamers.
-
streamerCount
public int streamerCount()Description copied from interface:StreamProcessorReturns the current number ofStreamers subscribed to thisStreamProcessor- Specified by:
streamerCountin interfaceStreamProcessor<T,T> - Returns:
- the current number of
Streamers subscribed to thisStreamProcessor
-
hasComplete
public boolean hasComplete()Description copied from interface:StreamProcessor- Specified by:
hasCompletein interfaceStreamProcessor<T,T> - Returns:
trueif thisStreamProcessorwas completed normally viaStreamSink.finish(Throwable).
-
hasThrowable
public boolean hasThrowable()Description copied from interface:StreamProcessorReturnstrueif thisStreamProcessorwas completed with aThrowableviaStreamSink.finish(Throwable).- Specified by:
hasThrowablein interfaceStreamProcessor<T,T> - Returns:
trueif thisStreamProcessorwas completed with aThrowableviaStreamSink.finish(Throwable).
-
getThrowable
Description copied from interface:StreamProcessorReturns the terminalThrowableif thisStreamProcessorwas completed with aThrowableviaStreamSink.finish(Throwable).- Specified by:
getThrowablein interfaceStreamProcessor<T,T> - Returns:
- the
Throwableif any
-