@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 * Implementation of the <code>JmxAttributeSource</code> interface that
* reads JDK 1.5+ annotations and exposes the corresponding attributes. * 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 Rob Harrop
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Jennifer Hickey * @author Jennifer Hickey
@ -66,7 +63,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource {
public ManagedAttribute getManagedAttribute(Method method) throws InvalidMetadataException { public ManagedAttribute getManagedAttribute(Method method) throws InvalidMetadataException {
org.springframework.jmx.export.annotation.ManagedAttribute ann = 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) { if (ann == null) {
return null; return null;
} }
@ -80,7 +77,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource {
public ManagedMetric getManagedMetric(Method method) throws InvalidMetadataException { public ManagedMetric getManagedMetric(Method method) throws InvalidMetadataException {
org.springframework.jmx.export.annotation.ManagedMetric ann = 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) { if (ann == null) {
return null; return null;
} }
@ -95,12 +92,10 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource {
throw new InvalidMetadataException( throw new InvalidMetadataException(
"The ManagedOperation attribute is not valid for JavaBean properties. Use ManagedAttribute instead."); "The ManagedOperation attribute is not valid for JavaBean properties. Use ManagedAttribute instead.");
} }
Annotation ann = AnnotationUtils.getAnnotation(method, org.springframework.jmx.export.annotation.ManagedOperation.class); Annotation ann = AnnotationUtils.getAnnotation(method, org.springframework.jmx.export.annotation.ManagedOperation.class);
if (ann == null) { if (ann == null) {
return null; return null;
} }
ManagedOperation op = new ManagedOperation(); ManagedOperation op = new ManagedOperation();
AnnotationBeanUtils.copyPropertiesToBean(ann, op); AnnotationBeanUtils.copyPropertiesToBean(ann, op);
return 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.Documented;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/** /**
* JDK 1.5+ class-level annotation that indicates to register * JDK 1.5+ class-level annotation that indicates to register instances of a
* instances of a class with a JMX server, corresponding to * class with a JMX server, corresponding to the ManagedResource attribute.
* 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 Rob Harrop
* @author Juergen Hoeller * @author Juergen Hoeller
@ -34,6 +39,7 @@ import java.lang.annotation.Target;
*/ */
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented @Documented
public @interface ManagedResource { 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,7 +17,6 @@
package org.springframework.jmx.export.naming; package org.springframework.jmx.export.naming;
import java.util.Hashtable; import java.util.Hashtable;
import javax.management.MalformedObjectNameException; import javax.management.MalformedObjectNameException;
import javax.management.ObjectName; import javax.management.ObjectName;
@ -38,16 +37,14 @@ import org.springframework.util.StringUtils;
* *
* <p>Uses the {@link JmxAttributeSource} strategy interface, so that * <p>Uses the {@link JmxAttributeSource} strategy interface, so that
* metadata can be read using any supported implementation. Out of the box, * metadata can be read using any supported implementation. Out of the box,
* two strategies are included: * {@link org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource}
* <ul> * introspects a well-defined set of Java 5 annotations that come with Spring.
* <li><code>AttributesJmxAttributeSource</code>, for Commons Attributes
* <li><code>AnnotationJmxAttributeSource</code>, for JDK 1.5+ annotations
* </ul>
* *
* @author Rob Harrop * @author Rob Harrop
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 1.2 * @since 1.2
* @see ObjectNamingStrategy * @see ObjectNamingStrategy
* @see org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource
*/ */
public class MetadataNamingStrategy implements ObjectNamingStrategy, InitializingBean { public class MetadataNamingStrategy implements ObjectNamingStrategy, InitializingBean {
@ -125,7 +122,7 @@ public class MetadataNamingStrategy implements ObjectNamingStrategy, Initializin
if (domain == null) { if (domain == null) {
domain = ClassUtils.getPackageName(managedClass); domain = ClassUtils.getPackageName(managedClass);
} }
Hashtable properties = new Hashtable(); Hashtable<String, String> properties = new Hashtable<String, String>();
properties.put("type", ClassUtils.getShortName(managedClass)); properties.put("type", ClassUtils.getShortName(managedClass));
properties.put("name", beanKey); properties.put("name", beanKey);
return ObjectNameManager.getInstance(domain, properties); return ObjectNameManager.getInstance(domain, properties);