Package org.apache.shiro.concurrent
Class SubjectAwareExecutorService
-
- org.apache.shiro.concurrent.SubjectAwareExecutor
-
- org.apache.shiro.concurrent.SubjectAwareExecutorService
-
- All Implemented Interfaces:
,
- Direct Known Subclasses:
SubjectAwareScheduledExecutorService
public class SubjectAwareExecutorService extends SubjectAwareExecutor implements
ExecutorService
implementation that will automatically first associate any argument or instances with thecurrently available subject
and then dispatch the Subject-enabled runnable or callable to an underlying delegate instance. The principle is the same as the parent API. This is a simplification for applications that want to execute code as the currently executingSubject
on another thread, but don't want or need to call theSubject.associateWith(Runnable)
orSubject.associateWith(Callable)
methods and dispatch them 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:applicationWork = //instantiate or acquire Callable from somewhere
Instead, if theSubject
subject =SecurityUtils
.getSubject()
; work = subject.associateWith(applicationWork)
; .;ExecutorService
instance used at runtime is an instance of this class (which delegates to the target ExecutorService that you want), all places in code like the above reduce to this:applicationWork = //instantiate or acquire Callable from somewhere .;
Notice there is no use of the Shiro API in the 2nd code block, encouraging the principle of loose coupling across your codebase.- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description SubjectAwareExecutorService()
target)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T> <<T>>
<? extends <T>> tasks)
protected <T> <T>
<T> task)
boolean
awaitTermination(long timeout, unit)
getTargetExecutorService()
<T> <<T>>
<? extends <T>> tasks)
<T> <<T>>
<? extends <T>> tasks, long timeout, unit)
<T> T
<? extends <T>> tasks)
<T> T
<? extends <T>> tasks, long timeout, unit)
boolean
isShutdown()
boolean
isTerminated()
void
targetExecutor)
Sets target Executor instance that will actually execute the subject-associated Runnable instances.void
targetExecutorService)
void
shutdown()
<>
shutdownNow()
<?>
task)
<T> <T>
task, T result)
<T> <T>
<T> task)
-
Methods inherited from class org.apache.shiro.concurrent.SubjectAwareExecutor
associateWithSubject, execute, getSubject, getTargetExecutor
-
-
-
-
Method Detail
-
getTargetExecutorService
public getTargetExecutorService()
-
setTargetExecutorService
public void setTargetExecutorService( targetExecutorService)
-
setTargetExecutor
public void setTargetExecutor( targetExecutor)
Description copied from class:SubjectAwareExecutor
Sets target Executor instance that will actually execute the subject-associated Runnable instances.- Overrides:
setTargetExecutor
in classSubjectAwareExecutor
- Parameters:
targetExecutor
- the target Executor instance that will actually execute the subject-associated Runnable instances.
-
shutdown
public void shutdown()
- Specified by:
in interface
-
shutdownNow
public <> shutdownNow()
- Specified by:
in interface
-
isShutdown
public boolean isShutdown()
- Specified by:
in interface
-
isTerminated
public boolean isTerminated()
- Specified by:
in interface
-
awaitTermination
public boolean awaitTermination(long timeout, unit) throws
- Specified by:
in interface
- Throws:
-
associateWithSubject
protected <T> <T> associateWithSubject(<T> task)
-
submit
public <T> <T> submit(<T> task)
- Specified by:
in interface
-
submit
public <T> <T> submit( task, T result)
- Specified by:
in interface
-
submit
public <?> submit( task)
- Specified by:
in interface
-
associateWithSubject
protected <T> <<T>> associateWithSubject(<? extends <T>> tasks)
-
invokeAll
public <T> <<T>> invokeAll(<? extends <T>> tasks) throws
- Specified by:
in interface
- Throws:
-
invokeAll
public <T> <<T>> invokeAll(<? extends <T>> tasks, long timeout, unit) throws
- Specified by:
in interface
- Throws:
-
invokeAny
public <T> T invokeAny(<? extends <T>> tasks) throws ,
- Specified by:
in interface
- Throws:
-
invokeAny
public <T> T invokeAny(<? extends <T>> tasks, long timeout, unit) throws , ,
- Specified by:
in interface
- Throws:
-
-