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
ConstructorsModifierConstructorDescriptionprotectedContextExecutorService(EXECUTOR executorService, Supplier<ContextSnapshot> contextSnapshot) Create an instance ofContextScheduledExecutorService. -
Method Summary
Modifier and TypeMethodDescriptionbooleanawaitTermination(long timeout, TimeUnit unit) protected ContextSnapshotcapture()voidprotected EXECUTORinvokeAll(Collection<? extends Callable<T>> tasks) 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) booleanbooleanvoidshutdown()Future<?><T> Future<T><T> Future<T>static ExecutorServicewrap(ExecutorService service) Variant ofwrap(ExecutorService, Supplier)that usesContextSnapshot.captureAll(Object...)to create the context snapshot.static ExecutorServicewrap(ExecutorService service, Supplier<ContextSnapshot> snapshotSupplier) Wrap the givenExecutorServicein order to propagate context to any executed task through the givenContextSnapshotsupplier.
-
Constructor Details
-
ContextExecutorService
protected ContextExecutorService(EXECUTOR executorService, Supplier<ContextSnapshot> contextSnapshot) Create an instance ofContextScheduledExecutorService.- Parameters:
executorService- theExecutorServiceto delegate tocontextSnapshot- supplier of theContextSnapshot- instruction on who to retrieveContextSnapshotwhen tasks are scheduled
-
-
Method Details
-
getExecutorService
-
submit
- Specified by:
submitin interfaceExecutorService
-
submit
- Specified by:
submitin interfaceExecutorService
-
submit
- 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
-
execute
-
isShutdown
public boolean isShutdown()- Specified by:
isShutdownin interfaceExecutorService
-
isTerminated
public boolean isTerminated()- Specified by:
isTerminatedin interfaceExecutorService
-
shutdown
public void shutdown()- Specified by:
shutdownin interfaceExecutorService
-
shutdownNow
- Specified by:
shutdownNowin interfaceExecutorService
-
awaitTermination
- Specified by:
awaitTerminationin interfaceExecutorService- Throws:
InterruptedException
-
capture
-
wrap
public static ExecutorService wrap(ExecutorService service, Supplier<ContextSnapshot> snapshotSupplier) Wrap the givenExecutorServicein order to propagate context to any executed task through the givenContextSnapshotsupplier.- Parameters:
service- the executorService to wrapsnapshotSupplier- supplier for capturing aContextSnapshotat 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
-