Obtaining a Reference to the MBean Server
The under-the-hood implementation
of the MBean server in the RI is
com.sun.management.jmx.MBeanServerImpl
, but this
class should never be instantiated directly. Instead, the RI provides
a factory class called MBeanServerFactory
that
contains various static methods that allow you to obtain a reference
to the MBean server. In this section, we will describe each of those
static methods and give examples of how to use them. Example 6-1 is an abbreviated version of the
MBeanServerFactory
class.
Example 6-1. The static methods of MBeanServerFactory
package javax.management; // . . . public class MBeanServerFactory { // . . . public static MBeanServer createMBeanServer ( ) { // . . . } public static MBeanServer createMBeanServer (String domain) { // . . . } public static MBeanServer newMBeanServer ( ) { // . . . } public static MBeanServer newMBeanServer (String domain) { // . . . } public synchronized static ArrayList findMBeanServer (String AgentId) { // . . . } public static void releaseMBeanServer (MBeanServer mbeanServer) { // . . . } // . . . }
There are six static methods on
MBeanServerFactory
, as shown in Example 6-1. These methods allow you to create an
instance, find one or more instances, and release a reference to an
instance of an MBean server.
Creating the MBean Server
If no MBean server instance exists (we’ll discuss how to find that out later), there are four static methods that allow you to create one. The first two, overloads ...
Get Java Management Extensions now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.