Skip to content

Commit 6e1706a

Browse files
committed
Polish [Annotation]JmxAttributeSource
1 parent f678af4 commit 6e1706a

File tree

2 files changed

+42
-39
lines changed

2 files changed

+42
-39
lines changed

spring-context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ public void setBeanFactory(BeanFactory beanFactory) {
7474

7575

7676
@Override
77-
public org.springframework.jmx.export.metadata.@Nullable ManagedResource getManagedResource(Class<?> beanClass) throws InvalidMetadataException {
77+
public org.springframework.jmx.export.metadata.@Nullable ManagedResource getManagedResource(Class<?> beanClass)
78+
throws InvalidMetadataException {
79+
7880
MergedAnnotation<ManagedResource> ann = MergedAnnotations.from(beanClass, SearchStrategy.TYPE_HIERARCHY)
7981
.get(ManagedResource.class).withNonMergedAttributes();
8082
if (!ann.isPresent()) {
@@ -86,7 +88,8 @@ public void setBeanFactory(BeanFactory beanFactory) {
8688
throw new InvalidMetadataException("@ManagedResource class '" + target.getName() + "' must be public");
8789
}
8890

89-
org.springframework.jmx.export.metadata.ManagedResource bean = new org.springframework.jmx.export.metadata.ManagedResource();
91+
org.springframework.jmx.export.metadata.ManagedResource bean =
92+
new org.springframework.jmx.export.metadata.ManagedResource();
9093
Map<String, Object> map = ann.asMap();
9194
List<PropertyValue> list = new ArrayList<>(map.size());
9295
map.forEach((attrName, attrValue) -> {
@@ -103,14 +106,17 @@ public void setBeanFactory(BeanFactory beanFactory) {
103106
}
104107

105108
@Override
106-
public org.springframework.jmx.export.metadata.@Nullable ManagedAttribute getManagedAttribute(Method method) throws InvalidMetadataException {
109+
public org.springframework.jmx.export.metadata.@Nullable ManagedAttribute getManagedAttribute(Method method)
110+
throws InvalidMetadataException {
111+
107112
MergedAnnotation<ManagedAttribute> ann = MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY)
108113
.get(ManagedAttribute.class).withNonMergedAttributes();
109114
if (!ann.isPresent()) {
110115
return null;
111116
}
112117

113-
org.springframework.jmx.export.metadata.ManagedAttribute bean = new org.springframework.jmx.export.metadata.ManagedAttribute();
118+
org.springframework.jmx.export.metadata.ManagedAttribute bean =
119+
new org.springframework.jmx.export.metadata.ManagedAttribute();
114120
Map<String, Object> map = ann.asMap();
115121
MutablePropertyValues pvs = new MutablePropertyValues(map);
116122
pvs.removePropertyValue("defaultValue");
@@ -123,24 +129,28 @@ public void setBeanFactory(BeanFactory beanFactory) {
123129
}
124130

125131
@Override
126-
public org.springframework.jmx.export.metadata.@Nullable ManagedMetric getManagedMetric(Method method) throws InvalidMetadataException {
132+
public org.springframework.jmx.export.metadata.@Nullable ManagedMetric getManagedMetric(Method method)
133+
throws InvalidMetadataException {
134+
127135
MergedAnnotation<ManagedMetric> ann = MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY)
128136
.get(ManagedMetric.class).withNonMergedAttributes();
129137

130138
return copyPropertiesToBean(ann, org.springframework.jmx.export.metadata.ManagedMetric.class);
131139
}
132140

133141
@Override
134-
public org.springframework.jmx.export.metadata.@Nullable ManagedOperation getManagedOperation(Method method) throws InvalidMetadataException {
142+
public org.springframework.jmx.export.metadata.@Nullable ManagedOperation getManagedOperation(Method method)
143+
throws InvalidMetadataException {
144+
135145
MergedAnnotation<ManagedOperation> ann = MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY)
136146
.get(ManagedOperation.class).withNonMergedAttributes();
137147

138148
return copyPropertiesToBean(ann, org.springframework.jmx.export.metadata.ManagedOperation.class);
139149
}
140150

141151
@Override
142-
public org.springframework.jmx.export.metadata.@Nullable ManagedOperationParameter[] getManagedOperationParameters(Method method)
143-
throws InvalidMetadataException {
152+
public org.springframework.jmx.export.metadata.@Nullable ManagedOperationParameter[] getManagedOperationParameters(
153+
Method method) throws InvalidMetadataException {
144154

145155
List<MergedAnnotation<? extends Annotation>> anns = getRepeatableAnnotations(
146156
method, ManagedOperationParameter.class, ManagedOperationParameters.class);
@@ -164,7 +174,7 @@ private static List<MergedAnnotation<? extends Annotation>> getRepeatableAnnotat
164174
Class<? extends Annotation> containerAnnotationType) {
165175

166176
return MergedAnnotations.from(annotatedElement, SearchStrategy.TYPE_HIERARCHY,
167-
RepeatableContainers.of(annotationType, containerAnnotationType))
177+
RepeatableContainers.of(annotationType, containerAnnotationType))
168178
.stream(annotationType)
169179
.filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex))
170180
.map(MergedAnnotation::withNonMergedAttributes)
Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,65 +33,58 @@
3333
public interface JmxAttributeSource {
3434

3535
/**
36-
* Implementations should return an instance of {@code ManagedResource}
37-
* if the supplied {@code Class} has the appropriate metadata.
38-
* Otherwise, should return {@code null}.
39-
* @param clazz the class to read the attribute data from
40-
* @return the attribute, or {@code null} if not found
41-
* @throws InvalidMetadataException in case of invalid attributes
36+
* Implementations should return an instance of {@link ManagedResource}
37+
* if the supplied {@code Class} has the corresponding metadata.
38+
* @param clazz the class to read the resource data from
39+
* @return the resource, or {@code null} if not found
40+
* @throws InvalidMetadataException in case of invalid metadata
4241
*/
4342
@Nullable ManagedResource getManagedResource(Class<?> clazz) throws InvalidMetadataException;
4443

4544
/**
46-
* Implementations should return an instance of {@code ManagedAttribute}
45+
* Implementations should return an instance of {@link ManagedAttribute}
4746
* if the supplied {@code Method} has the corresponding metadata.
48-
* Otherwise, should return {@code null}.
4947
* @param method the method to read the attribute data from
5048
* @return the attribute, or {@code null} if not found
51-
* @throws InvalidMetadataException in case of invalid attributes
49+
* @throws InvalidMetadataException in case of invalid metadata
5250
*/
5351
@Nullable ManagedAttribute getManagedAttribute(Method method) throws InvalidMetadataException;
5452

5553
/**
56-
* Implementations should return an instance of {@code ManagedMetric}
54+
* Implementations should return an instance of {@link ManagedMetric}
5755
* if the supplied {@code Method} has the corresponding metadata.
58-
* Otherwise, should return {@code null}.
59-
* @param method the method to read the attribute data from
56+
* @param method the method to read the metric data from
6057
* @return the metric, or {@code null} if not found
61-
* @throws InvalidMetadataException in case of invalid attributes
58+
* @throws InvalidMetadataException in case of invalid metadata
6259
*/
6360
@Nullable ManagedMetric getManagedMetric(Method method) throws InvalidMetadataException;
6461

6562
/**
66-
* Implementations should return an instance of {@code ManagedOperation}
63+
* Implementations should return an instance of {@link ManagedOperation}
6764
* if the supplied {@code Method} has the corresponding metadata.
68-
* Otherwise, should return {@code null}.
69-
* @param method the method to read the attribute data from
70-
* @return the attribute, or {@code null} if not found
71-
* @throws InvalidMetadataException in case of invalid attributes
65+
* @param method the method to read the operation data from
66+
* @return the operation, or {@code null} if not found
67+
* @throws InvalidMetadataException in case of invalid metadata
7268
*/
7369
@Nullable ManagedOperation getManagedOperation(Method method) throws InvalidMetadataException;
7470

7571
/**
76-
* Implementations should return an array of {@code ManagedOperationParameter}
77-
* if the supplied {@code Method} has the corresponding metadata. Otherwise,
78-
* should return an empty array if no metadata is found.
72+
* Implementations should return an array of {@link ManagedOperationParameter
73+
* ManagedOperationParameters} if the supplied {@code Method} has the corresponding
74+
* metadata.
7975
* @param method the {@code Method} to read the metadata from
80-
* @return the parameter information.
81-
* @throws InvalidMetadataException in the case of invalid attributes.
76+
* @return the parameter information, or an empty array if no metadata is found
77+
* @throws InvalidMetadataException in case of invalid metadata
8278
*/
8379
@Nullable ManagedOperationParameter[] getManagedOperationParameters(Method method) throws InvalidMetadataException;
8480

8581
/**
8682
* Implementations should return an array of {@link ManagedNotification ManagedNotifications}
87-
* if the supplied {@code Class} has the corresponding metadata. Otherwise,
88-
* should return an empty array.
83+
* if the supplied {@code Class} has the corresponding metadata.
8984
* @param clazz the {@code Class} to read the metadata from
90-
* @return the notification information
91-
* @throws InvalidMetadataException in the case of invalid metadata
85+
* @return the notification information, or an empty array if no metadata is found
86+
* @throws InvalidMetadataException in case of invalid metadata
9287
*/
9388
@Nullable ManagedNotification[] getManagedNotifications(Class<?> clazz) throws InvalidMetadataException;
9489

95-
96-
9790
}

0 commit comments

Comments
 (0)