E - Type of dispatched signalpublic final class WorkQueueProcessor<E> extends FluxProcessor<IN,IN>
Created from Flux.share(), the WorkQueueProcessor will authorize concurrent publishing
(multi-producer) from its receiving side Subscriber.onNext(Object).
WorkQueueProcessor is able to replay up to its buffer size number of failed signals (either
dropped or fatally throwing on child Subscriber.onNext(T)).
The processor is very similar to TopicProcessor but
only partially respects the Reactive Streams contract.
The purpose of this processor is to distribute the signals to only one of the subscribed subscribers and to share the demand amongst all subscribers. The scenario is akin to Executor or Round-Robin distribution. However there is no guarantee the distribution will be respecting a round-robin distribution all the time.
The core use for this component is to scale up easily without suffering the overhead of an Executor and without using dedicated queues by subscriber, which is less used memory, less GC, more win.
| Modifier and Type | Class and Description |
|---|---|
static class |
reactor.core.publisher.EventLoopProcessor.Slot<T>
A simple reusable data container.
|
static class |
WorkQueueProcessor.Builder<T>
WorkQueueProcessor builder that can be used to create new
processors. |
Scannable.Attr<T>Disposable.Composite, Disposable.Swap| Modifier and Type | Method and Description |
|---|---|
boolean |
alive()
Determine whether this
Processor can be used. |
boolean |
awaitAndShutdown()
Block until all submitted tasks have completed, then do a normal
EventLoopProcessor.dispose(). |
boolean |
awaitAndShutdown(Duration timeout)
Block until all submitted tasks have completed, then do a normal
EventLoopProcessor#dispose(). |
boolean |
awaitAndShutdown(long timeout,
TimeUnit timeUnit)
Deprecated.
use
awaitAndShutdown(Duration) instead |
static <T> WorkQueueProcessor.Builder<T> |
builder()
Create a new
WorkQueueProcessor WorkQueueProcessor.Builder with default properties. |
static <E> WorkQueueProcessor<E> |
create()
Create a new WorkQueueProcessor using
Queues.SMALL_BUFFER_SIZE backlog size,
blockingWait Strategy and auto-cancel. |
static <E> WorkQueueProcessor<E> |
create(String name,
int bufferSize)
Create a new WorkQueueProcessor using the passed buffer size, blockingWait
Strategy and auto-cancel.
|
protected static String |
defaultName(ThreadFactory threadFactory,
Class<? extends reactor.core.publisher.EventLoopProcessor> clazz)
A method to extract a name from the ThreadFactory if it turns out to be a Supplier
(in which case the supplied value string representation is used).
|
protected static ExecutorService |
defaultRequestTaskExecutor(String name)
A method to create a suitable default
ExecutorService for use in implementors
requestTask(Subscription) (a cached
thread pool), reusing a main name and appending [request-task] suffix. |
protected void |
doComplete() |
protected void |
doError(Throwable t) |
long |
downstreamCount()
Return the number of active
Subscriber or -1 if untracked. |
Flux<E> |
drain()
Drain is a hot replication of the current buffer delivered if supported.
|
Flux<IN> |
forceShutdown()
Shutdown this
Processor, forcibly halting any work currently executing and discarding any tasks that have
not yet been executed. |
long |
getAvailableCapacity() |
int |
getBufferSize()
Return the processor buffer capacity if any or
Integer.MAX_VALUE |
Throwable |
getError()
Current error if any, default to null
|
long |
getPending()
Return the number of parked elements in the emitter backlog.
|
int |
hashCode() |
Stream<? extends Scannable> |
inners()
Return a
Stream of referenced inners (flatmap, multicast etc) |
boolean |
isSerialized()
Return true if this
FluxProcessor supports multithread producing |
boolean |
isTerminated()
Has this upstream finished or "completed" / "failed" ?
|
void |
onComplete() |
void |
onError(Throwable t) |
void |
onNext(IN o) |
void |
onSubscribe(Subscription s)
Implementors should initialize any state used by
Subscriber.onNext(Object) before
calling Subscription.request(long). |
protected void |
requestTask(Subscription s) |
void |
run() |
Object |
scanUnsafe(Scannable.Attr key)
This method is used internally by components to define their key-value mappings
in a single place.
|
protected boolean |
serializeAlways()
Returns serialization strategy.
|
static <E> WorkQueueProcessor<E> |
share(String name,
int bufferSize)
Create a new shared WorkQueueProcessor using the passed buffer size, blockingWait
Strategy and auto-cancel.
|
void |
shutdown()
Shutdown this active
Processor such that it can no longer be used. |
void |
subscribe(CoreSubscriber<? super E> actual)
An internal
Publisher.subscribe(Subscriber) that will bypass
Hooks.onLastOperator(Function) pointcut. |
String |
toString() |
dispose, hasCompleted, hasDownstreams, hasError, serialize, sink, sink, switchOnNext, wrapall, any, as, blockFirst, blockFirst, blockLast, blockLast, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, bufferTimeout, bufferTimeout, bufferTimeout, bufferTimeout, bufferUntil, bufferUntil, bufferWhen, bufferWhen, bufferWhile, cache, cache, cache, cache, cancelOn, cast, checkpoint, checkpoint, checkpoint, collect, collect, collectList, collectMap, collectMap, collectMap, collectMultimap, collectMultimap, collectMultimap, collectSortedList, collectSortedList, combineLatest, combineLatest, combineLatest, combineLatest, combineLatest, combineLatest, combineLatest, combineLatest, combineLatest, compose, concat, concat, concat, concat, concatDelayError, concatDelayError, concatDelayError, concatDelayError, concatMap, concatMap, concatMapDelayError, concatMapDelayError, concatMapDelayError, concatMapIterable, concatMapIterable, concatWith, count, create, create, defaultIfEmpty, defer, delayElements, delayElements, delaySequence, delaySequence, delaySubscription, delaySubscription, delaySubscription, delayUntil, dematerialize, distinct, distinct, distinct, distinctUntilChanged, distinctUntilChanged, distinctUntilChanged, doAfterTerminate, doFinally, doOnCancel, doOnComplete, doOnEach, doOnError, doOnError, doOnError, doOnNext, doOnRequest, doOnSubscribe, doOnTerminate, elapsed, elapsed, elementAt, elementAt, empty, error, error, errorStrategyContinue, errorStrategyContinue, errorStrategyContinue, errorStrategyContinue, errorStrategyContinue, errorStrategyContinue, errorStrategyStop, expand, expand, expandDeep, expandDeep, filter, filterWhen, filterWhen, first, first, flatMap, flatMap, flatMap, flatMap, flatMapDelayError, flatMapIterable, flatMapIterable, flatMapSequential, flatMapSequential, flatMapSequential, flatMapSequentialDelayError, from, fromArray, fromIterable, fromStream, fromStream, generate, generate, generate, getPrefetch, groupBy, groupBy, groupBy, groupBy, groupJoin, handle, hasElement, hasElements, hide, ignoreElements, index, index, interval, interval, interval, interval, join, just, just, last, last, limitRate, limitRate, limitRequest, log, log, log, log, map, materialize, merge, merge, merge, merge, merge, merge, mergeDelayError, mergeSequential, mergeSequential, mergeSequential, mergeSequential, mergeSequential, mergeSequential, mergeSequentialDelayError, mergeSequentialDelayError, mergeSequentialDelayError, mergeWith, name, never, next, ofType, onAssembly, onAssembly, onBackpressureBuffer, onBackpressureBuffer, onBackpressureBuffer, onBackpressureBuffer, onBackpressureBuffer, onBackpressureBuffer, onBackpressureBuffer, onBackpressureDrop, onBackpressureDrop, onBackpressureError, onBackpressureLatest, onErrorMap, onErrorMap, onErrorMap, onErrorResume, onErrorResume, onErrorResume, onErrorReturn, onErrorReturn, onErrorReturn, onLastAssembly, onTerminateDetach, or, parallel, parallel, parallel, publish, publish, publish, publish, publishNext, publishOn, publishOn, publishOn, push, push, range, reduce, reduce, reduceWith, repeat, repeat, repeat, repeat, repeatWhen, replay, replay, replay, replay, replay, replay, retry, retry, retry, retry, retryWhen, sample, sample, sampleFirst, sampleFirst, sampleTimeout, sampleTimeout, scan, scan, scanWith, share, single, single, singleOrEmpty, skip, skip, skip, skipLast, skipUntil, skipUntilOther, skipWhile, sort, sort, startWith, startWith, startWith, subscribe, subscribe, subscribe, subscribe, subscribe, subscribe, subscribeOn, subscribeOn, subscriberContext, subscriberContext, subscribeWith, switchIfEmpty, switchMap, switchMap, switchOnNext, switchOnNext, tag, take, take, take, takeLast, takeUntil, takeUntilOther, takeWhile, then, then, thenEmpty, thenMany, timeout, timeout, timeout, timeout, timeout, timeout, timeout, timestamp, timestamp, toIterable, toIterable, toIterable, toStream, toStream, transform, using, using, window, window, window, window, window, window, window, windowTimeout, windowTimeout, windowUntil, windowUntil, windowUntil, windowWhen, windowWhile, windowWhile, withLatestFrom, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zipWith, zipWith, zipWith, zipWith, zipWithIterable, zipWithIterableclone, equals, finalize, getClass, notify, notifyAll, wait, wait, waitcurrentContextactuals, from, isScanAvailable, name, operatorName, parents, scan, scanOrDefault, tagsisDisposedpublic static final <T> WorkQueueProcessor.Builder<T> builder()
WorkQueueProcessor WorkQueueProcessor.Builder with default properties.public static <E> WorkQueueProcessor<E> create()
Queues.SMALL_BUFFER_SIZE backlog size,
blockingWait Strategy and auto-cancel. A new Cached ThreadExecutorPool will be implicitly created.
E - Type of processed signalspublic static <E> WorkQueueProcessor<E> create(String name, int bufferSize)
A new Cached ThreadExecutorPool will be implicitly created and will use the passed name to qualify the created threads.
E - Type of processed signalsname - Use a new Cached ExecutorService and assign this name to the created
threadsbufferSize - A Backlog Size to mitigate slow subscriberspublic static <E> WorkQueueProcessor<E> share(String name, int bufferSize)
A Shared Processor authorizes concurrent onNext calls and is suited for multi-threaded publisher that will fan-in data.
A new Cached ThreadExecutorPool will be implicitly created and will use the passed name to qualify the created threads.
E - Type of processed signalsname - Use a new Cached ExecutorService and assign this name to the created
threadsbufferSize - A Backlog Size to mitigate slow subscriberspublic void subscribe(CoreSubscriber<? super E> actual)
FluxPublisher.subscribe(Subscriber) that will bypass
Hooks.onLastOperator(Function) pointcut.
In addition to behave as expected by Publisher.subscribe(Subscriber)
in a controlled manner, it supports direct subscribe-time Context passing.
subscribe in class Flux<E>actual - the Subscriber interested into the published sequenceFlux.subscribe(Subscriber)public Flux<E> drain()
Flux sequence possibly unbounded of incoming buffered values or empty if not supported.protected void doError(Throwable t)
protected void doComplete()
protected void requestTask(Subscription s)
public long getPending()
public void run()
@Nullable public Object scanUnsafe(Scannable.Attr key)
ScannableScannable.Attr key,
implementors should take care to return values of the correct type, and return
null if no specific value is available.
For public consumption of attributes, prefer using Scannable.scan(Attr), which will
return a typed value and fall back to the key's default if the component didn't
define any mapping.
scanUnsafe in interface ScannablescanUnsafe in class FluxProcessor<IN,IN>key - a Scannable.Attr to resolve for the component.protected static String defaultName(@Nullable ThreadFactory threadFactory, Class<? extends reactor.core.publisher.EventLoopProcessor> clazz)
threadFactory - the factory to test for a supplied nameclazz - protected static ExecutorService defaultRequestTaskExecutor(String name)
ExecutorService for use in implementors
requestTask(Subscription) (a cached
thread pool), reusing a main name and appending [request-task] suffix.name - the main thread name used by the processor.ExecutorService for requestTask.public final boolean alive()
Processor can be used.Resource is alive and can be used, false otherwise.public final boolean awaitAndShutdown()
EventLoopProcessor.dispose().@Deprecated public final boolean awaitAndShutdown(long timeout, TimeUnit timeUnit)
awaitAndShutdown(Duration) insteadEventLoopProcessor#dispose().timeout - the timeout valuetimeUnit - the unit for timeoutpublic final boolean awaitAndShutdown(Duration timeout)
EventLoopProcessor#dispose().public Stream<? extends Scannable> inners()
ScannableStream of referenced inners (flatmap, multicast etc)inners in interface Scannableinners in class FluxProcessor<IN,IN>Stream of referenced inners (flatmap, multicast etc)public final Flux<IN> forceShutdown()
Processor, forcibly halting any work currently executing and discarding any tasks that have
not yet been executed.public final long getAvailableCapacity()
@Nullable public final Throwable getError()
FluxProcessorgetError in class FluxProcessor<IN,IN>public boolean isSerialized()
FluxProcessorFluxProcessor supports multithread producingisSerialized in class FluxProcessor<IN,IN>FluxProcessor supports multithread producingpublic final boolean isTerminated()
FluxProcessorisTerminated in class FluxProcessor<IN,IN>public final void onComplete()
onComplete in interface Subscriber<IN>public final void onError(Throwable t)
onError in interface Subscriber<IN>public final void onNext(IN o)
onNext in interface Subscriber<IN>public final void onSubscribe(Subscription s)
CoreSubscriberSubscriber.onNext(Object) before
calling Subscription.request(long). Should further onNext related
state modification occur, thread-safety will be required.
Note that an invalid request <= 0 will not produce an onError and
will simply be ignored or reported through a debug-enabled
Logger.
onSubscribe in interface Subscriber<IN>onSubscribe in interface CoreSubscriber<IN>protected boolean serializeAlways()
FluxProcessorFluxProcessor.sink() will always
be serialized. Otherwise sink is serialized only if FluxSink.onRequest(java.util.function.LongConsumer)
is invoked.serializeAlways in class FluxProcessor<IN,IN>public final void shutdown()
Processor such that it can no longer be used. If the resource carries any work, it
will wait (but NOT blocking the caller) for all the remaining tasks to perform before closing the resource.public final int getBufferSize()
FluxProcessorInteger.MAX_VALUEgetBufferSize in class FluxProcessor<IN,IN>Integer.MAX_VALUEpublic long downstreamCount()
FluxProcessorSubscriber or -1 if untracked.downstreamCount in class FluxProcessor<IN,IN>Subscriber or -1 if untracked