Java Code Examples for javax.management.MBeanServer#queryMBeans()

The following examples show how to use javax.management.MBeanServer#queryMBeans() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestJMX.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void registerAndVerifyMBean(MBeanServer mbs) {
    try {
        ObjectName myInfoObj = new ObjectName("com.alibaba.tenant.mxbean:type=MyTest");
        MXBeanImpl myMXBean = new MXBeanImpl();
        StandardMBean smb = new StandardMBean(myMXBean, MXBean.class);
        mbs.registerMBean(smb, myInfoObj);

        assertTrue(mbs.isRegistered(myInfoObj));

        //call the method of MXBean
        MXBean mbean =
                (MXBean)MBeanServerInvocationHandler.newProxyInstance(
                     mbs,new ObjectName("com.alibaba.tenant.mxbean:type=MyTest"), MXBean.class, true);
        assertTrue("test".equals(mbean.getName()));

        Set<ObjectInstance> instances = mbs.queryMBeans(new ObjectName("com.alibaba.tenant.mxbean:type=MyTest"), null);
        ObjectInstance instance = (ObjectInstance) instances.toArray()[0];
        assertTrue(myMXBean.getClass().getName().equals(instance.getClassName()));

        MBeanInfo info = mbs.getMBeanInfo(myInfoObj);
        assertTrue(myMXBean.getClass().getName().equals(info.getClassName()));
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
 
Example 2
Source File: CamelContextMetadataMBeanTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuilder() throws Exception {
    CamelContext context = new DefaultCamelContext();

    Properties properties = new Properties();
    properties.setProperty(Constants.PROPERTY_CAMEL_K_CUSTOMIZER, "metadata");

    PropertiesComponent pc  = new PropertiesComponent();
    pc.setInitialProperties(properties);
    context.setPropertiesComponent(pc);

    RuntimeSupport.configureContextCustomizers(context);

    context.start();

    final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    final Set<ObjectInstance> mBeans = mBeanServer.queryMBeans(ObjectName.getInstance("io.syndesis.camel:*"), null);
    assertThat(mBeans).hasSize(1);

    final ObjectName objectName = mBeans.iterator().next().getObjectName();
    final AttributeList attributes = mBeanServer.getAttributes(objectName, ATTRIBUTES);
    assertThat(attributes.asList()).hasSize(ATTRIBUTES.length);

    context.stop();
}
 
Example 3
Source File: TestRaftServerJmx.java    From incubator-ratis with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 30000)
public void testJmxBeans() throws Exception {
  final int NUM_SERVERS = 3;
  final MiniRaftClusterWithSimulatedRpc cluster
      = MiniRaftClusterWithSimulatedRpc.FACTORY.newCluster(3, new RaftProperties());
  cluster.start();
  waitForLeader(cluster);

  MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
  Set<ObjectInstance> objectInstances = platformMBeanServer.queryMBeans(new ObjectName("Ratis:*"), null);
  Assert.assertEquals(NUM_SERVERS, objectInstances.size());

  for (ObjectInstance instance : objectInstances) {
    Object groupId = platformMBeanServer.getAttribute(instance.getObjectName(), "GroupId");
    Assert.assertEquals(cluster.getGroupId().toString(), groupId);
  }
  cluster.shutdown();
}
 
Example 4
Source File: TestRaftServerJmx.java    From ratis with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 30000)
public void testJmxBeans() throws Exception {
  final int NUM_SERVERS = 3;
  final MiniRaftClusterWithSimulatedRpc cluster
      = MiniRaftClusterWithSimulatedRpc.FACTORY.newCluster(3, new RaftProperties());
  cluster.start();
  waitForLeader(cluster);

  MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
  Set<ObjectInstance> objectInstances = platformMBeanServer.queryMBeans(new ObjectName("Ratis:*"), null);
  Assert.assertEquals(NUM_SERVERS, objectInstances.size());

  for (ObjectInstance instance : objectInstances) {
    Object groupId = platformMBeanServer.getAttribute(instance.getObjectName(), "GroupId");
    Assert.assertEquals(cluster.getGroupId().toString(), groupId);
  }
  cluster.shutdown();
}
 
Example 5
Source File: JMXIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testMonitorMBeanAttribute() throws Exception {
    CamelContext context = contextRegistry.getCamelContext("jmx-context-1");
    Assert.assertNotNull("jmx-context-1 not null", context);
    final String routeName = context.getRoutes().get(0).getId();

    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    ObjectName onameAll = ObjectNameFactory.create("org.apache.camel:*");
    Set<ObjectInstance> mbeans = server.queryMBeans(onameAll, null);
    System.out.println(">>>>>>>>> MBeans: " + mbeans.size());
    mbeans.forEach(mb -> System.out.println(mb.getObjectName()));

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("jmx:platform?format=raw&objectDomain=org.apache.camel&key.context=jmx-context-1&key.type=routes&key.name=\"" + routeName + "\"" +
            "&monitorType=counter&observedAttribute=ExchangesTotal&granularityPeriod=500").
            to("direct:end");
        }
    });

    camelctx.start();
    try {
        ConsumerTemplate consumer = camelctx.createConsumerTemplate();
        MonitorNotification notifcation = consumer.receiveBody("direct:end", MonitorNotification.class);
        Assert.assertEquals("ExchangesTotal", notifcation.getObservedAttribute());
    } finally {
        camelctx.close();
    }
}
 
Example 6
Source File: JmxMbeanHelper.java    From iaf with Apache License 2.0 5 votes vote down vote up
public static Set getMBeans() {
    MBeanServer server = getMBeanServer();
    if (server != null) {
        try {
            return server.queryMBeans(getObjectName(null), null);
        } catch (MalformedObjectNameException e) {
            LOG.warn("Could not create object name", e);
        }
    }
    return null;
}
 
Example 7
Source File: MbeanCommand.java    From LagMonitor with MIT License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!canExecute(sender, command)) {
        return true;
    }

    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

    if (args.length > 0) {
        try {
            ObjectName beanObject = ObjectName.getInstance(args[0]);
            if (args.length > 1) {
                Object result = mBeanServer.getAttribute(beanObject, args[1]);
                sender.sendMessage(ChatColor.DARK_GREEN + Objects.toString(result));
            } else {
                MBeanAttributeInfo[] attributes = mBeanServer.getMBeanInfo(beanObject).getAttributes();
                for (MBeanAttributeInfo attribute : attributes) {
                    if ("ObjectName".equals(attribute.getName())) {
                        //ignore the object name - it's already known if the user invoke the command
                        continue;
                    }

                    sender.sendMessage(ChatColor.YELLOW + attribute.getName());
                }
            }
        } catch (Exception ex) {
            plugin.getLogger().log(Level.SEVERE, null, ex);
        }
    } else {
        Set<ObjectInstance> allBeans = mBeanServer.queryMBeans(null, null);
        allBeans.stream()
                .map(ObjectInstance::getObjectName)
                .map(ObjectName::getCanonicalName)
                .forEach(bean -> sender.sendMessage(ChatColor.DARK_AQUA + bean));
    }

    return true;
}
 
Example 8
Source File: JMServer.java    From jmonitor with GNU General Public License v2.0 5 votes vote down vote up
public static JSONObject geGCInfo(String app) throws Exception {
    ObjectName obj = new ObjectName("java.lang:type=GarbageCollector,*");
    MBeanServer conn = ManagementFactory.getPlatformMBeanServer();
    Set<ObjectInstance> MBeanset = conn.queryMBeans(obj, null);
    Class<GarbageCollectorMXBean> cls = GarbageCollectorMXBean.class;
    JSONObject data = new JSONObject();
    for (ObjectInstance objx : MBeanset) {
        String name = objx.getObjectName().getCanonicalName();
        String keyName = objx.getObjectName().getKeyProperty("name");
        GarbageCollectorMXBean gc = ManagementFactory.newPlatformMXBeanProxy(conn, name, cls);
        data.put(keyName + "-time", gc.getCollectionTime() / 1000.0);
        data.put(keyName + "-count", gc.getCollectionCount());
    }
    return data;
}
 
Example 9
Source File: InternalManagementServiceDUnit.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
static void verifyMemberMBeanCleanUp(String memberNameOrId) {
  MBeanServer mBeanServer = MBeanJMXAdapter.getMBeanServer();

  Set<ObjectInstance> queryMBeans = mBeanServer.queryMBeans(getMemberObjectNamePattern(memberNameOrId), null);
  assertTrue("Gfxd Member MBean didn't get unregistered.", queryMBeans.isEmpty());

  queryMBeans = mBeanServer.queryMBeans(getObjectName(ManagementConstants.OBJECTNAME__PREFIX_GFXD + "*"), null);
  assertTrue("All Gfxd MBeans didn't get unregistered.", queryMBeans.isEmpty());
}
 
Example 10
Source File: InternalManagementServiceDUnit.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
static String verifyMemberMBeanCreation() {
    MBeanServer mBeanServer = MBeanJMXAdapter.getMBeanServer();
    String memberNameOrId = MBeanJMXAdapter.getMemberNameOrId(Misc.getDistributedSystem().getDistributedMember());

    ObjectName memberObjectNamePattern = getMemberObjectNamePattern(memberNameOrId);
//    System.out.println("memberObjectNamePattern :: "+memberObjectNamePattern);

    Set<ObjectInstance> queryMBeans = mBeanServer.queryMBeans(memberObjectNamePattern, null);
    assertTrue("Gfxd Member MBean didn't get created.", !queryMBeans.isEmpty());

    return memberNameOrId;
  }
 
Example 11
Source File: MbeanCommand.java    From LagMonitor with MIT License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!canExecute(sender, command)) {
        return true;
    }

    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

    if (args.length > 0) {
        try {
            ObjectName beanObject = ObjectName.getInstance(args[0]);
            if (args.length > 1) {
                Object result = mBeanServer.getAttribute(beanObject, args[1]);
                sender.sendMessage(ChatColor.DARK_GREEN + Objects.toString(result));
            } else {
                MBeanAttributeInfo[] attributes = mBeanServer.getMBeanInfo(beanObject).getAttributes();
                for (MBeanAttributeInfo attribute : attributes) {
                    if ("ObjectName".equals(attribute.getName())) {
                        //ignore the object name - it's already known if the user invoke the command
                        continue;
                    }

                    sender.sendMessage(ChatColor.YELLOW + attribute.getName());
                }
            }
        } catch (Exception ex) {
            plugin.getLogger().log(Level.SEVERE, null, ex);
        }
    } else {
        Set<ObjectInstance> allBeans = mBeanServer.queryMBeans(null, null);
        allBeans.stream()
                .map(ObjectInstance::getObjectName)
                .map(ObjectName::getCanonicalName)
                .forEach(bean -> sender.sendMessage(ChatColor.DARK_AQUA + bean));
    }

    return true;
}
 
Example 12
Source File: InternalManagementServiceDUnit.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
static void verifyMemberMBeanCleanUp(String memberNameOrId) {
  MBeanServer mBeanServer = MBeanJMXAdapter.getMBeanServer();

  Set<ObjectInstance> queryMBeans = mBeanServer.queryMBeans(getMemberObjectNamePattern(memberNameOrId), null);
  assertTrue("Gfxd Member MBean didn't get unregistered.", queryMBeans.isEmpty());

  queryMBeans = mBeanServer.queryMBeans(getObjectName(ManagementConstants.OBJECTNAME__PREFIX_GFXD + "*"), null);
  assertTrue("All Gfxd MBeans didn't get unregistered.", queryMBeans.isEmpty());
}
 
Example 13
Source File: InternalManagementServiceDUnit.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
static String verifyMemberMBeanCreation() {
    MBeanServer mBeanServer = MBeanJMXAdapter.getMBeanServer();
    String memberNameOrId = MBeanJMXAdapter.getMemberNameOrId(Misc.getDistributedSystem().getDistributedMember());

    ObjectName memberObjectNamePattern = getMemberObjectNamePattern(memberNameOrId);
//    System.out.println("memberObjectNamePattern :: "+memberObjectNamePattern);

    Set<ObjectInstance> queryMBeans = mBeanServer.queryMBeans(memberObjectNamePattern, null);
    assertTrue("Gfxd Member MBean didn't get created.", !queryMBeans.isEmpty());

    return memberNameOrId;
  }
 
Example 14
Source File: CamelContextMetadataMBeanTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void testBuilder() throws Exception {
    final MBeanServer mBeanServer = JmxUtils.locateMBeanServer();
    final Set<ObjectInstance> mBeans = mBeanServer.queryMBeans(ObjectName.getInstance("io.syndesis.camel:*"), null);
    assertThat(mBeans).hasSize(1);

    final ObjectName objectName = mBeans.iterator().next().getObjectName();
    final AttributeList attributes = mBeanServer.getAttributes(objectName, ATTRIBUTES);
    assertThat(attributes.asList()).hasSize(ATTRIBUTES.length);
}
 
Example 15
Source File: JmxMetricTracker.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
private void addJmxMetricRegistration(final JmxMetric jmxMetric, List<JmxMetricRegistration> registrations, MBeanServer server) throws JMException {
    Set<ObjectInstance> mbeans = server.queryMBeans(jmxMetric.getObjectName(), null);
    logger.debug("Found mbeans for object name {}", jmxMetric.getObjectName());
    for (ObjectInstance mbean : mbeans) {
        for (JmxMetric.Attribute attribute : jmxMetric.getAttributes()) {
            final ObjectName objectName = mbean.getObjectName();
            final Object value;
            try {
                value = server.getAttribute(objectName, attribute.getJmxAttributeName());
                if (value instanceof Number) {
                    logger.debug("Found number attribute {}={}", attribute.getJmxAttributeName(), value);
                    registrations.add(new JmxMetricRegistration(JMX_PREFIX + attribute.getMetricName(),
                        Labels.Mutable.of(objectName.getKeyPropertyList()),
                        attribute.getJmxAttributeName(),
                        null,
                        objectName));
                } else if (value instanceof CompositeData) {
                    final CompositeData compositeValue = (CompositeData) value;
                    for (final String key : compositeValue.getCompositeType().keySet()) {
                        if (compositeValue.get(key) instanceof Number) {
                            logger.debug("Found composite number attribute {}.{}={}", attribute.getJmxAttributeName(), key, value);
                            registrations.add(new JmxMetricRegistration(JMX_PREFIX + attribute.getMetricName() + "." + key,
                                Labels.Mutable.of(objectName.getKeyPropertyList()),
                                attribute.getJmxAttributeName(),
                                key,
                                objectName));
                        } else {
                            logger.warn("Can't create metric '{}' because composite value '{}' is not a number: '{}'", jmxMetric, key, value);
                        }
                    }
                } else {
                    logger.warn("Can't create metric '{}' because attribute '{}' is not a number: '{}'", jmxMetric, attribute.getJmxAttributeName(), value);
                }
            } catch (AttributeNotFoundException e) {
                logger.warn("Can't create metric '{}' because attribute '{}' could not be found", jmxMetric, attribute.getJmxAttributeName());
            }
        }
    }
}
 
Example 16
Source File: DevelopmentSampleJobMXBean.java    From quarks with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    DevelopmentProvider dtp = new DevelopmentProvider();
    
    Topology t = dtp.newTopology("DevelopmentSampleJobMXBean");
    
    Random r = new Random();
    
    TStream<Double> d  = t.poll(() -> r.nextGaussian(), 100, TimeUnit.MILLISECONDS);
    
    d.sink(tuple -> System.out.print("."));
    
    dtp.submit(t);
    
    System.out.println(dtp.getServices().getService(HttpServer.class).getConsoleUrl());
    
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

    StringBuffer sbuf = new StringBuffer();
    sbuf.append(DevelopmentProvider.JMX_DOMAIN);
    sbuf.append(":interface=");
    sbuf.append(ObjectName.quote("quarks.graph.execution.mbeans.JobMXBean"));
    sbuf.append(",type=");
    sbuf.append(ObjectName.quote("job"));
    sbuf.append(",*");
    
    System.out.println("Looking for MBeans of type job: " + sbuf.toString());
    
    ObjectName jobObjName = new ObjectName(sbuf.toString());
    Set<ObjectInstance> jobInstances = mBeanServer.queryMBeans(jobObjName, null);
    Iterator<ObjectInstance> jobIterator = jobInstances.iterator();

    while (jobIterator.hasNext()) {
    	ObjectInstance jobInstance = jobIterator.next();
    	ObjectName objectName = jobInstance.getObjectName();

    	String jobId = (String) mBeanServer.getAttribute(objectName, "Id");
    	String jobName = (String) mBeanServer.getAttribute(objectName, "Name");
    	String jobCurState = (String) mBeanServer.getAttribute(objectName, "CurrentState");
    	String jobNextState = (String) mBeanServer.getAttribute(objectName, "NextState");
    	
    	System.out.println("Found a job with JobId: " + jobId + " Name: " + jobName + " CurrentState: " + jobCurState + " NextState: " + jobNextState);
    }
}
 
Example 17
Source File: GridCommonAbstractTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param ignite Ignite instance to collect metrics from.
 * @return {@code Set} of metrics methods that have forbidden return types.
 * @throws Exception If failed to obtain metrics.
 */
protected Set<String> getInvalidMbeansMethods(Ignite ignite) throws Exception {
    Set<String> sysMetricsPackages = new HashSet<>();
    sysMetricsPackages.add("sun.management");
    sysMetricsPackages.add("javax.management");

    MBeanServer srv = ignite.configuration().getMBeanServer();

    Set<String> invalidMethods = new HashSet<>();

    final Set<ObjectInstance> instances = srv.queryMBeans(null, null);

    for (ObjectInstance instance: instances) {
        final String clsName = instance.getClassName();

        if (sysMetricsPackages.stream().anyMatch(clsName::startsWith))
            continue;

        Class c;

        try {
            c = Class.forName(clsName);
        }
        catch (ClassNotFoundException e) {
            log.warning("Failed to load class: " + clsName);

            continue;
        }

        for (Class interf : c.getInterfaces()) {
            for (Method m : interf.getMethods()) {
                if (!m.isAnnotationPresent(MXBeanDescription.class))
                    continue;

                if (!validateMetricsMethod(m))
                    invalidMethods.add(m.toString());
            }
        }
    }

    return invalidMethods;
}
 
Example 18
Source File: ManagedRMManagerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testManagedRMManager() throws Exception {
    final SpringBusFactory factory = new SpringBusFactory();
    bus = factory.createBus("org/apache/cxf/ws/rm/managed-manager-bean.xml");
    im = bus.getExtension(InstrumentationManager.class);
    manager = bus.getExtension(RMManager.class);
    endpoint = createTestEndpoint();
    assertNotNull("Instrumentation Manager should not be null", im);
    assertNotNull("RMManager should not be null", manager);

    MBeanServer mbs = im.getMBeanServer();
    assertNotNull("MBeanServer should be available.", mbs);

    ObjectName managerName = RMUtils.getManagedObjectName(manager);
    Set<ObjectInstance> mbset = mbs.queryMBeans(managerName, null);
    assertEquals("ManagedRMManager should be found", 1, mbset.size());

    Object o;
    o = mbs.getAttribute(managerName, "UsingStore");
    assertTrue(o instanceof Boolean);
    assertFalse("Store attribute is false", (Boolean)o);

    o = mbs.invoke(managerName, "getEndpointIdentifiers", null, null);
    assertTrue(o instanceof String[]);
    assertEquals("No Endpoint", 0, ((String[])o).length);

    RMEndpoint rme = createTestRMEndpoint();

    ObjectName endpointName = RMUtils.getManagedObjectName(rme);
    mbset = mbs.queryMBeans(endpointName, null);
    assertEquals("ManagedRMEndpoint should be found", 1, mbset.size());

    o = mbs.invoke(managerName, "getEndpointIdentifiers", null, null);
    assertEquals("One Endpoint", 1, ((String[])o).length);
    assertEquals("Endpoint identifier must match",
                 RMUtils.getEndpointIdentifier(endpoint, bus), ((String[])o)[0]);

    // test some endpoint methods
    o = mbs.getAttribute(endpointName, "Address");
    assertTrue(o instanceof String);
    assertEquals("Endpoint address must match", TEST_URI, o);

    o = mbs.getAttribute(endpointName, "LastApplicationMessage");
    assertNull(o);

    o = mbs.getAttribute(endpointName, "LastControlMessage");
    assertNull(o);

    o = mbs.invoke(endpointName, "getDestinationSequenceIds", null, null);
    assertTrue(o instanceof String[]);
    assertEquals("No sequence", 0, ((String[])o).length);

    o = mbs.invoke(endpointName, "getDestinationSequences", null, null);
    assertTrue(o instanceof CompositeData[]);
    assertEquals("No sequence", 0, ((CompositeData[])o).length);

    o = mbs.invoke(endpointName, "getSourceSequenceIds", new Object[]{true}, new String[]{"boolean"});
    assertTrue(o instanceof String[]);
    assertEquals("No sequence", 0, ((String[])o).length);

    o = mbs.invoke(endpointName, "getSourceSequences", new Object[]{true}, new String[]{"boolean"});
    assertTrue(o instanceof CompositeData[]);
    assertEquals("No sequence", 0, ((CompositeData[])o).length);

    o = mbs.invoke(endpointName, "getDeferredAcknowledgementTotalCount", null, null);
    assertTrue(o instanceof Integer);
    assertEquals("No deferred acks", 0, o);

    o = mbs.invoke(endpointName, "getQueuedMessageTotalCount",
                   new Object[]{true}, new String[]{"boolean"});
    assertTrue(o instanceof Integer);
    assertEquals("No queued messages", 0, o);
}
 
Example 19
Source File: StatusTransformer.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Write context state.
 * @param writer The output writer
 * @param objectName The context MBean name
 * @param mBeanServer MBean server
 * @param mode Mode <code>0</code> will generate HTML.
 *   Mode <code>1</code> will generate XML.
 * @throws Exception Propagated JMX error
 */
protected static void writeContext(PrintWriter writer,
                                   ObjectName objectName,
                                   MBeanServer mBeanServer, int mode)
    throws Exception {

    if (mode == 0){
        String webModuleName = objectName.getKeyProperty("name");
        String name = webModuleName;
        if (name == null) {
            return;
        }

        String hostName = null;
        String contextName = null;
        if (name.startsWith("//")) {
            name = name.substring(2);
        }
        int slash = name.indexOf('/');
        if (slash != -1) {
            hostName = name.substring(0, slash);
            contextName = name.substring(slash);
        } else {
            return;
        }

        ObjectName queryManager = new ObjectName
            (objectName.getDomain() + ":type=Manager,context=" + contextName
             + ",host=" + hostName + ",*");
        Set<ObjectName> managersON =
            mBeanServer.queryNames(queryManager, null);
        ObjectName managerON = null;
        for (ObjectName aManagersON : managersON) {
            managerON = aManagersON;
        }

        ObjectName queryJspMonitor = new ObjectName
            (objectName.getDomain() + ":type=JspMonitor,WebModule=" +
             webModuleName + ",*");
        Set<ObjectName> jspMonitorONs =
            mBeanServer.queryNames(queryJspMonitor, null);

        // Special case for the root context
        if (contextName.equals("/")) {
            contextName = "";
        }

        writer.print("<h1>");
        writer.print(Escape.htmlElementContext(name));
        writer.print("</h1>");
        writer.print("</a>");

        writer.print("<p>");
        Object startTime = mBeanServer.getAttribute(objectName,
                                                    "startTime");
        writer.print(" Start time: " +
                     new Date(((Long) startTime).longValue()));
        writer.print(" Startup time: ");
        writer.print(formatTime(mBeanServer.getAttribute
                                (objectName, "startupTime"), false));
        writer.print(" TLD scan time: ");
        writer.print(formatTime(mBeanServer.getAttribute
                                (objectName, "tldScanTime"), false));
        if (managerON != null) {
            writeManager(writer, managerON, mBeanServer, mode);
        }
        if (jspMonitorONs != null) {
            writeJspMonitor(writer, jspMonitorONs, mBeanServer, mode);
        }
        writer.print("</p>");

        String onStr = objectName.getDomain()
            + ":j2eeType=Servlet,WebModule=" + webModuleName + ",*";
        ObjectName servletObjectName = new ObjectName(onStr);
        Set<ObjectInstance> set =
            mBeanServer.queryMBeans(servletObjectName, null);
        for (ObjectInstance oi : set) {
            writeWrapper(writer, oi.getObjectName(), mBeanServer, mode);
        }

    } else if (mode == 1){
        // for now we don't write out the context in XML
    }

}