Top Description Fields Constructors Methods
org.springframework.scheduling.annotation

public Class AsyncAnnotationAdvisor

extends AbstractPointcutAdvisor
implements BeanFactoryAware
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.Aware
Annotations
@SuppressWarnings:serial
Imports
java.lang.annotation.Annotation, java.util.HashSet, .LinkedHashSet, .Set, java.util.concurrent.Executor, java.util.function.Supplier, org.aopalliance.aop.Advice, org.springframework.aop.Pointcut, org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler, org.springframework.aop.support.AbstractPointcutAdvisor, .ComposablePointcut, org.springframework.aop.support.annotation.AnnotationMatchingPointcut, org.springframework.beans.factory.BeanFactory, .BeanFactoryAware, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, org.springframework.util.function.SingletonSupplier

Advisor that activates asynchronous method execution through the Async annotation. This annotation can be used at the method and type level in implementation classes as well as in service interfaces.

This advisor detects the EJB 3.1 jakarta.ejb.Asynchronous annotation as well, treating it exactly like Spring's own Async. Furthermore, a custom async annotation type may get specified through the "asyncAnnotationType" property.

Author
Juergen Hoeller
Since
3.0
See Also
Async, AnnotationAsyncExecutionInterceptor

Field Summary

Modifier and TypeField and Description
private final Advice
private Pointcut

Constructor Summary

AccessConstructor and Description
public
AsyncAnnotationAdvisor()

Create a new AsyncAnnotationAdvisor for bean-style configuration.

public
AsyncAnnotationAdvisor(Executor
the task executor to use for asynchronous methods (can be null to trigger default executor resolution)
executor
,
AsyncUncaughtExceptionHandler
the AsyncUncaughtExceptionHandler to use to handle unexpected exception thrown by asynchronous method executions
exceptionHandler
)

Create a new AsyncAnnotationAdvisor for the given task executor.

public
AsyncAnnotationAdvisor(Supplier<Executor>
the task executor to use for asynchronous methods (can be null to trigger default executor resolution)
executor
,
Supplier<AsyncUncaughtExceptionHandler>
the AsyncUncaughtExceptionHandler to use to handle unexpected exception thrown by asynchronous method executions
exceptionHandler
)

Create a new AsyncAnnotationAdvisor for the given task executor.

Method Summary

Modifier and TypeMethod and Description
protected Advice
protected Pointcut

Returns:

the applicable Pointcut object, or null if none
buildPointcut
(Set<Class<? extends Annotation>>
the async annotation types to introspect
asyncAnnotationTypes
)

Calculate a pointcut for the given async annotation types, if any.

public Advice
getAdvice()

Implements org.springframework.aop.Advisor.getAdvice.

Return the advice part of this aspect.

public Pointcut
getPointcut()

Implements org.springframework.aop.PointcutAdvisor.getPointcut.

Get the Pointcut that drives this advisor.

public void
setAsyncAnnotationType(Class<? extends Annotation>
the desired annotation type
asyncAnnotationType
)

Set the 'async' annotation type.

public void
setBeanFactory(BeanFactory
owning BeanFactory (never null). The bean can immediately call methods on the factory.
beanFactory
)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Set the BeanFactory to be used when looking up executors by qualifier.

Inherited from org.springframework.aop.support.AbstractPointcutAdvisor:
equalsgetOrderhashCodesetOrder

Field Detail

adviceback to summary
private final Advice advice
pointcutback to summary
private Pointcut pointcut

Constructor Detail

AsyncAnnotationAdvisorback to summary
public AsyncAnnotationAdvisor()

Create a new AsyncAnnotationAdvisor for bean-style configuration.

AsyncAnnotationAdvisorback to summary
public AsyncAnnotationAdvisor(Executor executor, AsyncUncaughtExceptionHandler exceptionHandler)

Create a new AsyncAnnotationAdvisor for the given task executor.

Parameters
executor:Executor

the task executor to use for asynchronous methods (can be null to trigger default executor resolution)

exceptionHandler:AsyncUncaughtExceptionHandler

the AsyncUncaughtExceptionHandler to use to handle unexpected exception thrown by asynchronous method executions

See Also
AnnotationAsyncExecutionInterceptor#getDefaultExecutor(BeanFactory)
AsyncAnnotationAdvisorback to summary
public AsyncAnnotationAdvisor(Supplier<Executor> executor, Supplier<AsyncUncaughtExceptionHandler> exceptionHandler)

Create a new AsyncAnnotationAdvisor for the given task executor.

Parameters
executor:Supplier<Executor>

the task executor to use for asynchronous methods (can be null to trigger default executor resolution)

exceptionHandler:Supplier<AsyncUncaughtExceptionHandler>

the AsyncUncaughtExceptionHandler to use to handle unexpected exception thrown by asynchronous method executions

Annotations
@SuppressWarnings:unchecked
Since
5.1
See Also
AnnotationAsyncExecutionInterceptor#getDefaultExecutor(BeanFactory)

Method Detail

buildAdviceback to summary
protected Advice buildAdvice(Supplier<Executor> executor, Supplier<AsyncUncaughtExceptionHandler> exceptionHandler)
buildPointcutback to summary
protected Pointcut buildPointcut(Set<Class<? extends Annotation>> asyncAnnotationTypes)

Calculate a pointcut for the given async annotation types, if any.

Parameters
asyncAnnotationTypes:Set<Class<? extends Annotation>>

the async annotation types to introspect

Returns:Pointcut

the applicable Pointcut object, or null if none

getAdviceback to summary
public Advice getAdvice()

Implements org.springframework.aop.Advisor.getAdvice.

Doc from org.springframework.aop.Advisor.getAdvice.

Return the advice part of this aspect. An advice may be an interceptor, a before advice, a throws advice, etc.

Returns:Advice

the advice that should apply if the pointcut matches

Annotations
@Override
getPointcutback to summary
public Pointcut getPointcut()

Implements org.springframework.aop.PointcutAdvisor.getPointcut.

Doc from org.springframework.aop.PointcutAdvisor.getPointcut.

Get the Pointcut that drives this advisor.

Annotations
@Override
setAsyncAnnotationTypeback to summary
public void setAsyncAnnotationType(Class<? extends Annotation> asyncAnnotationType)

Set the 'async' annotation type.

The default async annotation type is the Async annotation, as well as the EJB 3.1 jakarta.ejb.Asynchronous annotation (if present).

This setter property exists so that developers can provide their own (non-Spring-specific) annotation type to indicate that a method is to be executed asynchronously.

Parameters
asyncAnnotationType:Class<? extends Annotation>

the desired annotation type

setBeanFactoryback to summary
public void setBeanFactory(BeanFactory beanFactory)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Set the BeanFactory to be used when looking up executors by qualifier.

Parameters
beanFactory:BeanFactory

Doc from org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

owning BeanFactory (never null). The bean can immediately call methods on the factory.

Annotations
@Override