The examples directory provides two examples that demonstrate how to implement and manage an open MBean.
In the first open MBean example, we implement an open MBean and manage it through a simple JMX agent application. We develop a sample open MBean that uses some of the open data types and correctly exposes its management interface at runtime through the OpenMBean*Info classes. We then develop a simple JMX agent for exercising the open MBean, which involves:
Initializing the MBean server
Creating and adding the sample open MBean to the MBean server
Getting and displaying the open MBean management information
Calling some operations on the MBean
The examplesDir/OpenMBean directory contains the SampleOpenMBean.java file, which is an open MBean, and the OpenAgent.java file which is a simple JMX agent used to interact with the open MBean.
Compile all files in the examplesDir/OpenMBean directory with the javac command.
For example, on the Solaris platform, type:
$ cd examplesDir/OpenMBean/ $ javac -classpath classpath *.java |
Run the agent class that interacts with the open MBean:
$ java -classpath classpath OpenAgent |
Press Enter when the application pauses, to step through the example.
You interact with the agent through the standard input and output in the window where it was launched. The OpenAgent displays information about each management step and waits for your input before continuing.
In the second open MBean example, we implement an open MBean and manage it through a simple JMX manager application. Although it is helpful to run the first open MBean example before this example, it is not obligatory.
We develop a sample open MBean that uses some of the open data types and correctly exposes its management interface at runtime through the OpenMBean*Info classes. See the README2.html file in the examplesDir/OpenMBean2/README2 directory for more detailed information on the data structure of this example.
We then develop a simple manager for exercising the open MBean, which involves:
Creating and adding the sample open MBean to the MBean server
Getting and displaying the open MBean management information
Invoking some operations on the MBean
The examplesDir/OpenMBean2 directory contains the following source files:
CarOpenMBean.java, which is an open MBean
Agent.java, which is a minimal agent comprising an MBean server, an HTML adaptor and an RMI connector
Manager.java, which is a client application that runs the example scenario
Compile all files in the examplesDir/OpenMBean2 directory with the javac command.
For example, on the Solaris platform, type:
$ cd examplesDir/OpenMBean2/ $ javac -classpath classpath *.java |
Run the agent class that interacts with the open MBean:
$ java -classpath classpath Agent |
Open a second terminal window and change to the OpenMBean2 example directory:
For example, on the Solaris platform, type:
$ cd examplesDir/OpenMBean2/ |
You can open this second terminal window on another host.
Run the manager class:
If you are using a second terminal window on the same host as the agent class, type:
$ java -classpath classpath Manager |
If you are using another host, type:
$ java -classpath classpath Manager hostname |
where hostname is the name or IP address of the host on which the agent is running.
Interact with the manager through the standard input and output in the window where it was started. The Manager class displays information about each management step and waits for your input before continuing.