public class BlockingManagerImpl extends Object implements BlockingManager
BlockingManager.BlockingExecutor
Constructor and Description |
---|
BlockingManagerImpl() |
Modifier and Type | Method and Description |
---|---|
<V> org.reactivestreams.Publisher<V> |
blockingPublisher(org.reactivestreams.Publisher<V> publisher)
Provided a publisher that is known to block when subscribed to, this ensures that the publisher is subscribed
on the blocking executor and any values published are observed on a non blocking thread.
|
<V> CompletionStage<V> |
continueOnNonBlockingThread(CompletionStage<V> delay,
Object traceId)
When the provided stage is complete, continue the completion chain of the returned CompletionStage on the
supplied executor.
|
<I,O> CompletionStage<O> |
handleBlocking(CompletionStage<? extends I> stage,
BiFunction<? super I,Throwable,? extends O> function,
Object traceId)
Replacement for
CompletionStage.handleAsync() that invokes the BiFunction in a blocking thread
(if the current thread is non-blocking) or in the current thread (if the current thread is blocking). |
BlockingManager.BlockingExecutor |
limitedBlockingExecutor(String name,
int concurrentExecutions)
Provides a
BlockingManager.BlockingExecutor which is limited to the provided concurrency amount. |
CompletionStage<Void> |
runBlocking(Runnable runnable,
Object traceId)
Replacement for
CompletionStage.runAsync() that invokes the Runnable in a blocking thread
if the current thread is non-blocking or in the current thread if the current thread is blocking. |
protected void |
start() |
<T,A,R> CompletionStage<R> |
subscribeBlockingCollector(org.reactivestreams.Publisher<T> publisher,
Collector<? super T,A,R> collector,
Object traceId)
Subscribes to the provided publisher on the invoking thread.
|
<E> CompletionStage<Void> |
subscribeBlockingConsumer(org.reactivestreams.Publisher<E> publisher,
Consumer<E> consumer,
Object traceId)
Subscribes to the provided publisher on the invoking thread.
|
<V> CompletionStage<V> |
supplyBlocking(Supplier<V> supplier,
Object traceId)
Replacement for
CompletionStage.supplyAsync() that invokes the Supplier in a blocking thread
(if the current thread is non-blocking) or in the current thread (if the current thread is blocking). |
<I,O> CompletionStage<O> |
thenApplyBlocking(CompletionStage<? extends I> stage,
Function<? super I,? extends O> function,
Object traceId)
Replacement for
CompletionStage.thenApplyAsync() that invokes the Function in a blocking thread
(if the current thread is non-blocking) or in the current thread (if the current thread is blocking). |
<V> CompletionStage<V> |
whenCompleteBlocking(CompletionStage<V> stage,
BiConsumer<? super V,? super Throwable> biConsumer,
Object traceId)
Replacement for
CompletionStage.whenCompleteAsync() that invokes the BiConsumer in a blocking thread
(if the current thread is non-blocking) or in the current thread (if the current thread is blocking). |
protected void start()
public CompletionStage<Void> runBlocking(Runnable runnable, Object traceId)
BlockingManager
CompletionStage.runAsync()
that invokes the Runnable
in a blocking thread
if the current thread is non-blocking or in the current thread if the current thread is blocking.
The returned stage, if not complete, resumes any chained stage on the non-blocking executor.
Note that if the current thread is blocking, the task is invoked in the current thread, meaning the stage is always completed when returned, so any chained stage is also invoked on the current thread.
runBlocking
in interface BlockingManager
runnable
- blocking operation that runs some code.traceId
- an identifier that can be used to tell in a trace when an operation moves between threads.public <E> CompletionStage<Void> subscribeBlockingConsumer(org.reactivestreams.Publisher<E> publisher, Consumer<E> consumer, Object traceId)
BlockingManager
If no values are published the returned stage will be completed upon return of this method and require no thread context switches
Note that if the current thread is blocking everything including subscription, publication and consumption of values will be done on the current thread.
subscribeBlockingConsumer
in interface BlockingManager
E
- the type of entriespublisher
- publisher of values to consumeconsumer
- consumer to handle the valuestraceId
- an identifier that can be used to tell in a trace when an operation moves between threadspublic <T,A,R> CompletionStage<R> subscribeBlockingCollector(org.reactivestreams.Publisher<T> publisher, Collector<? super T,A,R> collector, Object traceId)
BlockingManager
If no values are published the returned stage will be completed upon return of this method and require no thread context switches
Note that if the current thread is blocking everything including subscription, publication and collection of values will be done on the current thread.
subscribeBlockingCollector
in interface BlockingManager
T
- the type of entriesA
- accumulator type of the entriesR
- final value typepublisher
- publisher of values to collectcollector
- collector of the valuestraceId
- an identifier that can be used to tell in a trace when an operation moves between threadspublic <V> CompletionStage<V> supplyBlocking(Supplier<V> supplier, Object traceId)
BlockingManager
CompletionStage.supplyAsync()
that invokes the Supplier
in a blocking thread
(if the current thread is non-blocking) or in the current thread (if the current thread is blocking).
The returned stage, if not complete, resumes any chained stage on the non-blocking executor.
Note that if the current thread is blocking, the task is invoked in the current thread meaning the stage is always completed when returned, so any chained stage is also invoked on the current thread.
supplyBlocking
in interface BlockingManager
V
- the supplied type.supplier
- blocking operation that returns a value.traceId
- an identifier that can be used to tell in a trace when an operation moves between threads.public <I,O> CompletionStage<O> handleBlocking(CompletionStage<? extends I> stage, BiFunction<? super I,Throwable,? extends O> function, Object traceId)
BlockingManager
CompletionStage.handleAsync()
that invokes the BiFunction
in a blocking thread
(if the current thread is non-blocking) or in the current thread (if the current thread is blocking).
The returned stage, if not complete, resumes any chained stage on the non-blocking executor.
Note that if the current thread is blocking, the task is invoked in the current thread meaning the stage is always completed when returned, so any chained stage is also invoked on the current thread.
handleBlocking
in interface BlockingManager
I
- input value type to the function.O
- output value type after being transformed via function.stage
- stage, that may or may not be complete, to handle.function
- the blocking function.traceId
- an identifier that can be used to tell in a trace when an operation moves between threads.public <I,O> CompletionStage<O> thenApplyBlocking(CompletionStage<? extends I> stage, Function<? super I,? extends O> function, Object traceId)
BlockingManager
CompletionStage.thenApplyAsync()
that invokes the Function
in a blocking thread
(if the current thread is non-blocking) or in the current thread (if the current thread is blocking).
The returned stage, if not complete, resumes any chained stage on the non-blocking executor.
Note that if the current thread is blocking, the task is invoked in the current thread meaning the stage is always completed when returned, so any chained stage is also invoked on the current thread.
thenApplyBlocking
in interface BlockingManager
I
- input value type to the function.O
- output value type after being transformed via function.stage
- stage, that may or may not be complete, to apply.function
- the blocking function.traceId
- an identifier that can be used to tell in a trace when an operation moves between threads.public <V> CompletionStage<V> whenCompleteBlocking(CompletionStage<V> stage, BiConsumer<? super V,? super Throwable> biConsumer, Object traceId)
BlockingManager
CompletionStage.whenCompleteAsync()
that invokes the BiConsumer
in a blocking thread
(if the current thread is non-blocking) or in the current thread (if the current thread is blocking).
The returned stage, if not complete, resumes any chained stage on the non-blocking executor.
Note that if the current thread is blocking, the task is invoked in the current thread meaning the stage is always completed when returned, so any chained stage is also invoked on the current thread.
whenCompleteBlocking
in interface BlockingManager
V
- stage value type.stage
- stage, that may or may not be complete, to apply.biConsumer
- the blocking biConsumer.traceId
- an identifier that can be used to tell in a trace when an operation moves between threads.public <V> CompletionStage<V> continueOnNonBlockingThread(CompletionStage<V> delay, Object traceId)
BlockingManager
This method is useful when an asynchronous computation completes and you do not want to run further processing on the thread that returned it. An example may be that some blocking operation is performed on a special blocking thread pool. However when the blocking operation completes we want to continue processing that result in a thread pool that is for computational tasks.
If the supplied stage is already completed when invoking this command, it returns an already completed stage, which means any additional dependent stages are run in the invoking thread.
continueOnNonBlockingThread
in interface BlockingManager
V
- return value type of the supplied stage.delay
- the stage to delay the continuation until complete.traceId
- the identifier to print when tracing is enabled.public <V> org.reactivestreams.Publisher<V> blockingPublisher(org.reactivestreams.Publisher<V> publisher)
BlockingManager
blockingPublisher
in interface BlockingManager
V
- the published entry types.publisher
- the publisher that, when subscribed to, blocks the current thread.public BlockingManager.BlockingExecutor limitedBlockingExecutor(String name, int concurrentExecutions)
BlockingManager
BlockingManager.BlockingExecutor
which is limited to the provided concurrency amount.limitedBlockingExecutor
in interface BlockingManager
name
- name of the limited blocking executor.concurrentExecutions
- maximum amount of concurrent operations to be performed via the returned executor.Copyright © 2021 JBoss by Red Hat. All rights reserved.