Java Dynamic Management Kit 5.1 Tutorial

3.5 Running the Model MBean Example

The examplesDir/current/ModelMBean directory contains the TestBean.java file that is the target object of the sample model MBean. This directory also contains a simple notification listener class and the agent application, ModelAgent, which instantiates, configures, and manages a model MBean.

The model MBean itself is given by the RequiredModelMBean class defined in the javax.management.modelmbean package provided in the runtime JAR file (jmx.jar) of the Java Dynamic Management Kit (Java DMK).

To Run the Model MBean Example
  1. Compile all files in this directory with the javac command.

    For example, on the Solaris platform, type:


    $ cd examplesDir/current/ModelMBean/
    $ javac -classpath classpath *.java
    
  2. To run the example, start the agent class with the following command:


    $ java -classpath classpath ModelAgent
    
  3. Press Enter when the application pauses to step through the example.

    The agent application handles all input and output in this example and gives a view of the MBean at runtime.

We can then see the result of managing the resource through its exposed attributes and operations. The agent also instantiates and registers a listener object for attribute change notifications sent by the model MBean. You can see the output of this listener whenever it receives a notification, after the application has called one of the attribute setters.