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 classSmallRyeManagedExecutor.Builder
-
Constructor Summary
Constructors Constructor Description SmallRyeManagedExecutor(int maxAsync, int maxQueued, SmallRyeThreadContext threadContext, ExecutorService executor, String injectionPointName)
-
Method Summary
Modifier and Type Method Description booleanawaitTermination(long timeout, TimeUnit unit)static SmallRyeManagedExecutor.Builderbuilder()<U> CompletableFuture<U>completedFuture(U value)<U> CompletionStage<U>completedStage(U value)<T> CompletableFuture<T>copy(CompletableFuture<T> stage)Returns a newCompletableFuturethat is completed by the completion of the specified stage.<T> CompletionStage<T>copy(CompletionStage<T> stage)Returns a newCompletionStagethat is completed by the completion of the specified stage.voidexecute(Runnable command)<U> CompletableFuture<U>failedFuture(Throwable ex)<U> CompletionStage<U>failedStage(Throwable ex)StringgetInjectionPointName()intgetMaxAsync()intgetMaxQueued()SmallRyeThreadContextgetThreadContext()Returns aThreadContextwhich has the same propagation settings as thisManagedExecutor, which uses thisManagedExecutoras its default executor.ThreadContextProviderPlangetThreadContextProviderPlan()<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> TinvokeAny(Collection<? extends Callable<T>> tasks)<T> TinvokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)booleanisShutdown()booleanisTerminated()<U> CompletableFuture<U>newIncompleteFuture()static ExecutorServicenewThreadPoolExecutor(int maxAsync, int maxQueued)CompletableFuture<Void>runAsync(Runnable runnable)voidshutdown()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)StringtoString()
-
-
-
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:
shutdownin interfaceExecutorService
-
shutdownNow
public List<Runnable> shutdownNow()
- Specified by:
shutdownNowin interfaceExecutorService
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdownin interfaceExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminatedin interfaceExecutorService
-
awaitTermination
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException- Specified by:
awaitTerminationin interfaceExecutorService- Throws:
InterruptedException
-
submit
public <T> Future<T> submit(Callable<T> task)
- Specified by:
submitin interfaceExecutorService
-
submit
public <T> Future<T> submit(Runnable task, T result)
- Specified by:
submitin interfaceExecutorService
-
submit
public Future<?> submit(Runnable task)
- Specified by:
submitin interfaceExecutorService
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
- Specified by:
invokeAllin interfaceExecutorService- Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
invokeAllin interfaceExecutorService- Throws:
InterruptedException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException
- Specified by:
invokeAnyin interfaceExecutorService- Throws:
InterruptedExceptionExecutionException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
invokeAnyin interfaceExecutorService- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
completedFuture
public <U> CompletableFuture<U> completedFuture(U value)
- Specified by:
completedFuturein interfaceorg.eclipse.microprofile.context.ManagedExecutor
-
completedStage
public <U> CompletionStage<U> completedStage(U value)
- Specified by:
completedStagein interfaceorg.eclipse.microprofile.context.ManagedExecutor
-
failedFuture
public <U> CompletableFuture<U> failedFuture(Throwable ex)
- Specified by:
failedFuturein interfaceorg.eclipse.microprofile.context.ManagedExecutor
-
failedStage
public <U> CompletionStage<U> failedStage(Throwable ex)
- Specified by:
failedStagein interfaceorg.eclipse.microprofile.context.ManagedExecutor
-
runAsync
public CompletableFuture<Void> runAsync(Runnable runnable)
- Specified by:
runAsyncin interfaceorg.eclipse.microprofile.context.ManagedExecutor
-
supplyAsync
public <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier)
- Specified by:
supplyAsyncin interfaceorg.eclipse.microprofile.context.ManagedExecutor
-
newIncompleteFuture
public <U> CompletableFuture<U> newIncompleteFuture()
- Specified by:
newIncompleteFuturein 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
CompletableFuturethat 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.
- Specified by:
copyin interfaceorg.eclipse.microprofile.context.ManagedExecutor- 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
CompletionStagethat 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.
- Specified by:
copyin interfaceorg.eclipse.microprofile.context.ManagedExecutor- 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 aThreadContextwhich has the same propagation settings as thisManagedExecutor, which uses thisManagedExecutoras its default executor.- Specified by:
getThreadContextin interfaceorg.eclipse.microprofile.context.ManagedExecutor- Returns:
- a ThreadContext with the same propagation settings as this ManagedExecutor.
-
-