Class RequestAttributesPropagatingExecutor

java.lang.Object
com.fayupable.logged.spring.security.RequestAttributesPropagatingExecutor
All Implemented Interfaces:
Executor

public final class RequestAttributesPropagatingExecutor extends Object implements 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

    Constructors
    Constructor
    Description
    Wraps delegate so that every task submitted through this executor carries the submitting thread's RequestAttributes into whichever thread delegate actually runs it on.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    execute(@NonNull Runnable command)
    Captures the calling thread's current RequestAttributes and submits a wrapped task to the delegate executor that restores them before running command and restores the executor thread's own previous request attributes again afterward, regardless of whether command completes normally or throws.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RequestAttributesPropagatingExecutor

      public RequestAttributesPropagatingExecutor(Executor delegate)
      Wraps delegate so that every task submitted through this executor carries the submitting thread's RequestAttributes into whichever thread delegate actually runs it on.
      Parameters:
      delegate - the executor that will actually run submitted tasks
  • Method Details

    • execute

      public void execute(@NonNull Runnable command)
      Captures the calling thread's current RequestAttributes and submits a wrapped task to the delegate executor that restores them before running command and restores the executor thread's own previous request attributes again afterward, regardless of whether command completes normally or throws.
      Specified by:
      execute in interface Executor
      Parameters:
      command - the task to run