Commit Graph

22 Commits

Author SHA1 Message Date
Chris Beams 8bab873107 Support executor qualification with @Async#value
Prior to this change, Spring's @Async annotation support was tied to a
single AsyncTaskExecutor bean, meaning that all methods marked with
@Async were forced to use the same executor. This is an undesirable
limitation, given that certain methods may have different priorities,
etc. This leads to the need to (optionally) qualify which executor
should handle each method.

This is similar to the way that Spring's @Transactional annotation was
originally tied to a single PlatformTransactionManager, but in Spring
3.0 was enhanced to allow for a qualifier via the #value attribute, e.g.

  @Transactional(ptm1)
  public void m() { ... }

where ptm1 is either the name of a PlatformTransactionManager bean or
a qualifier value associated with a PlatformTransactionManager bean,
e.g. via the <qualifier> element in XML or the @Qualifier annotation.

This commit introduces the same approach to @Async and its relationship
to underlying executor beans. As always, the following syntax remains
supported

  @Async
  public void m() { ... }

indicating that calls to #m will be delegated to the default executor,
i.e. the executor provided to

  <task:annotation-driven executor=.../>

or the executor specified when authoring a @Configuration class that
implements AsyncConfigurer and its #getAsyncExecutor method.

However, it now also possible to qualify which executor should be used
on a method-by-method basis, e.g.

  @Async(e1)
  public void m() { ... }

indicating that calls to #m will be delegated to the executor bean
named or otherwise qualified as e1. Unlike the default executor
which is specified up front at configuration time as described above,
the e1 executor bean is looked up within the container on the first
execution of #m and then cached in association with that method for the
lifetime of the container.

Class-level use of Async#value behaves as expected, indicating that all
methods within the annotated class should be executed with the named
executor. In the case of both method- and class-level annotations, any
method-level #value overrides any class level #value.

This commit introduces the following major changes:

 - Add @Async#value attribute for executor qualification

 - Introduce AsyncExecutionAspectSupport as a common base class for
   both MethodInterceptor- and AspectJ-based async aspects. This base
   class provides common structure for specifying the default executor
   (#setExecutor) as well as logic for determining (and caching) which
   executor should execute a given method (#determineAsyncExecutor) and
   an abstract method to allow subclasses to provide specific strategies
   for executor qualification (#getExecutorQualifier).

 - Introduce AnnotationAsyncExecutionInterceptor as a specialization of
   the existing AsyncExecutionInterceptor to allow for introspection of
   the @Async annotation and its #value attribute for a given method.
   Note that this new subclass was necessary for packaging reasons -
   the original AsyncExecutionInterceptor lives in
   org.springframework.aop and therefore does not have visibility to
   the @Async annotation in org.springframework.scheduling.annotation.
   This new subclass replaces usage of AsyncExecutionInterceptor
   throughout the framework, though the latter remains usable and
   undeprecated for compatibility with any existing third-party
   extensions.

 - Add documentation to spring-task-3.2.xsd and reference manual
   explaining @Async executor qualification

 - Add tests covering all new functionality

Note that the public API of all affected components remains backward-
compatible.

Issue: SPR-9443
Backport-Issue: SPR-6847
Backport-Commit: ed0576c181
2012-06-27 23:06:54 +02:00
Chris Beams 41c405998e Convert CRLF=>LF on files missed earlier
Complete pass with `dos2unix` found additional files missed on earlier
related commit.

Issue: SPR-5608
2011-12-22 14:06:44 +01:00
Chris Beams d35620511e Introduce @EnableSpringConfigured
Equivalent to <context:spring-configured/>.

Also update @EnableLoadTimeWeaving Javadoc and spring-configured XSD
documentation to reflect.

Issue: SPR-7888
2011-11-28 06:57:17 +00:00
Juergen Hoeller b5520bc01a shortened build properties "org.junit.version" to "junit.version" and "org.testng.version" to "testng.version"; reverted SLF4J version back to 1.5.3 (for Hibernate 3.3.1 compatibility) 2011-06-09 13:01:09 +00:00
Chris Beams de50789cb6 Introduce @EnableAsync
Introduce @EnableAsync#order

AsyncAnnotationBeanPostProcessor's 'order' property is now mutable;
@EnableAsync's 'order()' attribute allows for setting it, but must
have a default value, thus uses the new Ordered#NOT_ORDERED
constant - a reserved negative number very unlikely to be otherwise
used that may be interpreted as 'not ordered', useful in annotation
defaulting scenarios where null is not an option.

Introduce first working cut of AsyncConfiguration

Remove AsyncCapability
2011-05-06 19:08:53 +00:00
Costin Leau caf1a0875a SPR-7308
+ add updated IDE classpath
+ add updated OSGi manifest
2010-10-29 17:17:38 +00:00
Juergen Hoeller 82ec515e59 declared JPA API as optional (SPR-6819) 2010-10-20 05:37:25 +00:00
Costin Leau 6e516b7281 SPR-6819
+ change jpa Maven dependency from provided to compile
2010-09-21 23:14:22 +00:00
Ben Hale 7730e76c06 Publishing license and notice files 2010-08-23 13:17:31 +00:00
Costin Leau 94292cad1c SPR-6819
+ fix EBR pom as well
2010-06-25 09:32:29 +00:00
Juergen Hoeller 99c5a70ce3 added optional JPA dependency to spring-aspects POM (SPR-6819) 2010-02-10 23:02:31 +00:00
Costin Leau 0fd4a45070 + upgrade to AspectJ 1.6.8
+ externalize some of the jar versions
+ align the versions of some dependencies between pom.xml and ivy.xml
2010-02-04 11:46:21 +00:00
David Syer 1202f67cc8 SPR-5327: tweak the ivy.xml so that commons-logging is a separate configuration. It already comes out as optional in the generated poms (including core), which isn't great, but I can't see what is causing that 2009-12-04 18:25:31 +00:00
Juergen Hoeller 0b577dd558 fixed dependencies 2009-12-03 13:15:33 +00:00
Ramnivas Laddad d1f3772ca1 Fixed a build issue 2009-10-27 19:35:01 +00:00
Ramnivas Laddad 66261ecb8c Moved over JPA exception translator from Roo 2009-10-27 19:15:54 +00:00
Ramnivas Laddad 064343d056 Make JUnit a compile-time dependency, since static mock functionality depends on its annotations. 2009-10-27 17:23:23 +00:00
Ramnivas Laddad 451bbce345 Moved over static mock testing from Roo; added tests 2009-10-27 17:16:02 +00:00
Mark Pollack bd098ce1db pom maintenance - sync with ivy.xml
update junit version in ivy.xml for org.sf.aspects
2009-09-24 06:09:54 +00:00
Ramnivas Laddad 7199fcc233 Fixed SPR-5918.
Had to override the test.do definition in build.xml. Need to consult the spring-build team to add the change to spring-build itself. 
Since classes in test sources from another project cannot be shared, had to duplicate those classes.
2009-07-12 04:47:59 +00:00
Chris Beams d7a9d7c8e6 + refactoring .testsuite .aop.aspectj tests in preparation for migration to .context
+ updated all ivy.xml files to depend on AspectJ 1.6.2
2008-12-19 14:56:09 +00:00
Arjen Poutsma 7d62aab6cc Initial import of the aspects module 2008-10-28 11:42:01 +00:00