Java Dynamic Management Kit 4.2 Tutorial

Running the Agent Notification Example

Now that we have seen all of our notification broadcaster objects and all of our listener handlers, we are ready to run the example.

The examplesDir/Notification2 directory contains all of the files for the simple MBean, the listener objects, and the agent. When launched, the agent application adds the MBean server delegate listener first, so that a notification can be seen for the creation of the MBean. Attribute change notifications are triggered by modifying attributes through the HTML adaptor.

Compile all files in this directory with the javac command. For example, on the Solaris platform with the Korn shell, you would type:


$ cd examplesDir/Notification2/
$ javac -classpath classpath *.java

To run the example, launch the agent application:


$ java -classpath classpath Agent
Triggering Notifications in the Agent Example
  1. After the agent application has started and added the MBean server delegate listener, press <Enter> to create the simple MBean.

    Before the next printout of the agent application, you should see the text generated by the AgentListener class. Its handler method has been called with an MBean creation notification, and it prints out the object name of our new MBean.

  2. Now that the simple MBean is registered and the SimpleStandardListener has been added as a listener, you can trigger attribute change notifications by modifying the State attribute through the HTML adaptor.

    Load the following URL in your browser:

    http://localhost:8082/

    If you get an error, you may have to switch off proxies in your preference settings or substitute your machine name for localhost. Any browser on your local network can also connect to this agent by using your machine name in this URL.

    In the attribute table of our MBean view, enter a new value for the State attribute and click the "Apply" button. Every time you do this, you should see the output of the attribute change listener in the terminal window where you launched the agent.

  3. When you are finished with the attribute change notifications, press <Enter> in the agent's terminal window to remove our simple MBean.

    Again, you should see the output of the MBean server delegate listener. This time it has detected that our MBean has been de-registered from the MBean server.

  4. Press <Enter> again to stop the agent application.