Package io.micrometer.context
Class ContextExecutorService<EXECUTOR extends ExecutorService>
java.lang.Object
io.micrometer.context.ContextExecutorService<EXECUTOR>
- All Implemented Interfaces:
Executor
,ExecutorService
- Direct Known Subclasses:
ContextScheduledExecutorService
public class ContextExecutorService<EXECUTOR extends ExecutorService>
extends Object
implements ExecutorService
Wraps an
ExecutorService
in order to capture context via
ContextSnapshot
when a task is submitted, and propagate context to the task
when it is executed.- Since:
- 1.0.0
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ContextExecutorService
(EXECUTOR executorService, Supplier<ContextSnapshot> contextSnapshot) Create an instance ofContextScheduledExecutorService
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
awaitTermination
(long timeout, TimeUnit unit) protected ContextSnapshot
capture()
void
protected EXECUTOR
invokeAll
(Collection<? extends Callable<T>> tasks) 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
boolean
void
shutdown()
Future<?>
<T> Future<T>
<T> Future<T>
static ExecutorService
wrap
(ExecutorService service) Variant ofwrap(ExecutorService, Supplier)
that usesContextSnapshot.captureAll(Object...)
to create the context snapshot.static ExecutorService
wrap
(ExecutorService service, Supplier<ContextSnapshot> snapshotSupplier) Wrap the givenExecutorService
in order to propagate context to any executed task through the givenContextSnapshot
supplier.
-
Constructor Details
-
ContextExecutorService
protected ContextExecutorService(EXECUTOR executorService, Supplier<ContextSnapshot> contextSnapshot) Create an instance ofContextScheduledExecutorService
.- Parameters:
executorService
- theExecutorService
to delegate tocontextSnapshot
- supplier of theContextSnapshot
- instruction on who to retrieveContextSnapshot
when tasks are scheduled
-
-
Method Details
-
getExecutorService
-
submit
- Specified by:
submit
in interfaceExecutorService
-
submit
- Specified by:
submit
in interfaceExecutorService
-
submit
- 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
-
execute
-
isShutdown
public boolean isShutdown()- Specified by:
isShutdown
in interfaceExecutorService
-
isTerminated
public boolean isTerminated()- Specified by:
isTerminated
in interfaceExecutorService
-
shutdown
public void shutdown()- Specified by:
shutdown
in interfaceExecutorService
-
shutdownNow
- Specified by:
shutdownNow
in interfaceExecutorService
-
awaitTermination
- Specified by:
awaitTermination
in interfaceExecutorService
- Throws:
InterruptedException
-
capture
-
wrap
public static ExecutorService wrap(ExecutorService service, Supplier<ContextSnapshot> snapshotSupplier) Wrap the givenExecutorService
in order to propagate context to any executed task through the givenContextSnapshot
supplier.- Parameters:
service
- the executorService to wrapsnapshotSupplier
- supplier for capturing aContextSnapshot
at the point when tasks are scheduled
-
wrap
Variant ofwrap(ExecutorService, Supplier)
that usesContextSnapshot.captureAll(Object...)
to create the context snapshot.- Parameters:
service
- the executorService to wrap
-