private Map < String , String > getMBeanAttributes ( ObjectName objName ) throws Exception { Map < String , String > response = Maps . newLinkedHashMap ( ) ; // Look for the object MBeanInfo mBeanInfo = mBeanServer . getMBeanInfo ( objName ) ; if ( mBeanInfo != null ) { // Does it have attributes? MBeanAttributeInfo [ ] attrs = mBeanInfo . getAttributes ( ) ; if ( attrs != null ) { // List all attributes List < String > attrNames = Lists . newArrayList ( ) ; for ( MBeanAttributeInfo attr : attrs ) { attrNames . add ( attr . getName ( ) ) ; } AttributeList attrList = mBeanServer . getAttributes ( objName , attrNames . toArray ( new String [ 0 ] ) ) ; // Process each attribute for ( Attribute attr : attrList . asList ( ) ) { String attrName = attr . getName ( ) ; Object value = attr . getValue ( ) ; String attrValue = null ; // Attribute has data if ( value != null ) { // Special case of CompositeDataSuppert if ( value instanceof CompositeDataSupport ) { CompositeDataSupport compositeValue = ( CompositeDataSupport ) value ; if ( compositeValue != null ) { try { if ( compositeValue . containsKey ( CURRENT_VALUE ) ) { Object curValue = compositeValue . get ( CURRENT_VALUE ) ; attrValue = ( curValue == null ? "null" : curValue . toString ( ) ) ; } } catch ( Exception e ) { attrValue = compositeValue . toString ( ) ; } } } if ( attrValue == null ) { attrValue = value . toString ( ) ; } } else { value = "none" ; } response . put ( attrName , attrValue ) ; } } } return response ; }
Get list of all attributes of an object