• 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

72.55
today-context/src/main/java/infra/context/annotation/MBeanExportConfiguration.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.context.annotation;
19

20
import org.jspecify.annotations.Nullable;
21

22
import java.util.Map;
23

24
import javax.management.MBeanServer;
25

26
import infra.beans.factory.BeanFactory;
27
import infra.beans.factory.BeanFactoryAware;
28
import infra.beans.factory.config.BeanDefinition;
29
import infra.context.EnvironmentAware;
30
import infra.core.annotation.AnnotationAttributes;
31
import infra.core.env.Environment;
32
import infra.core.type.AnnotationMetadata;
33
import infra.jmx.export.annotation.AnnotationMBeanExporter;
34
import infra.jmx.support.RegistrationPolicy;
35
import infra.lang.Assert;
36
import infra.stereotype.Component;
37
import infra.util.StringUtils;
38

39
/**
40
 * {@code @Configuration} class that registers a {@link AnnotationMBeanExporter} bean.
41
 *
42
 * <p>This configuration class is automatically imported when using the
43
 * {@link EnableMBeanExport} annotation. See its javadoc for complete usage details.
44
 *
45
 * @author Phillip Webb
46
 * @author Chris Beams
47
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
48
 * @see EnableMBeanExport
49
 * @since 4.0 2022/3/7 23:07
50
 */
51
@Configuration(proxyBeanMethods = false)
52
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
53
public class MBeanExportConfiguration implements ImportAware, EnvironmentAware, BeanFactoryAware {
3✔
54

55
  private static final String MBEAN_EXPORTER_BEAN_NAME = "mbeanExporter";
56

57
  @Nullable
58
  private AnnotationAttributes enableMBeanExport;
59

60
  @Nullable
61
  private Environment environment;
62

63
  @Nullable
64
  private BeanFactory beanFactory;
65

66
  @Override
67
  public void setImportMetadata(AnnotationMetadata importMetadata) {
68
    Map<String, Object> map = importMetadata.getAnnotationAttributes(EnableMBeanExport.class);
4✔
69
    this.enableMBeanExport = AnnotationAttributes.fromMap(map);
4✔
70
    if (enableMBeanExport == null) {
3!
71
      throw new IllegalArgumentException(
×
72
              "@EnableMBeanExport is not present on importing class " + importMetadata.getClassName());
×
73
    }
74
  }
1✔
75

76
  @Override
77
  public void setEnvironment(Environment environment) {
78
    this.environment = environment;
3✔
79
  }
1✔
80

81
  @Override
82
  public void setBeanFactory(BeanFactory beanFactory) {
83
    this.beanFactory = beanFactory;
3✔
84
  }
1✔
85

86
  @Component(name = MBEAN_EXPORTER_BEAN_NAME)
87
  @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
88
  public AnnotationMBeanExporter mbeanExporter() {
89
    AnnotationMBeanExporter exporter = new AnnotationMBeanExporter();
4✔
90
    Assert.state(enableMBeanExport != null, "No EnableMBeanExport annotation found");
7!
91
    setupDomain(exporter, enableMBeanExport);
5✔
92
    setupServer(exporter, enableMBeanExport);
5✔
93
    setupRegistrationPolicy(exporter, enableMBeanExport);
5✔
94
    return exporter;
2✔
95
  }
96

97
  private void setupDomain(AnnotationMBeanExporter exporter, AnnotationAttributes enableMBeanExport) {
98
    String defaultDomain = enableMBeanExport.getString("defaultDomain");
4✔
99
    if (StringUtils.isNotEmpty(defaultDomain) && environment != null) {
3!
100
      defaultDomain = environment.resolvePlaceholders(defaultDomain);
×
101
    }
102
    if (StringUtils.hasText(defaultDomain)) {
3!
103
      exporter.setDefaultDomain(defaultDomain);
×
104
    }
105
  }
1✔
106

107
  private void setupServer(AnnotationMBeanExporter exporter, AnnotationAttributes enableMBeanExport) {
108
    String server = enableMBeanExport.getString("server");
4✔
109
    if (StringUtils.isNotEmpty(server) && environment != null) {
6!
110
      server = environment.resolvePlaceholders(server);
5✔
111
    }
112
    if (StringUtils.hasText(server)) {
3!
113
      Assert.state(beanFactory != null, "No BeanFactory set");
7!
114
      exporter.setServer(beanFactory.getBean(server, MBeanServer.class));
8✔
115
    }
116
  }
1✔
117

118
  private void setupRegistrationPolicy(AnnotationMBeanExporter exporter, AnnotationAttributes enableMBeanExport) {
119
    RegistrationPolicy registrationPolicy = enableMBeanExport.getEnum("registration");
5✔
120
    exporter.setRegistrationPolicy(registrationPolicy);
3✔
121
  }
1✔
122

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