• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TAKETODAY / today-infrastructure / 18154768944

01 Oct 2025 07:26AM UTC coverage: 81.882% (-0.005%) from 81.887%
18154768944

push

github

web-flow
Merge pull request #290 from TAKETODAY/dev/jspecify

jspecify

59788 of 78013 branches covered (76.64%)

Branch coverage included in aggregate %.

141239 of 167496 relevant lines covered (84.32%)

3.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.48
today-context/src/main/java/infra/scheduling/annotation/AbstractAsyncConfiguration.java
1
/*
2
 * Copyright 2017 - 2025 the original author or authors.
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see [https://www.gnu.org/licenses/]
16
 */
17

18
package infra.scheduling.annotation;
19

20
import org.jspecify.annotations.Nullable;
21

22
import java.util.concurrent.Executor;
23
import java.util.function.Function;
24
import java.util.function.Supplier;
25

26
import infra.aop.interceptor.AsyncUncaughtExceptionHandler;
27
import infra.beans.BeansException;
28
import infra.beans.factory.BeanFactory;
29
import infra.beans.factory.BeanFactoryAware;
30
import infra.beans.factory.annotation.DisableDependencyInjection;
31
import infra.context.annotation.Configuration;
32
import infra.context.annotation.ImportAware;
33
import infra.core.annotation.MergedAnnotation;
34
import infra.core.type.AnnotationMetadata;
35
import infra.util.ObjectUtils;
36
import infra.util.function.SingletonSupplier;
37

38
/**
39
 * Abstract base {@code Configuration} class providing common structure for enabling
40
 * asynchronous method execution capability.
41
 *
42
 * @author Chris Beams
43
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
44
 * @author Juergen Hoeller
45
 * @author Stephane Nicoll
46
 * @see EnableAsync
47
 * @since 4.0
48
 */
49
@SuppressWarnings("NullAway")
50
@DisableDependencyInjection
51
@Configuration(proxyBeanMethods = false)
52
public abstract class AbstractAsyncConfiguration implements ImportAware, BeanFactoryAware {
3✔
53

54
  @Nullable
55
  protected MergedAnnotation<EnableAsync> enableAsync;
56

57
  @Nullable
58
  protected Supplier<@Nullable Executor> executor;
59

60
  @Nullable
61
  protected Supplier<@Nullable AsyncUncaughtExceptionHandler> exceptionHandler;
62

63
  @Override
64
  public void setImportMetadata(AnnotationMetadata importMetadata) {
65
    this.enableAsync = importMetadata.getAnnotation(EnableAsync.class);
5✔
66
    if (!enableAsync.isPresent()) {
4!
67
      throw new IllegalArgumentException(
×
68
              "@EnableAsync is not present on importing class " + importMetadata.getClassName());
×
69
    }
70
  }
1✔
71

72
  /**
73
   * Collect any {@link AsyncConfigurer} beans through autowiring.
74
   */
75
  @Override
76
  public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
77
    var asyncConfigurer = SingletonSupplier.ofNullable(() -> {
4✔
78
      var configurers = beanFactory.getBeanNamesForType(AsyncConfigurer.class);
4✔
79
      if (ObjectUtils.isEmpty(configurers)) {
3✔
80
        return null;
2✔
81
      }
82
      if (configurers.length > 1) {
4!
83
        throw new IllegalStateException("Only one AsyncConfigurer may exist");
×
84
      }
85
      return beanFactory.getBean(configurers[0], AsyncConfigurer.class);
8✔
86
    });
87

88
    this.executor = adapt(asyncConfigurer, AsyncConfigurer::getAsyncExecutor);
6✔
89
    this.exceptionHandler = adapt(asyncConfigurer, AsyncConfigurer::getAsyncUncaughtExceptionHandler);
6✔
90
  }
1✔
91

92
  private <T> Supplier<@Nullable T> adapt(SingletonSupplier<AsyncConfigurer> supplier, Function<AsyncConfigurer, @Nullable T> provider) {
93
    return () -> {
4✔
94
      AsyncConfigurer asyncConfigurer = supplier.get();
4✔
95
      return asyncConfigurer != null ? provider.apply(asyncConfigurer) : null;
8✔
96
    };
97
  }
98

99
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc