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

TAKETODAY / today-infrastructure / 16688256371

02 Aug 2025 01:13AM UTC coverage: 81.778% (-0.006%) from 81.784%
16688256371

push

github

TAKETODAY
:white_check_mark:

59512 of 77725 branches covered (76.57%)

Branch coverage included in aggregate %.

140809 of 167233 relevant lines covered (84.2%)

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 java.util.concurrent.Executor;
21
import java.util.function.Function;
22
import java.util.function.Supplier;
23

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

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

52
  @Nullable
53
  protected MergedAnnotation<EnableAsync> enableAsync;
54

55
  @Nullable
56
  protected Supplier<Executor> executor;
57

58
  @Nullable
59
  protected Supplier<AsyncUncaughtExceptionHandler> exceptionHandler;
60

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

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

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

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

97
}
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