类 AsyncExecutionAspectSupport
- 所有已实现的接口:
infra.beans.factory.Aware,infra.beans.factory.BeanFactoryAware
- 直接已知子类:
AsyncExecutionInterceptor
infra.scheduling.annotation.AnnotationAsyncExecutionInterceptor
or infra.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.
- 从以下版本开始:
- 4.0
- 作者:
- Chris Beams, Juergen Hoeller, Stephane Nicoll, Harry Yang
-
字段概要
字段修饰符和类型字段说明private infra.beans.factory.BeanFactorystatic final StringThe default name of theTaskExecutorbean to pick up: "taskExecutor".private infra.util.function.SingletonSupplier<Executor>private infra.core.StringValueResolverprivate infra.util.function.SingletonSupplier<AsyncUncaughtExceptionHandler>private final ConcurrentHashMap<Method,infra.core.task.AsyncTaskExecutor> private static final infra.logging.Logger -
构造器概要
构造器构造器说明AsyncExecutionAspectSupport(Executor defaultExecutor) Create a new instance with a defaultAsyncUncaughtExceptionHandler.AsyncExecutionAspectSupport(Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) Create a newAsyncExecutionAspectSupportwith the given exception handler. -
方法概要
修饰符和类型方法说明voidconfigure(Supplier<Executor> defaultExecutor, Supplier<AsyncUncaughtExceptionHandler> exceptionHandler) Configure this aspect with the given executor and exception handler suppliers, applying the corresponding default if a supplier is not resolvable.protected infra.core.task.AsyncTaskExecutordetermineAsyncExecutor(Method method) Determine the specific executor to use when executing the given method.protected ObjectDelegate for actually executing the given task with the chosen executor.protected ExecutorfindQualifiedExecutor(infra.beans.factory.BeanFactory beanFactory, String qualifier) Retrieve a target executor for the given qualifier.protected ExecutorgetDefaultExecutor(infra.beans.factory.BeanFactory beanFactory) Retrieve or build a default executor for this advice instance.protected abstract StringgetExecutorQualifier(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.voidhandleError(Throwable ex, Method method, Object... params) Handles a fatal error thrown while asynchronously invoking the specifiedMethod.voidsetBeanFactory(infra.beans.factory.BeanFactory beanFactory) Set theBeanFactoryto be used when looking up executors by qualifier or when relying on the default executor lookup algorithm.voidsetExceptionHandler(AsyncUncaughtExceptionHandler exceptionHandler) Supply theAsyncUncaughtExceptionHandlerto use to handle exceptions thrown by invoking asynchronous methods with avoidreturn type.voidsetExecutor(Executor defaultExecutor) Supply the executor to be used when executing async methods.
-
字段详细资料
-
log
private static final infra.logging.Logger log -
DEFAULT_TASK_EXECUTOR_BEAN_NAME
The default name of theTaskExecutorbean to pick up: "taskExecutor".Note that the initial lookup happens by type; this is just the fallback in case of multiple executor beans found in the context.
- 另请参阅:
-
beanFactory
@Nullable private infra.beans.factory.BeanFactory beanFactory -
defaultExecutor
-
exceptionHandler
-
executors
-
embeddedValueResolver
@Nullable private infra.core.StringValueResolver embeddedValueResolver
-
-
构造器详细资料
-
AsyncExecutionAspectSupport
Create a new instance with a defaultAsyncUncaughtExceptionHandler.- 参数:
defaultExecutor- theExecutor(typically a FrameworkAsyncTaskExecutororExecutorService) 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
-
AsyncExecutionAspectSupport
public AsyncExecutionAspectSupport(@Nullable Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) Create a newAsyncExecutionAspectSupportwith the given exception handler.- 参数:
defaultExecutor- theExecutor(typically a FrameworkAsyncTaskExecutororExecutorService) 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 factoryexceptionHandler- theAsyncUncaughtExceptionHandlerto use
-
-
方法详细资料
-
configure
public void configure(@Nullable Supplier<Executor> defaultExecutor, @Nullable Supplier<AsyncUncaughtExceptionHandler> exceptionHandler) Configure this aspect with the given executor and exception handler suppliers, applying the corresponding default if a supplier is not resolvable. -
setExecutor
Supply the executor to be used when executing async methods.- 参数:
defaultExecutor- theExecutor(typically a FrameworkAsyncTaskExecutororExecutorService) 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- 另请参阅:
-
setExceptionHandler
Supply theAsyncUncaughtExceptionHandlerto use to handle exceptions thrown by invoking asynchronous methods with avoidreturn type. -
setBeanFactory
public void setBeanFactory(@Nullable infra.beans.factory.BeanFactory beanFactory) Set theBeanFactoryto be used when looking up executors by qualifier or when relying on the default executor lookup algorithm.- 指定者:
setBeanFactory在接口中infra.beans.factory.BeanFactoryAware- 另请参阅:
-
determineAsyncExecutor
Determine the specific executor to use when executing the given method.Should preferably return an
AsyncTaskExecutorimplementation.- 返回:
- the executor to use (or
null, but just if no default executor is available)
-
getExecutorQualifier
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. Returning an empty string ornullindicates that no specific executor has been specified and that the default executor should be used.- 参数:
method- the method to inspect for executor qualifier metadata- 返回:
- the qualifier if specified, otherwise empty String or
null - 另请参阅:
-
findQualifiedExecutor
@Nullable protected Executor findQualifiedExecutor(@Nullable infra.beans.factory.BeanFactory beanFactory, String qualifier) Retrieve a target executor for the given qualifier.- 参数:
qualifier- the qualifier to resolve- 返回:
- the target executor, or
nullif none available - 另请参阅:
-
getDefaultExecutor
@Nullable protected Executor getDefaultExecutor(@Nullable infra.beans.factory.BeanFactory beanFactory) Retrieve or build a default executor for this advice instance. An executor returned from here will be cached for further use.The default implementation searches for a unique
TaskExecutorbean in the context, or for anExecutorbean named "taskExecutor" otherwise. If neither of the two is resolvable, this implementation will returnnull.- 参数:
beanFactory- the BeanFactory to use for a default executor lookup- 返回:
- the default executor, or
nullif none available - 另请参阅:
-
doSubmit
@Nullable protected Object doSubmit(Callable<Object> task, infra.core.task.AsyncTaskExecutor executor, Class<?> returnType) Delegate for actually executing the given task with the chosen executor. -
handleError
Handles a fatal error thrown while asynchronously invoking the specifiedMethod.If the return type of the method is a
Futureobject, 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 currentAsyncUncaughtExceptionHandlerwill be used to manage such exception.- 参数:
ex- the exception to handlemethod- the method that was invokedparams- the parameters used to invoke the method- 抛出:
Exception
-