private int renderMBeans ( JsonGenerator jg , String [ ] mBeanNames ) throws IOException , MalformedObjectNameException { jg . writeStartObject ( ) ; Set < ObjectName > nameQueries , queriedObjects ; nameQueries = new HashSet < ObjectName > ( ) ; queriedObjects = new HashSet < ObjectName > ( ) ; // if no mbean names provided, add one null entry to query everything if ( mBeanNames == null ) { nameQueries . add ( null ) ; } else { for ( String mBeanName : mBeanNames ) { if ( mBeanName != null ) { nameQueries . add ( new ObjectName ( mBeanName ) ) ; } } } // perform name queries for ( ObjectName nameQuery : nameQueries ) { queriedObjects . addAll ( mBeanServer . queryNames ( nameQuery , null ) ) ; } // render each query result for ( ObjectName objectName : queriedObjects ) { renderMBean ( jg , objectName ) ; } jg . writeEndObject ( ) ; return HttpServletResponse . SC_OK ; }
Renders MBean attributes to jg . The queries parameter allows selection of a subset of mbeans .