Make Local Connections to the Domain Runtime MBean Server Navigate MBean Hierarchies

Accessing WebLogic Server MBeans with JMX 4-7 port + ; String mserver = MBean-server-JNDI-name; JMXServiceURL serviceURL = new JMXServiceURLprotocol, hostname, port, jndiroot + mserver; Hashtable h = new Hashtable; h.putContext.SECURITY_PRINCIPAL, username; h.putContext.SECURITY_CREDENTIALS, password; connector = JMXConnectorFactory.connectserviceURL, h; where WLS-host and WLS-port are the listen address and listen port of a WebLogic Server instance and MBean-server-JNDI-name is one of the values listed in Table 4–1 . Note that the hash table you create does not include the name of a protocol package. By leaving this value as null, the JMX client uses the protocol definitions from the com.sun.jmx.remote.protocol package, which is in the JDK.

4.3 Make Local Connections to the Runtime MBean Server

Local clients can access a WebLogic Server instances Runtime MBean Server through the JNDI tree instead of constructing a JMXServiceURL object. When accessed from JNDI, the Runtime MBean Server returns its javax.management.MBeanServer interface. This interface contains all of the methods in the MBeanServerConnection interface plus additional methods such as registerMBean , which a local process can use to register custom MBeans. See MBeanServer in the J2SE 6.0 API Specification at http:download.oracle.comjavase6docsapijavaxmanagementMB eanServer.html . If the classes for the JMX client are located in a Java EE module, such as an EJB or Web application, then the JNDI name for the Runtime MBeanServer is: java:compenvjmxruntime For example: InitialContext ctx = new InitialContext; server = MBeanServerctx.lookupjava:compenvjmxruntime; If the classes for the JMX client are not part of a Java EE module, then the JNDI name for the Runtime MBean Server is: java:compjmxruntime

4.4 Make Local Connections to the Domain Runtime MBean Server

Local clients can also access a WebLogic Server instances Domain Runtime MBean Server through the JNDI tree instead of constructing a JMXServiceURL object. When accessed from JNDI, the Domain Runtime MBean Server returns its javax.management.MBeanServer interface. This interface contains all of the Note: Local clients can also access a WebLogic Server’s Domain Runtime MBean Server through the JNDI tree, as described in Section 4.4, Make Local Connections to the Domain Runtime MBean Server. 4-8 Developing Custom Management Utilities With JMX for Oracle WebLogic Server methods in the MBeanServerConnection interface plus additional methods such as registerMBean , which a local process can use to register custom MBeans, and other methods such as getMBeanCount, instatiate, and getClassLoader . See MBeanServer in the J2SE 6.0 API Specification at http:download.oracle.comjavase6docsapijavaxmanagementMB eanServer.html . If the classes for the JMX client are located in a Java EE module, such as an EJB or Web application, then the JNDI name for the Domain Runtime MBeanServer is: java:compenvjmxdomainRuntime For example: InitialContext ctx = new InitialContext; server = MBeanServerctx.lookupjava:compenvjmxdomainRuntime; If the classes for the JMX client are not part of a Java EE module, then the JNDI name for the Domain Runtime MBean Server is: java:compjmxdomainRuntime The Domain Runtime MBean Server is present only on the Administration Server. Because the ctx.lookup call returns a reference to the local MBeanServer, the lookup method can only be called when running on the Administration Server. If called when running on a Managed Server, a NameNotFound exception is thrown.

4.5 Navigate MBean Hierarchies

WebLogic Server organizes its MBeans in a hierarchical data model. See Section 2.4, WebLogic Server MBean Data Model. In this model, all parent MBeans include attributes that contain the object names of their children. You use the childs object name in standard JMX APIs to get or set values of the child MBeans attributes or invoke its methods. To navigate the WebLogic Server MBean hierarchy: 1. Initiate a connection to an MBean server. See the previous section, Section 4.2, Make Remote Connections to an MBean Server. Initiating the connection returns an object of type javax.management.MBeanServerConnection 2. Obtain the object name for an MBean at the root of an MBean hierarchy by invoking the MBeanServerConnection.getAttributeObjectName object-name , String attribute method where: ■ object-name is the object name of the service MBean that is registered in the MBean server. See Section 2.5.3, Service MBeans. Note: As a best practice, Oracle recommends that you use the Domain Runtime MBean Server only for MBeans that perform domain-wide operations. You should ensure that any MBean processing and network activity do not slow down the Administration Server and prevent it from processing administration operations. Accessing WebLogic Server MBeans with JMX 4-9 Table 2–3 describes the type of service MBeans that are available in each type of MBean server. ■ attribute is the name of a service MBean attribute that contains the root MBean. 3. Successively invoke code similar to the following: ObjectName on = MBeanServerConnection.getAttributeobject-name, attribute where: ■ object-name is the object name of the current node MBean in the MBean hierarchy. ■ attribute is the name of an attribute in the current MBean that contains one or more instances of a child MBean. If the attribute contains multiple children, assign the output to an object name array, ObjectName[]. To determine an MBeans location in an MBean hierarchy, refer to the MBeans description in Oracle WebLogic Server MBean Reference. For each MBean, the WebLogic Server MBean Reference lists the parent MBean that contains the current MBeans factory methods. For an MBean whose factory methods are not public, the Oracle WebLogic Server MBean Reference lists other MBeans from which you can access the current MBean.

4.6 Example: Printing the Name and State of Servers