Class RequestAttributesPropagatingExecutor
- All Implemented Interfaces:
Executor
Executor decorator that carries the submitting thread's Spring Web
RequestAttributes over to whatever thread actually runs the
submitted task.
com.fayupable.logged.spring.aspect.FlowContextPropagatingExecutor
solves the equivalent problem for this library's own call-chain tracking.
That class deliberately does not also propagate RequestAttributes,
so that it stays usable in applications with no Spring Web on the
classpath at all. This class fills that specific gap for applications
that do have Spring Web: without it, a nested @Logged call made
from inside work submitted through a plain, unwrapped executor loses
access to the current HTTP request entirely on the executor thread, and
this library's IP-based caller identity resolution silently falls back to
"unknown" for that nested call.
Wrap once, alongside FlowContextPropagatingExecutor if both are
needed, by nesting decorators around the same delegate:
Executor propagating = new FlowContextPropagatingExecutor(
new RequestAttributesPropagatingExecutor(realExecutor));
This class is deliberately not wired in automatically anywhere in this
library's auto-configuration: a consuming application decides which
executor should carry the current request across a thread hand-off, the
same way it decides which methods get @Logged in the first place.
-
Constructor Summary
ConstructorsConstructorDescriptionRequestAttributesPropagatingExecutor(Executor delegate) Wrapsdelegateso that every task submitted through this executor carries the submitting thread'sRequestAttributesinto whichever threaddelegateactually runs it on. -
Method Summary
Modifier and TypeMethodDescriptionvoidCaptures the calling thread's currentRequestAttributesand submits a wrapped task to the delegate executor that restores them before runningcommandand restores the executor thread's own previous request attributes again afterward, regardless of whethercommandcompletes normally or throws.
-
Constructor Details
-
RequestAttributesPropagatingExecutor
Wrapsdelegateso that every task submitted through this executor carries the submitting thread'sRequestAttributesinto whichever threaddelegateactually runs it on.- Parameters:
delegate- the executor that will actually run submitted tasks
-
-
Method Details
-
execute
Captures the calling thread's currentRequestAttributesand submits a wrapped task to the delegate executor that restores them before runningcommandand restores the executor thread's own previous request attributes again afterward, regardless of whethercommandcompletes normally or throws.
-