SubjectAwareExecutor

{@code Executor} implementation that will automatically first associate any argument {@link Runnable} instances with the currently available {@link Subject} and then dispatch the Subject-enabled runnable to an underlying delegate {@link Executor} instance. <p/> This is a simplification for applications that want to execute code as the currently executing {@code Subject} on another thread, but don't want or need to call the {@link Subject#associateWith(Runnable)} method and dispatch to a Thread manually. This simplifies code and reduces Shiro dependencies across application source code. <p/> Consider this code that could be repeated in many places across an application: <pre> {@link Runnable Runnable} applicationWork = //instantiate or acquire Runnable from somewhere {@link Subject Subject} subject = {@link SecurityUtils SecurityUtils}.{@link SecurityUtils#getSubject() getSubject()}; {@link Runnable Runnable} work = subject.{@link Subject#associateWith(Runnable) associateWith(applicationWork)}; {@link Executor anExecutor}.{@link Executor#execute(Runnable) execute(work)}; </pre> Instead, if the {@code Executor} instance used in application code is an instance of this class (which delegates to the target Executor that you want), all places in code like the above reduce to this: <pre> {@link Runnable Runnable} applicationWork = //instantiate or acquire Runnable from somewhere {@link Executor anExecutor}.{@link Executor#execute(Runnable) execute(work)}; </pre> Notice there is no use of the Shiro API in the 2nd code block, encouraging the principle of loose coupling across your codebase.

@see SubjectAwareExecutorService

Constructors

this
this()
Undocumented in source.
this
this(Executor targetExecutor)
Undocumented in source.

Members

Functions

execute
void execute(Runnable command)

Executes the specified runnable by first associating it with the currently executing {@code Subject} and then dispatches the associated Runnable to the underlying target {@link Executor} instance.

getTargetExecutor
Executor getTargetExecutor()

Returns the target Executor instance that will actually execute the subject-associated Runnable instances.

setTargetExecutor
void setTargetExecutor(Executor targetExecutor)

Sets target Executor instance that will actually execute the subject-associated Runnable instances.

Meta