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;
  }
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 ( mBeanNames == null ) { nameQueries . add ( null ) ; } else { for ( String mBeanName : mBeanNames ) { if ( mBeanName != null ) { nameQueries . add ( new ObjectName ( mBeanName ) ) ; } } } for ( ObjectName nameQuery : nameQueries ) { queriedObjects . addAll ( mBeanServer . queryNames ( nameQuery , null ) ) ; } 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.

@param jg
JsonGenerator that will be written to
@param mBeanNames
Optional list of mbean names to render. If null, every
mbean will be returned.
@return int
Returns the appropriate HTTP status code.