|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.shiro.concurrent.SubjectAwareExecutor
public class SubjectAwareExecutor
Executor
implementation that will automatically first associate any argument
Runnable
instances with the currently available Subject
and then
dispatch the Subject-enabled runnable to an underlying delegate Executor
instance.
Subject
on another thread, but don't want or need to call the
Subject.associateWith(Runnable)
method and dispatch to a Thread manually. This
simplifies code and reduces Shiro dependencies across application source code.
Consider this code that could be repeated in many places across an application:
Instead, if theRunnable
applicationWork = //instantiate or acquire Runnable from somewhereSubject
subject =SecurityUtils
.getSubject()
;Runnable
work = subject.associateWith(applicationWork)
;anExecutor
.execute(work)
;
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:
Notice there is no use of the Shiro API in the 2nd code block, encouraging the principle of loose coupling across your codebase.Runnable
applicationWork = //instantiate or acquire Runnable from somewhereanExecutor
.execute(work)
;
SubjectAwareExecutorService
Constructor Summary | |
---|---|
SubjectAwareExecutor()
|
|
SubjectAwareExecutor(Executor targetExecutor)
|
Method Summary | |
---|---|
protected Runnable |
associateWithSubject(Runnable r)
Utility method for subclasses to associate the argument Runnable with the currently executing subject
and then return the associated Runnable. |
void |
execute(Runnable command)
Executes the specified runnable by first associating it with the currently executing Subject and then
dispatches the associated Runnable to the underlying target Executor instance. |
protected Subject |
getSubject()
Returns the currently Subject instance that should be associated with Runnable or Callable instances before being dispatched to the target Executor instance. |
Executor |
getTargetExecutor()
Returns the target Executor instance that will actually execute the subject-associated Runnable instances. |
void |
setTargetExecutor(Executor targetExecutor)
Sets target Executor instance that will actually execute the subject-associated Runnable instances. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SubjectAwareExecutor()
public SubjectAwareExecutor(Executor targetExecutor)
Method Detail |
---|
public Executor getTargetExecutor()
public void setTargetExecutor(Executor targetExecutor)
targetExecutor
- the target Executor instance that will actually execute the subject-associated Runnable
instances.protected Subject getSubject()
Executor
instance. This implementation merely defaults to returning
SecurityUtils
.getSubject()
.
Executor
instance.protected Runnable associateWithSubject(Runnable r)
Runnable
with the currently executing subject
and then return the associated Runnable. The default implementation merely defaults to
Subject subject =getSubject()
; return subject.associateWith(r)
;
r
- the argument runnable to be associated with the current subject
public void execute(Runnable command)
Subject
and then
dispatches the associated Runnable to the underlying target Executor
instance.
execute
in interface Executor
command
- the runnable to associate with the currently executing subject and then to execute via the target
Executor
instance.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |