@ManagedResource is marked as inherited now, for generic management-aware base classes (SPR-3500)

This commit is contained in:
Juergen Hoeller 2009-06-08 15:38:55 +00:00
parent 0cb28f5b41
commit 95a7ec6587
3 changed files with 17 additions and 19 deletions

View File

@ -37,9 +37,6 @@ import org.springframework.util.StringUtils;
* Implementation of the <code>JmxAttributeSource</code> interface that
* reads JDK 1.5+ annotations and exposes the corresponding attributes.
*
* <p>This is a direct alternative to <code>AttributesJmxAttributeSource</code>,
* which is able to read in source-level attributes via Commons Attributes.
*
* @author Rob Harrop
* @author Juergen Hoeller
* @author Jennifer Hickey
@ -66,7 +63,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource {
public ManagedAttribute getManagedAttribute(Method method) throws InvalidMetadataException {
org.springframework.jmx.export.annotation.ManagedAttribute ann =
AnnotationUtils.getAnnotation(method, org.springframework.jmx.export.annotation.ManagedAttribute.class);
AnnotationUtils.getAnnotation(method, org.springframework.jmx.export.annotation.ManagedAttribute.class);
if (ann == null) {
return null;
}
@ -80,7 +77,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource {
public ManagedMetric getManagedMetric(Method method) throws InvalidMetadataException {
org.springframework.jmx.export.annotation.ManagedMetric ann =
AnnotationUtils.getAnnotation(method, org.springframework.jmx.export.annotation.ManagedMetric.class);
AnnotationUtils.getAnnotation(method, org.springframework.jmx.export.annotation.ManagedMetric.class);
if (ann == null) {
return null;
}
@ -95,12 +92,10 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource {
throw new InvalidMetadataException(
"The ManagedOperation attribute is not valid for JavaBean properties. Use ManagedAttribute instead.");
}
Annotation ann = AnnotationUtils.getAnnotation(method, org.springframework.jmx.export.annotation.ManagedOperation.class);
if (ann == null) {
return null;
}
ManagedOperation op = new ManagedOperation();
AnnotationBeanUtils.copyPropertiesToBean(ann, op);
return op;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2009 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.
@ -18,14 +18,19 @@ package org.springframework.jmx.export.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* JDK 1.5+ class-level annotation that indicates to register
* instances of a class with a JMX server, corresponding to
* the ManagedResource attribute.
* JDK 1.5+ class-level annotation that indicates to register instances of a
* class with a JMX server, corresponding to the ManagedResource attribute.
*
* <p><b>Note:</b> This annotation is marked as inherited, allowing for generic
* management-aware base classes. In such a scenario, it is recommended to
* <i>not</i> specify an object name value since this would lead to naming
* collisions in case of multiple subclasses getting registered.
*
* @author Rob Harrop
* @author Juergen Hoeller
@ -34,6 +39,7 @@ import java.lang.annotation.Target;
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface ManagedResource {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2009 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.
@ -17,7 +17,6 @@
package org.springframework.jmx.export.naming;
import java.util.Hashtable;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
@ -38,16 +37,14 @@ import org.springframework.util.StringUtils;
*
* <p>Uses the {@link JmxAttributeSource} strategy interface, so that
* metadata can be read using any supported implementation. Out of the box,
* two strategies are included:
* <ul>
* <li><code>AttributesJmxAttributeSource</code>, for Commons Attributes
* <li><code>AnnotationJmxAttributeSource</code>, for JDK 1.5+ annotations
* </ul>
* {@link org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource}
* introspects a well-defined set of Java 5 annotations that come with Spring.
*
* @author Rob Harrop
* @author Juergen Hoeller
* @since 1.2
* @see ObjectNamingStrategy
* @see org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource
*/
public class MetadataNamingStrategy implements ObjectNamingStrategy, InitializingBean {
@ -125,7 +122,7 @@ public class MetadataNamingStrategy implements ObjectNamingStrategy, Initializin
if (domain == null) {
domain = ClassUtils.getPackageName(managedClass);
}
Hashtable properties = new Hashtable();
Hashtable<String, String> properties = new Hashtable<String, String>();
properties.put("type", ClassUtils.getShortName(managedClass));
properties.put("name", beanKey);
return ObjectNameManager.getInstance(domain, properties);