Java Dynamic Management Kit 5.1 Tutorial

14.3 Running the Cascading Example

The examplesDir/current/Cascading directory contains all of the files for the master agent and subagent applications, along with a simple MBean.

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

    $ cd examplesDir/current/Cascading/
    $ javac -classpath classpath *.java
  2. Start the subagent in another terminal window with the following command. Be sure that the classes for the SimpleStandard MBean can be found in its classpath.

    $ java -classpath classpath -Durl="subagent_input_url" SubAgent

    Here, subagent_url is the URL that is passed to the JMXConnectorServerFactory to create the subagent's JMXConnectorServer. You can use one of the following URLs:

    • service:jmx:jmxmp://

    • service:jmx:rmi://

    • service:jmx:iiop://

    Alternatively, you can specify your own URL, for example.


    Note that you can start many subagents in different terminal windows, for example.

    $ java -Dhtml.port=8082 -Durl="subagent1_input_url" SubAgent
    $ java -Dhtml.port=8182 -Durl="subagent2_input_url" SubAgent

    However you start the subagent, it will inform you onscreen of the URL, subagent-actual-url, at which it can be found.

  3. Wait for the agent to be completely initialized, then start the master agent with the following command:

    $ java -classpath classpath MasterAgent subagent-actual-url

    In the command above, subagent-actual-url is the URL you were given when you launched the subagent. If you started more than one subagent, you can start the MasterAgent as shown in the following command.

    $ java -classpath classpath MasterAgent subagent1-actual-url 
    subagent2-actual-ur ... 

    When started, the master agent application first creates the CascadingService MBean and then mounts the subagent's ExportDomain in its target MBean server. The master agent then performs operations on the cascaded MBeans of the subagent. Press Enter to step through the example when the application pauses.

  4. You can interact with the example through the HTML adaptor of the master agent and subagent.

    This is demonstrated in How to Interact with a Cascade Hierarchy.

  5. If you are still receiving timer notifications on the master agent, press Enter once more to remove the listener, but leave both agent applications running.

How to Interact with a Cascade Hierarchy
  1. Open two browser windows side by side and load the following URLs:



    Master Agent


    In the subagent, you should see the timer MBean in the ExportDomain and a SimpleStandard MBean in the DefaultDomain.

    The master agent is recognizable by the cascading service MBean in com.sun.jdmk. Otherwise it has identical timer MBeans registered in the subagent/agent#/ExportDomain: this is the cascaded version of the timer in the subagent. The SimpleStandard MBean is not cascaded because our cascading service instance filters with the following object name pattern:


  2. Create four MBeans of the SimpleStandard class in following order:

    On the Master Agent:


    On the Subagent:




  3. Reload the agent view on the master agent.

    The cascaded MBeans for the last two agents have been created automatically. Look at the MBean view of either of these cascaded MBeans on the master agent. Their class name appears as SimpleStandard.

  4. In the master agent, set a new value for the State string attribute of all 3 of its SimpleStandard MBeans.

    When you look at the corresponding MBeans in the subagent, you see that all the MBeans were updated through the master agent.

  5. In the subagent, invoke the reset operation of all 3 of its SimpleStandard MBeans.

    When you inspect the MBeans in the master agent, the values for all were reset. Remember that the HTML adaptor must get the values of attributes for displaying them, so they were correctly retrieved from the cascaded MBeans that we reset.

  6. In the subagent, unregister MBeans number=1 and number=3, then update the agent view on the master agent.

    The cascaded MBean is automatically removed by the cascading service.

  7. Invoke the stop operation of the CascadingService MBean in the master agent.

    The last cascaded MBean for the timer is removed from the master agent. The two agents are no longer connected.

  8. If you have finished with the agents, press Enter in both of their terminal windows to exit the applications.