org.springframework.jmx.export.assembler
Class MetadataMBeanInfoAssembler

java.lang.Object
  extended by org.springframework.jmx.export.assembler.AbstractMBeanInfoAssembler
      extended by org.springframework.jmx.export.assembler.AbstractReflectiveMBeanInfoAssembler
          extended by org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler
All Implemented Interfaces:
InitializingBean, AutodetectCapableMBeanInfoAssembler, MBeanInfoAssembler

public class MetadataMBeanInfoAssembler
extends AbstractReflectiveMBeanInfoAssembler
implements AutodetectCapableMBeanInfoAssembler, InitializingBean

Implementation of the MBeanInfoAssembler interface that reads the management interface information from source level metadata.

Uses the JmxAttributeSource strategy interface, so that metadata can be read using any supported implementation. Out of the box, Spring provides an implementation based on JDK 1.5+ annotations, AnnotationJmxAttributeSource.

Since:
1.2
Author:
Rob Harrop, Juergen Hoeller, Jennifer Hickey
See Also:
setAttributeSource(org.springframework.jmx.export.metadata.JmxAttributeSource), AnnotationJmxAttributeSource

Field Summary
private  JmxAttributeSource attributeSource
           
 
Fields inherited from class org.springframework.jmx.export.assembler.AbstractReflectiveMBeanInfoAssembler
ATTRIBUTE_OPERATION_VISIBILITY, FIELD_CLASS, FIELD_CURRENCY_TIME_LIMIT, FIELD_DEFAULT, FIELD_DISPLAY_NAME, FIELD_GET_METHOD, FIELD_LOG, FIELD_LOG_FILE, FIELD_METRIC_CATEGORY, FIELD_METRIC_TYPE, FIELD_PERSIST_LOCATION, FIELD_PERSIST_NAME, FIELD_PERSIST_PERIOD, FIELD_PERSIST_POLICY, FIELD_ROLE, FIELD_SET_METHOD, FIELD_UNITS, FIELD_VISIBILITY, ROLE_GETTER, ROLE_OPERATION, ROLE_SETTER
 
Constructor Summary
MetadataMBeanInfoAssembler()
          Create a new MetadataMBeanInfoAssembler which needs to be configured through the setAttributeSource(org.springframework.jmx.export.metadata.JmxAttributeSource) method.
MetadataMBeanInfoAssembler(JmxAttributeSource attributeSource)
          Create a new MetadataMBeanInfoAssembler for the given JmxAttributeSource.
 
Method Summary
 void afterPropertiesSet()
          Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
protected  void checkManagedBean(java.lang.Object managedBean)
          Throws an IllegalArgumentException if it encounters a JDK dynamic proxy.
protected  java.lang.String getAttributeDescription(java.beans.PropertyDescriptor propertyDescriptor, java.lang.String beanKey)
          Creates a description for the attribute corresponding to this property descriptor.
protected  java.lang.String getDescription(java.lang.Object managedBean, java.lang.String beanKey)
          Reads managed resource description from the source level metadata.
protected  javax.management.modelmbean.ModelMBeanNotificationInfo[] getNotificationInfo(java.lang.Object managedBean, java.lang.String beanKey)
          Reads the ManagedNotification metadata from the Class of the managed resource and generates and returns the corresponding ModelMBeanNotificationInfo metadata.
protected  java.lang.String getOperationDescription(java.lang.reflect.Method method, java.lang.String beanKey)
          Retrieves the description for the supplied Method from the metadata.
protected  javax.management.MBeanParameterInfo[] getOperationParameters(java.lang.reflect.Method method, java.lang.String beanKey)
          Reads MBeanParameterInfo from the ManagedOperationParameter attributes attached to a method.
private  boolean hasManagedAttribute(java.lang.reflect.Method method)
          Checks to see if the given Method has the ManagedAttribute attribute.
private  boolean hasManagedMetric(java.lang.reflect.Method method)
          Checks to see if the given Method has the ManagedMetric attribute.
private  boolean hasManagedOperation(java.lang.reflect.Method method)
          Checks to see if the given Method has the ManagedOperation attribute.
 boolean includeBean(java.lang.Class<?> beanClass, java.lang.String beanName)
          Used for autodetection of beans.
protected  boolean includeOperation(java.lang.reflect.Method method, java.lang.String beanKey)
          Votes on the inclusion of an operation.
protected  boolean includeReadAttribute(java.lang.reflect.Method method, java.lang.String beanKey)
          Vote on the inclusion of an attribute accessor.
protected  boolean includeWriteAttribute(java.lang.reflect.Method method, java.lang.String beanKey)
          Votes on the inclusion of an attribute mutator.
private  void populateAttributeDescriptor(javax.management.Descriptor desc, ManagedAttribute gma, ManagedAttribute sma)
           
protected  void populateAttributeDescriptor(javax.management.Descriptor desc, java.lang.reflect.Method getter, java.lang.reflect.Method setter, java.lang.String beanKey)
          Adds descriptor fields from the ManagedAttribute attribute or the ManagedMetric attribute to the attribute descriptor.
protected  void populateMBeanDescriptor(javax.management.Descriptor desc, java.lang.Object managedBean, java.lang.String beanKey)
          Adds descriptor fields from the ManagedResource attribute to the MBean descriptor.
private  void populateMetricDescriptor(javax.management.Descriptor desc, ManagedMetric metric)
           
protected  void populateOperationDescriptor(javax.management.Descriptor desc, java.lang.reflect.Method method, java.lang.String beanKey)
          Adds descriptor fields from the ManagedAttribute attribute to the attribute descriptor.
private  int resolveIntDescriptor(int getter, int setter)
          Determines which of two int values should be used as the value for an attribute descriptor.
private  java.lang.Object resolveObjectDescriptor(java.lang.Object getter, java.lang.Object setter)
          Locates the value of a descriptor based on values attached to both the getter and setter methods.
private  java.lang.String resolveStringDescriptor(java.lang.String getter, java.lang.String setter)
          Locates the value of a descriptor based on values attached to both the getter and setter methods.
 void setAttributeSource(JmxAttributeSource attributeSource)
          Set the JmxAttributeSource implementation to use for reading the metadata from the bean class.
 
Methods inherited from class org.springframework.jmx.export.assembler.AbstractReflectiveMBeanInfoAssembler
applyCurrencyTimeLimit, applyDefaultCurrencyTimeLimit, createModelMBeanOperationInfo, getAttributeInfo, getClassForDescriptor, getDefaultCurrencyTimeLimit, getOperationInfo, isExposeClassDescriptor, isUseStrictCasing, setDefaultCurrencyTimeLimit, setExposeClassDescriptor, setUseStrictCasing
 
Methods inherited from class org.springframework.jmx.export.assembler.AbstractMBeanInfoAssembler
getClassName, getClassToExpose, getClassToExpose, getConstructorInfo, getMBeanInfo, getTargetClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.jmx.export.assembler.MBeanInfoAssembler
getMBeanInfo
 

Field Detail

attributeSource

private JmxAttributeSource attributeSource
Constructor Detail

MetadataMBeanInfoAssembler

public MetadataMBeanInfoAssembler()
Create a new MetadataMBeanInfoAssembler which needs to be configured through the setAttributeSource(org.springframework.jmx.export.metadata.JmxAttributeSource) method.


MetadataMBeanInfoAssembler

public MetadataMBeanInfoAssembler(JmxAttributeSource attributeSource)
Create a new MetadataMBeanInfoAssembler for the given JmxAttributeSource.

Parameters:
attributeSource - the JmxAttributeSource to use
Method Detail

setAttributeSource

public void setAttributeSource(JmxAttributeSource attributeSource)
Set the JmxAttributeSource implementation to use for reading the metadata from the bean class.

See Also:
AnnotationJmxAttributeSource

afterPropertiesSet

public void afterPropertiesSet()
Description copied from interface: InitializingBean
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

Specified by:
afterPropertiesSet in interface InitializingBean

checkManagedBean

protected void checkManagedBean(java.lang.Object managedBean)
                         throws java.lang.IllegalArgumentException
Throws an IllegalArgumentException if it encounters a JDK dynamic proxy. Metadata can only be read from target classes and CGLIB proxies!

Overrides:
checkManagedBean in class AbstractMBeanInfoAssembler
Parameters:
managedBean - the bean that will be exposed (might be an AOP proxy)
Throws:
java.lang.IllegalArgumentException - the bean is not valid for exposure

includeBean

public boolean includeBean(java.lang.Class<?> beanClass,
                           java.lang.String beanName)
Used for autodetection of beans. Checks to see if the bean's class has a ManagedResource attribute. If so it will add it list of included beans.

Specified by:
includeBean in interface AutodetectCapableMBeanInfoAssembler
Parameters:
beanClass - the class of the bean
beanName - the name of the bean in the bean factory

includeReadAttribute

protected boolean includeReadAttribute(java.lang.reflect.Method method,
                                       java.lang.String beanKey)
Vote on the inclusion of an attribute accessor.

Specified by:
includeReadAttribute in class AbstractReflectiveMBeanInfoAssembler
Parameters:
method - the accessor method
beanKey - the key associated with the MBean in the beans map
Returns:
whether the method has the appropriate metadata

includeWriteAttribute

protected boolean includeWriteAttribute(java.lang.reflect.Method method,
                                        java.lang.String beanKey)
Votes on the inclusion of an attribute mutator.

Specified by:
includeWriteAttribute in class AbstractReflectiveMBeanInfoAssembler
Parameters:
method - the mutator method
beanKey - the key associated with the MBean in the beans map
Returns:
whether the method has the appropriate metadata

includeOperation

protected boolean includeOperation(java.lang.reflect.Method method,
                                   java.lang.String beanKey)
Votes on the inclusion of an operation.

Specified by:
includeOperation in class AbstractReflectiveMBeanInfoAssembler
Parameters:
method - the operation method
beanKey - the key associated with the MBean in the beans map
Returns:
whether the method has the appropriate metadata

hasManagedAttribute

private boolean hasManagedAttribute(java.lang.reflect.Method method)
Checks to see if the given Method has the ManagedAttribute attribute.


hasManagedMetric

private boolean hasManagedMetric(java.lang.reflect.Method method)
Checks to see if the given Method has the ManagedMetric attribute.


hasManagedOperation

private boolean hasManagedOperation(java.lang.reflect.Method method)
Checks to see if the given Method has the ManagedOperation attribute.

Parameters:
method - the method to check

getDescription

protected java.lang.String getDescription(java.lang.Object managedBean,
                                          java.lang.String beanKey)
Reads managed resource description from the source level metadata. Returns an empty String if no description can be found.

Overrides:
getDescription in class AbstractMBeanInfoAssembler
Parameters:
managedBean - the bean instance (might be an AOP proxy)
beanKey - the key associated with the MBean in the beans map of the MBeanExporter

getAttributeDescription

protected java.lang.String getAttributeDescription(java.beans.PropertyDescriptor propertyDescriptor,
                                                   java.lang.String beanKey)
Creates a description for the attribute corresponding to this property descriptor. Attempts to create the description using metadata from either the getter or setter attributes, otherwise uses the property name.

Overrides:
getAttributeDescription in class AbstractReflectiveMBeanInfoAssembler
Parameters:
propertyDescriptor - the PropertyDescriptor for the attribute
beanKey - the key associated with the MBean in the beans map of the MBeanExporter
Returns:
the description for the attribute

getOperationDescription

protected java.lang.String getOperationDescription(java.lang.reflect.Method method,
                                                   java.lang.String beanKey)
Retrieves the description for the supplied Method from the metadata. Uses the method name is no description is present in the metadata.

Overrides:
getOperationDescription in class AbstractReflectiveMBeanInfoAssembler
Parameters:
method - the operation method
beanKey - the key associated with the MBean in the beans map of the MBeanExporter
Returns:
the description for the operation

getOperationParameters

protected javax.management.MBeanParameterInfo[] getOperationParameters(java.lang.reflect.Method method,
                                                                       java.lang.String beanKey)
Reads MBeanParameterInfo from the ManagedOperationParameter attributes attached to a method. Returns an empty array of MBeanParameterInfo if no attributes are found.

Overrides:
getOperationParameters in class AbstractReflectiveMBeanInfoAssembler
Parameters:
method - the Method to get the parameter information for
beanKey - the key associated with the MBean in the beans map of the MBeanExporter
Returns:
the MBeanParameterInfo array

getNotificationInfo

protected javax.management.modelmbean.ModelMBeanNotificationInfo[] getNotificationInfo(java.lang.Object managedBean,
                                                                                       java.lang.String beanKey)
Reads the ManagedNotification metadata from the Class of the managed resource and generates and returns the corresponding ModelMBeanNotificationInfo metadata.

Overrides:
getNotificationInfo in class AbstractMBeanInfoAssembler
Parameters:
managedBean - the bean instance (might be an AOP proxy)
beanKey - the key associated with the MBean in the beans map of the MBeanExporter
Returns:
the notification metadata

populateMBeanDescriptor

protected void populateMBeanDescriptor(javax.management.Descriptor desc,
                                       java.lang.Object managedBean,
                                       java.lang.String beanKey)
Adds descriptor fields from the ManagedResource attribute to the MBean descriptor. Specifically, adds the currencyTimeLimit, persistPolicy, persistPeriod, persistLocation and persistName descriptor fields if they are present in the metadata.

Overrides:
populateMBeanDescriptor in class AbstractReflectiveMBeanInfoAssembler
Parameters:
desc - the Descriptor for the MBean resource.
managedBean - the bean instance (might be an AOP proxy)
beanKey - the key associated with the MBean in the beans map of the MBeanExporter
See Also:
AbstractReflectiveMBeanInfoAssembler.setDefaultCurrencyTimeLimit(Integer), AbstractReflectiveMBeanInfoAssembler.applyDefaultCurrencyTimeLimit(javax.management.Descriptor)

populateAttributeDescriptor

protected void populateAttributeDescriptor(javax.management.Descriptor desc,
                                           java.lang.reflect.Method getter,
                                           java.lang.reflect.Method setter,
                                           java.lang.String beanKey)
Adds descriptor fields from the ManagedAttribute attribute or the ManagedMetric attribute to the attribute descriptor.

Overrides:
populateAttributeDescriptor in class AbstractReflectiveMBeanInfoAssembler
Parameters:
desc - the attribute descriptor
getter - the accessor method for the attribute
setter - the mutator method for the attribute
beanKey - the key associated with the MBean in the beans map of the MBeanExporter
See Also:
AbstractReflectiveMBeanInfoAssembler.setDefaultCurrencyTimeLimit(Integer), AbstractReflectiveMBeanInfoAssembler.applyDefaultCurrencyTimeLimit(javax.management.Descriptor)

populateAttributeDescriptor

private void populateAttributeDescriptor(javax.management.Descriptor desc,
                                         ManagedAttribute gma,
                                         ManagedAttribute sma)

populateMetricDescriptor

private void populateMetricDescriptor(javax.management.Descriptor desc,
                                      ManagedMetric metric)

populateOperationDescriptor

protected void populateOperationDescriptor(javax.management.Descriptor desc,
                                           java.lang.reflect.Method method,
                                           java.lang.String beanKey)
Adds descriptor fields from the ManagedAttribute attribute to the attribute descriptor. Specifically, adds the currencyTimeLimit descriptor field if it is present in the metadata.

Overrides:
populateOperationDescriptor in class AbstractReflectiveMBeanInfoAssembler
Parameters:
desc - the operation descriptor
method - the method corresponding to the operation
beanKey - the key associated with the MBean in the beans map of the MBeanExporter
See Also:
AbstractReflectiveMBeanInfoAssembler.setDefaultCurrencyTimeLimit(Integer), AbstractReflectiveMBeanInfoAssembler.applyDefaultCurrencyTimeLimit(javax.management.Descriptor)

resolveIntDescriptor

private int resolveIntDescriptor(int getter,
                                 int setter)
Determines which of two int values should be used as the value for an attribute descriptor. In general, only the getter or the setter will be have a non-negative value so we use that value. In the event that both values are non-negative, we use the greater of the two. This method can be used to resolve any int valued descriptor where there are two possible values.

Parameters:
getter - the int value associated with the getter for this attribute
setter - the int associated with the setter for this attribute

resolveObjectDescriptor

private java.lang.Object resolveObjectDescriptor(java.lang.Object getter,
                                                 java.lang.Object setter)
Locates the value of a descriptor based on values attached to both the getter and setter methods. If both have values supplied then the value attached to the getter is preferred.

Parameters:
getter - the Object value associated with the get method
setter - the Object value associated with the set method
Returns:
the appropriate Object to use as the value for the descriptor

resolveStringDescriptor

private java.lang.String resolveStringDescriptor(java.lang.String getter,
                                                 java.lang.String setter)
Locates the value of a descriptor based on values attached to both the getter and setter methods. If both have values supplied then the value attached to the getter is preferred. The supplied default value is used to check to see if the value associated with the getter has changed from the default.

Parameters:
getter - the String value associated with the get method
setter - the String value associated with the set method
Returns:
the appropriate String to use as the value for the descriptor