public abstract class AsyncExecutionAspectSupport extends Object implements BeanFactoryAware
org.springframework.scheduling.annotation.AnnotationAsyncExecutionInterceptor
or org.springframework.scheduling.aspectj.AnnotationAsyncExecutionAspect
.
Provides support for executor qualification on a method-by-method basis.
AsyncExecutionAspectSupport
objects must be constructed with a default Executor
, but each individual method may further qualify a specific Executor
bean to be used when executing it, e.g. through an annotation attribute.
Constructor and Description |
---|
AsyncExecutionAspectSupport(Executor defaultExecutor)
Create a new instance with a default
AsyncUncaughtExceptionHandler . |
AsyncExecutionAspectSupport(Executor defaultExecutor,
AsyncUncaughtExceptionHandler exceptionHandler)
Create a new
AsyncExecutionAspectSupport , using the provided default
executor unless individual async methods indicate via qualifier that a more
specific executor should be used. |
Modifier and Type | Method and Description |
---|---|
protected AsyncTaskExecutor |
determineAsyncExecutor(Method method)
Determine the specific executor to use when executing the given method.
|
protected Object |
doSubmit(Callable<Object> task,
AsyncTaskExecutor executor,
Class<?> returnType)
Delegate for actually executing the given task with the chosen executor.
|
protected abstract String |
getExecutorQualifier(Method method)
Return the qualifier or bean name of the executor to be used when executing the
given async method, typically specified in the form of an annotation attribute.
|
protected void |
handleError(Throwable ex,
Method method,
Object... params)
Handles a fatal error thrown while asynchronously invoking the specified
Method . |
void |
setBeanFactory(BeanFactory beanFactory)
Set the
BeanFactory to be used when looking up executors by qualifier. |
void |
setExceptionHandler(AsyncUncaughtExceptionHandler exceptionHandler)
Supply the
AsyncUncaughtExceptionHandler to use to handle exceptions
thrown by invoking asynchronous methods with a void return type. |
void |
setExecutor(Executor defaultExecutor)
Supply the executor to be used when executing async methods.
|
protected final Log logger
public AsyncExecutionAspectSupport(Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler)
AsyncExecutionAspectSupport
, using the provided default
executor unless individual async methods indicate via qualifier that a more
specific executor should be used.defaultExecutor
- the executor to use when executing asynchronous methodsexceptionHandler
- the AsyncUncaughtExceptionHandler
to usepublic AsyncExecutionAspectSupport(Executor defaultExecutor)
AsyncUncaughtExceptionHandler
.public void setExecutor(Executor defaultExecutor)
defaultExecutor
- the Executor
(typically a Spring AsyncTaskExecutor
or ExecutorService
) to delegate to
unless a more specific executor has been requested via a qualifier on the async
method, in which case the executor will be looked up at invocation time against the
enclosing bean factory.getExecutorQualifier(java.lang.reflect.Method)
,
setBeanFactory(BeanFactory)
public void setExceptionHandler(AsyncUncaughtExceptionHandler exceptionHandler)
AsyncUncaughtExceptionHandler
to use to handle exceptions
thrown by invoking asynchronous methods with a void
return type.public void setBeanFactory(BeanFactory beanFactory)
BeanFactory
to be used when looking up executors by qualifier.setBeanFactory
in interface BeanFactoryAware
beanFactory
- owning BeanFactory (never null
).
The bean can immediately call methods on the factory.BeanInitializationException
protected AsyncTaskExecutor determineAsyncExecutor(Method method)
AsyncListenableTaskExecutor
implementation.null
, but just if no default executor has been set)protected abstract String getExecutorQualifier(Method method)
null
indicates that no specific executor has
been specified and that the default executor
should be used.method
- the method to inspect for executor qualifier metadatanull
determineAsyncExecutor(Method)
protected Object doSubmit(Callable<Object> task, AsyncTaskExecutor executor, Class<?> returnType)
protected void handleError(Throwable ex, Method method, Object... params) throws Exception
Method
.
If the return type of the method is a Future
object, the original
exception can be propagated by just throwing it at the higher level. However,
for all other cases, the exception will not be transmitted back to the client.
In that later case, the current AsyncUncaughtExceptionHandler
will be
used to manage such exception.
ex
- the exception to handlemethod
- the method that was invokedparams
- the parameters used to invoke the methodException