E
- Type of dispatched signalpublic final class TopicProcessor<E> extends FluxProcessor<IN,IN>
Created from share(java.lang.String, int)
, the TopicProcessor
will authorize concurrent publishing (multi-producer)
from its receiving side Subscriber.onNext(Object)
.
Additionally, any of the TopicProcessor
will stop the event loop thread if an error occurs.
The processor
respects the Reactive Streams contract and must not be signalled concurrently on any
onXXXX method if share(java.lang.String, int)
has not been used. Each subscriber will be assigned a unique thread that will only
stop on
terminal event: Complete, Error or Cancel. If Auto-Cancel is enabled, when all
subscribers are unregistered, a cancel signal is sent to the upstream Publisher if any.
Executor can be customized and will define how many concurrent subscribers are allowed
(fixed thread). When a Subscriber requests Long.MAX, there won't be any backpressure
applied and the producer will run at risk of being throttled if the subscribers don't
catch up. With any other strictly positive demand, a subscriber will stop reading new
Next signals (Complete and Error will still be read) as soon as the demand has been
fully consumed by the publisher.
When more than 1 subscriber listens to that processor, they will all receive the exact same events if their respective demand is still strictly positive, very much like a Fan-Out scenario.
When the backlog has been completely booked and no subscribers is draining the signals, the publisher will start throttling. In effect the smaller the backlog size is defined, the smaller the difference in processing rate between subscribers must remain. Since the sequence for each subscriber will point to various ringBuffer locations, the processor knows when a backlog can't override the previously occupied slot.
Modifier and Type | Class and Description |
---|---|
static class |
reactor.core.publisher.EventLoopProcessor.Slot<T>
A simple reusable data container.
|
static class |
TopicProcessor.Builder<T>
TopicProcessor 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 <E> TopicProcessor.Builder<E> |
builder()
Create a new
TopicProcessor TopicProcessor.Builder with default properties. |
static <E> TopicProcessor<E> |
create()
Create a new TopicProcessor using
Queues.SMALL_BUFFER_SIZE backlog size,
blockingWait Strategy and auto-cancel. |
static <E> TopicProcessor<E> |
create(String name,
int bufferSize)
Create a new TopicProcessor using the provided backlog size, with a blockingWait Strategy
and auto-cancellation.
|
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> TopicProcessor<E> |
share(String name,
int bufferSize)
Create a new shared TopicProcessor using the passed backlog size, with a blockingWait
Strategy and auto-cancellation.
|
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, wrap
all, 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, concatWithValues, count, create, create, defaultIfEmpty, defer, delayElements, delayElements, delaySequence, delaySequence, delaySubscription, delaySubscription, delaySubscription, delayUntil, dematerialize, distinct, 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, 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, log, log, map, materialize, merge, merge, merge, merge, merge, merge, mergeDelayError, mergeOrdered, mergeOrdered, mergeOrdered, mergeOrderedWith, 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, zipWithIterable
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
currentContext
actuals, from, isScanAvailable, name, operatorName, parents, scan, scanOrDefault, tags
isDisposed
public static <E> TopicProcessor.Builder<E> builder()
TopicProcessor
TopicProcessor.Builder
with default properties.public static <E> TopicProcessor<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> TopicProcessor<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> TopicProcessor<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)
Flux
Publisher.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()
public long getPending()
protected void requestTask(Subscription s)
public void run()
@Nullable public Object scanUnsafe(Scannable.Attr key)
Scannable
Scannable.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 Scannable
scanUnsafe
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()
Scannable
Stream
of referenced inners (flatmap, multicast etc)inners
in interface Scannable
inners
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()
FluxProcessor
getError
in class FluxProcessor<IN,IN>
public boolean isSerialized()
FluxProcessor
FluxProcessor
supports multithread producingisSerialized
in class FluxProcessor<IN,IN>
FluxProcessor
supports multithread producingpublic final boolean isTerminated()
FluxProcessor
isTerminated
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)
CoreSubscriber
Subscriber.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()
FluxProcessor
FluxProcessor.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()
FluxProcessor
Integer.MAX_VALUE
getBufferSize
in class FluxProcessor<IN,IN>
Integer.MAX_VALUE
public long downstreamCount()
FluxProcessor
Subscriber
or -1 if untracked.downstreamCount
in class FluxProcessor<IN,IN>
Subscriber
or -1 if untracked