Class ScanRunContext
ScanRun, the JUL-friendly
equivalent of SLF4J's MDC.
MethodAtlasApp.run(String[], java.io.PrintWriter) constructs a
ScanRun once at the top of every invocation and calls
set(ScanRun) so that any code executed on the same thread for
the duration of the run can read the correlation id through
current(). A custom java.util.logging.Formatter reads
the context and prepends the run id to every log record (introduced in
Item 20 of the architecture remediation plan).
Thread safety
Each thread sees its own value. The MethodAtlas CLI runs single-threaded
scans by default; AI provider calls are sequential. When concurrent
threads do appear (the ServiceLoader per-plugin
isolation), callers that want the run id on those threads must propagate
it explicitly.
Cleanup
Always pair set(ScanRun) with a clear() in a
finally block — without it, the thread-local reference outlives
the CLI invocation in container deployments that pool threads. The
standard MethodAtlas CLI exits the JVM at end-of-run, so cleanup matters
mainly when MethodAtlas is invoked programmatically.
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidclear()Removes the current scan run from the calling thread.current()Returns the current scan run for the calling thread, orOptional.empty()when no run is currently set (the standard case beforeMethodAtlasApp.main(String[])runs or afterclear()).static voidSets the current scan run for the calling thread.
-
Method Details
-
set
Sets the current scan run for the calling thread.- Parameters:
run- the run identifier; must not benull
-
current
Returns the current scan run for the calling thread, orOptional.empty()when no run is currently set (the standard case beforeMethodAtlasApp.main(String[])runs or afterclear()).- Returns:
- optional carrying the current run
-
clear
public static void clear()Removes the current scan run from the calling thread. Always called in afinallyblock paired withset(ScanRun)so that the thread-local reference does not outlive the CLI invocation.
-