Polish [Annotation]JmxAttributeSource
This commit is contained in:
@@ -74,7 +74,9 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac
|
||||
|
||||
|
||||
@Override
|
||||
public org.springframework.jmx.export.metadata.@Nullable ManagedResource getManagedResource(Class<?> beanClass) throws InvalidMetadataException {
|
||||
public org.springframework.jmx.export.metadata.@Nullable ManagedResource getManagedResource(Class<?> beanClass)
|
||||
throws InvalidMetadataException {
|
||||
|
||||
MergedAnnotation<ManagedResource> ann = MergedAnnotations.from(beanClass, SearchStrategy.TYPE_HIERARCHY)
|
||||
.get(ManagedResource.class).withNonMergedAttributes();
|
||||
if (!ann.isPresent()) {
|
||||
@@ -86,7 +88,8 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac
|
||||
throw new InvalidMetadataException("@ManagedResource class '" + target.getName() + "' must be public");
|
||||
}
|
||||
|
||||
org.springframework.jmx.export.metadata.ManagedResource bean = new org.springframework.jmx.export.metadata.ManagedResource();
|
||||
org.springframework.jmx.export.metadata.ManagedResource bean =
|
||||
new org.springframework.jmx.export.metadata.ManagedResource();
|
||||
Map<String, Object> map = ann.asMap();
|
||||
List<PropertyValue> list = new ArrayList<>(map.size());
|
||||
map.forEach((attrName, attrValue) -> {
|
||||
@@ -103,14 +106,17 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.springframework.jmx.export.metadata.@Nullable ManagedAttribute getManagedAttribute(Method method) throws InvalidMetadataException {
|
||||
public org.springframework.jmx.export.metadata.@Nullable ManagedAttribute getManagedAttribute(Method method)
|
||||
throws InvalidMetadataException {
|
||||
|
||||
MergedAnnotation<ManagedAttribute> ann = MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY)
|
||||
.get(ManagedAttribute.class).withNonMergedAttributes();
|
||||
if (!ann.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
org.springframework.jmx.export.metadata.ManagedAttribute bean = new org.springframework.jmx.export.metadata.ManagedAttribute();
|
||||
org.springframework.jmx.export.metadata.ManagedAttribute bean =
|
||||
new org.springframework.jmx.export.metadata.ManagedAttribute();
|
||||
Map<String, Object> map = ann.asMap();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues(map);
|
||||
pvs.removePropertyValue("defaultValue");
|
||||
@@ -123,7 +129,9 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.springframework.jmx.export.metadata.@Nullable ManagedMetric getManagedMetric(Method method) throws InvalidMetadataException {
|
||||
public org.springframework.jmx.export.metadata.@Nullable ManagedMetric getManagedMetric(Method method)
|
||||
throws InvalidMetadataException {
|
||||
|
||||
MergedAnnotation<ManagedMetric> ann = MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY)
|
||||
.get(ManagedMetric.class).withNonMergedAttributes();
|
||||
|
||||
@@ -131,7 +139,9 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.springframework.jmx.export.metadata.@Nullable ManagedOperation getManagedOperation(Method method) throws InvalidMetadataException {
|
||||
public org.springframework.jmx.export.metadata.@Nullable ManagedOperation getManagedOperation(Method method)
|
||||
throws InvalidMetadataException {
|
||||
|
||||
MergedAnnotation<ManagedOperation> ann = MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY)
|
||||
.get(ManagedOperation.class).withNonMergedAttributes();
|
||||
|
||||
@@ -139,8 +149,8 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.springframework.jmx.export.metadata.@Nullable ManagedOperationParameter[] getManagedOperationParameters(Method method)
|
||||
throws InvalidMetadataException {
|
||||
public org.springframework.jmx.export.metadata.@Nullable ManagedOperationParameter[] getManagedOperationParameters(
|
||||
Method method) throws InvalidMetadataException {
|
||||
|
||||
List<MergedAnnotation<? extends Annotation>> anns = getRepeatableAnnotations(
|
||||
method, ManagedOperationParameter.class, ManagedOperationParameters.class);
|
||||
@@ -164,7 +174,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac
|
||||
Class<? extends Annotation> containerAnnotationType) {
|
||||
|
||||
return MergedAnnotations.from(annotatedElement, SearchStrategy.TYPE_HIERARCHY,
|
||||
RepeatableContainers.of(annotationType, containerAnnotationType))
|
||||
RepeatableContainers.of(annotationType, containerAnnotationType))
|
||||
.stream(annotationType)
|
||||
.filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex))
|
||||
.map(MergedAnnotation::withNonMergedAttributes)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,65 +33,58 @@ import org.jspecify.annotations.Nullable;
|
||||
public interface JmxAttributeSource {
|
||||
|
||||
/**
|
||||
* Implementations should return an instance of {@code ManagedResource}
|
||||
* if the supplied {@code Class} has the appropriate metadata.
|
||||
* Otherwise, should return {@code null}.
|
||||
* @param clazz the class to read the attribute data from
|
||||
* @return the attribute, or {@code null} if not found
|
||||
* @throws InvalidMetadataException in case of invalid attributes
|
||||
* Implementations should return an instance of {@link ManagedResource}
|
||||
* if the supplied {@code Class} has the corresponding metadata.
|
||||
* @param clazz the class to read the resource data from
|
||||
* @return the resource, or {@code null} if not found
|
||||
* @throws InvalidMetadataException in case of invalid metadata
|
||||
*/
|
||||
@Nullable ManagedResource getManagedResource(Class<?> clazz) throws InvalidMetadataException;
|
||||
|
||||
/**
|
||||
* Implementations should return an instance of {@code ManagedAttribute}
|
||||
* Implementations should return an instance of {@link ManagedAttribute}
|
||||
* if the supplied {@code Method} has the corresponding metadata.
|
||||
* Otherwise, should return {@code null}.
|
||||
* @param method the method to read the attribute data from
|
||||
* @return the attribute, or {@code null} if not found
|
||||
* @throws InvalidMetadataException in case of invalid attributes
|
||||
* @throws InvalidMetadataException in case of invalid metadata
|
||||
*/
|
||||
@Nullable ManagedAttribute getManagedAttribute(Method method) throws InvalidMetadataException;
|
||||
|
||||
/**
|
||||
* Implementations should return an instance of {@code ManagedMetric}
|
||||
* Implementations should return an instance of {@link ManagedMetric}
|
||||
* if the supplied {@code Method} has the corresponding metadata.
|
||||
* Otherwise, should return {@code null}.
|
||||
* @param method the method to read the attribute data from
|
||||
* @param method the method to read the metric data from
|
||||
* @return the metric, or {@code null} if not found
|
||||
* @throws InvalidMetadataException in case of invalid attributes
|
||||
* @throws InvalidMetadataException in case of invalid metadata
|
||||
*/
|
||||
@Nullable ManagedMetric getManagedMetric(Method method) throws InvalidMetadataException;
|
||||
|
||||
/**
|
||||
* Implementations should return an instance of {@code ManagedOperation}
|
||||
* Implementations should return an instance of {@link ManagedOperation}
|
||||
* if the supplied {@code Method} has the corresponding metadata.
|
||||
* Otherwise, should return {@code null}.
|
||||
* @param method the method to read the attribute data from
|
||||
* @return the attribute, or {@code null} if not found
|
||||
* @throws InvalidMetadataException in case of invalid attributes
|
||||
* @param method the method to read the operation data from
|
||||
* @return the operation, or {@code null} if not found
|
||||
* @throws InvalidMetadataException in case of invalid metadata
|
||||
*/
|
||||
@Nullable ManagedOperation getManagedOperation(Method method) throws InvalidMetadataException;
|
||||
|
||||
/**
|
||||
* Implementations should return an array of {@code ManagedOperationParameter}
|
||||
* if the supplied {@code Method} has the corresponding metadata. Otherwise,
|
||||
* should return an empty array if no metadata is found.
|
||||
* Implementations should return an array of {@link ManagedOperationParameter
|
||||
* ManagedOperationParameters} if the supplied {@code Method} has the corresponding
|
||||
* metadata.
|
||||
* @param method the {@code Method} to read the metadata from
|
||||
* @return the parameter information.
|
||||
* @throws InvalidMetadataException in the case of invalid attributes.
|
||||
* @return the parameter information, or an empty array if no metadata is found
|
||||
* @throws InvalidMetadataException in case of invalid metadata
|
||||
*/
|
||||
@Nullable ManagedOperationParameter[] getManagedOperationParameters(Method method) throws InvalidMetadataException;
|
||||
|
||||
/**
|
||||
* Implementations should return an array of {@link ManagedNotification ManagedNotifications}
|
||||
* if the supplied {@code Class} has the corresponding metadata. Otherwise,
|
||||
* should return an empty array.
|
||||
* if the supplied {@code Class} has the corresponding metadata.
|
||||
* @param clazz the {@code Class} to read the metadata from
|
||||
* @return the notification information
|
||||
* @throws InvalidMetadataException in the case of invalid metadata
|
||||
* @return the notification information, or an empty array if no metadata is found
|
||||
* @throws InvalidMetadataException in case of invalid metadata
|
||||
*/
|
||||
@Nullable ManagedNotification[] getManagedNotifications(Class<?> clazz) throws InvalidMetadataException;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user