28 Configuring Custom MBeans

This chater provides information on configuring standard, MX, and JMX MBeans.

28.1 Creating an MBean XML Configuration File

Custom MBeans are configured in an XML configuration file. The elements in the file describe the MBean type, MBean implementation, and the target MBean ObjectName. The current release of Coherence supports these types of custom MBeans.

See Appendix K, "MBean Configuration Elements" for a complete descriptions of the elements used in this chapter.

28.1.1 Configuring Standard MBeans

The configuration in Example 28-1 will create a Coherence:type=Query,nodeId=<nodeId> using the standard MBean com.oracle.customMBeans.Query class for the node. This example specifies an MBean class (mbean-class), an MBean name (mbean-name), and whether it is registered (enabled) in the instance.

Example 28-1 Using an MBean to Create a Query Node

<mbeans>
  <mbean id="100">
    <mbean-class>com.oracle.customMBeans.Query</mbean-class>
    <mbean-name>type=Query</mbean-name>
    <enabled>true</enabled>
  </mbean>
</mbeans>

28.1.2 Configuring MXBeans

The configuration in Example 28-2 will execute the standard Java method getMemoryMXBean in the java.lang.management.ManagementFactory class and use the result to create a Coherence:type=java,SubSystem=Memory,nodeId=<nodeId> for the node. The example specifies an MBean factory (mbean-factory), an accessor method name on the factory (mbean-accessor), an MBean name (mbean-name), and whether it is registered (enabled) in the instance.

Example 28-2 Getting an MBean for the Memory System of a Java Virtual Machine

<mbeans>
  <mbean id="2">
    <mbean-factory>java.lang.management.ManagementFactory</mbean-factory>
    <mbean-accessor>getMemoryMXBean</mbean-accessor>
    <mbean-name>type=java,SubSystem=Memory</mbean-name>
    <enabled>true</enabled>
  </mbean>
</mbeans>

28.1.3 Configuring JMX MBeans

JMX MBeans are MBeans that exist in a local MBean server that need to be added to the Coherence Management structure. This allows consolidation of MBeanServer information into a single source. The configuration in Example 28-3 executes the JMX query, java.lang:*, on the node's local MBean server and uses the results to create corresponding MBeans on the centralized Coherence MBean server. The example specifies a JMX MBean query(mbean-query), an MBean name (mbean-name), and whether it is registered(enabled) in the instance.

Example 28-3 Executing a JMX Query and Creating an MBean on the MBean Server

<mbeans>
  <mbean id="1">
    <mbean-query>java.lang:*</mbean-query>
    <mbean-name>type=Platform</mbean-name>
    <enabled>true</enabled>
  </mbean>
<mbeans>

Figure 28-1 illustrates the results on the query in JConsole.

Figure 28-1 MBean Query Displayed in the JConsole

Description of Figure 28-1 follows
Description of "Figure 28-1 MBean Query Displayed in the JConsole"

28.2 Enabling a Custom MBean Configuration File

You can enable the custom MBean configuration file by setting a system property or by including a specially named file in the class path.

28.2.1 Setting a System Property

Coherence provides the following system property to specify the name and location of a custom MBean configuration file. Setting this system property will cause the Coherence node to load the MBeans defined in the file represented by filename.

Example 28-4 System Property to Load an MBean

-Dtangosol.coherence.mbeans=<filename>

28.2.2 Adding a Custom MBean Configuration File to the Class Path

By convention, Coherence recognizes the configuration file named custom-mbeans.xml as containing a custom MBean configuration. If you name your custom MBean configuration file custom-mbeans.xml and include it in the class path, then the Coherence node will load the configured MBeans.