Class SmallRyeManagedExecutor
- java.lang.Object
-
- io.smallrye.context.SmallRyeManagedExecutor
-
- All Implemented Interfaces:
Executor
,ExecutorService
,org.eclipse.microprofile.context.ManagedExecutor
public class SmallRyeManagedExecutor extends Object implements org.eclipse.microprofile.context.ManagedExecutor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SmallRyeManagedExecutor.Builder
-
Constructor Summary
Constructors Constructor Description SmallRyeManagedExecutor(int maxAsync, int maxQueued, SmallRyeThreadContext threadContext, ExecutorService executor, String injectionPointName)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
awaitTermination(long timeout, TimeUnit unit)
static SmallRyeManagedExecutor.Builder
builder()
<U> CompletableFuture<U>
completedFuture(U value)
<U> CompletionStage<U>
completedStage(U value)
<T> CompletableFuture<T>
copy(CompletableFuture<T> stage)
Returns a newCompletableFuture
that is completed by the completion of the specified stage.<T> CompletionStage<T>
copy(CompletionStage<T> stage)
Returns a newCompletionStage
that is completed by the completion of the specified stage.void
execute(Runnable command)
<U> CompletableFuture<U>
failedFuture(Throwable ex)
<U> CompletionStage<U>
failedStage(Throwable ex)
String
getInjectionPointName()
int
getMaxAsync()
int
getMaxQueued()
SmallRyeThreadContext
getThreadContext()
Returns aThreadContext
which has the same propagation settings as thisManagedExecutor
, which uses thisManagedExecutor
as its default executor.ThreadContextProviderPlan
getThreadContextProviderPlan()
<T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>> tasks)
<T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
<T> T
invokeAny(Collection<? extends Callable<T>> tasks)
<T> T
invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
boolean
isShutdown()
boolean
isTerminated()
<U> CompletableFuture<U>
newIncompleteFuture()
static ExecutorService
newThreadPoolExecutor(int maxAsync, int maxQueued)
CompletableFuture<Void>
runAsync(Runnable runnable)
void
shutdown()
List<Runnable>
shutdownNow()
Future<?>
submit(Runnable task)
<T> Future<T>
submit(Runnable task, T result)
<T> Future<T>
submit(Callable<T> task)
<U> CompletableFuture<U>
supplyAsync(Supplier<U> supplier)
String
toString()
-
-
-
Constructor Detail
-
SmallRyeManagedExecutor
public SmallRyeManagedExecutor(int maxAsync, int maxQueued, SmallRyeThreadContext threadContext, ExecutorService executor, String injectionPointName)
-
-
Method Detail
-
newThreadPoolExecutor
public static ExecutorService newThreadPoolExecutor(int maxAsync, int maxQueued)
-
shutdown
public void shutdown()
- Specified by:
shutdown
in interfaceExecutorService
-
shutdownNow
public List<Runnable> shutdownNow()
- Specified by:
shutdownNow
in interfaceExecutorService
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdown
in interfaceExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminated
in interfaceExecutorService
-
awaitTermination
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
awaitTermination
in interfaceExecutorService
- Throws:
InterruptedException
-
submit
public <T> Future<T> submit(Callable<T> task)
- Specified by:
submit
in interfaceExecutorService
-
submit
public <T> Future<T> submit(Runnable task, T result)
- Specified by:
submit
in interfaceExecutorService
-
submit
public Future<?> submit(Runnable task)
- Specified by:
submit
in interfaceExecutorService
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
- Specified by:
invokeAll
in interfaceExecutorService
- Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
invokeAll
in interfaceExecutorService
- Throws:
InterruptedException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException
- Specified by:
invokeAny
in interfaceExecutorService
- Throws:
InterruptedException
ExecutionException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
invokeAny
in interfaceExecutorService
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
completedFuture
public <U> CompletableFuture<U> completedFuture(U value)
- Specified by:
completedFuture
in interfaceorg.eclipse.microprofile.context.ManagedExecutor
-
completedStage
public <U> CompletionStage<U> completedStage(U value)
- Specified by:
completedStage
in interfaceorg.eclipse.microprofile.context.ManagedExecutor
-
failedFuture
public <U> CompletableFuture<U> failedFuture(Throwable ex)
- Specified by:
failedFuture
in interfaceorg.eclipse.microprofile.context.ManagedExecutor
-
failedStage
public <U> CompletionStage<U> failedStage(Throwable ex)
- Specified by:
failedStage
in interfaceorg.eclipse.microprofile.context.ManagedExecutor
-
runAsync
public CompletableFuture<Void> runAsync(Runnable runnable)
- Specified by:
runAsync
in interfaceorg.eclipse.microprofile.context.ManagedExecutor
-
supplyAsync
public <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier)
- Specified by:
supplyAsync
in interfaceorg.eclipse.microprofile.context.ManagedExecutor
-
newIncompleteFuture
public <U> CompletableFuture<U> newIncompleteFuture()
- Specified by:
newIncompleteFuture
in interfaceorg.eclipse.microprofile.context.ManagedExecutor
-
getThreadContextProviderPlan
public ThreadContextProviderPlan getThreadContextProviderPlan()
-
getMaxAsync
public int getMaxAsync()
-
getMaxQueued
public int getMaxQueued()
-
getInjectionPointName
public String getInjectionPointName()
-
builder
public static SmallRyeManagedExecutor.Builder builder()
-
copy
public <T> CompletableFuture<T> copy(CompletableFuture<T> stage)
Returns a new
CompletableFuture
that is completed by the completion of the specified stage.The new completable future is backed by the ManagedExecutor upon which copy is invoked, which serves as the default asynchronous execution facility for the new stage and all dependent stages created from it, and so forth.
When dependent stages are created from the new completable future, thread context is captured and/or cleared by the ManagedExecutor. This guarantees that the action performed by each stage always runs under the thread context of the code that creates the stage, unless the user explicitly overrides by supplying a pre-contextualized action.
Invocation of this method does not impact thread context propagation for the supplied completable future or any dependent stages created from it, other than the new dependent completable future that is created by this method.
- Type Parameters:
T
- completable future result type.- Parameters:
stage
- a completable future whose completion triggers completion of the new completable future that is created by this method.- Returns:
- the new completable future.
-
copy
public <T> CompletionStage<T> copy(CompletionStage<T> stage)
Returns a new
CompletionStage
that is completed by the completion of the specified stage.The new completable future is backed by the ManagedExecutor upon which copy is invoked, which serves as the default asynchronous execution facility for the new stage and all dependent stages created from it, and so forth.
When dependent stages are created from the new completable future, thread context is captured and/or cleared by the ManagedExecutor. This guarantees that the action performed by each stage always runs under the thread context of the code that creates the stage, unless the user explicitly overrides by supplying a pre-contextualized action.
Invocation of this method does not impact thread context propagation for the supplied stage or any dependent stages created from it, other than the new dependent completion stage that is created by this method.
- Type Parameters:
T
- completion stage result type.- Parameters:
stage
- a completion stage whose completion triggers completion of the new stage that is created by this method.- Returns:
- the new completion stage.
-
getThreadContext
public SmallRyeThreadContext getThreadContext()
Returns aThreadContext
which has the same propagation settings as thisManagedExecutor
, which uses thisManagedExecutor
as its default executor.- Returns:
- a ThreadContext with the same propagation settings as this ManagedExecutor.
-
-