Java Dynamic Management Kit 4.1 Tutorial

Running the Notification Forwarding Example

The examplesDir/Notification directory contains all of the files for the broadcaster MBean, the BaseAgent application, and our Client application which is itself the listener object.

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/Notification/
$ javac -classpath classpath *.java

To run the notification forwarding example, we use the BaseAgent application which contains an RMI adaptor server. To run the example, launch the agent on another host or in another terminal window with the following command. Be sure that the classes for the NotificationEmitter MBean can be found in its classpath.


$ java -classpath classpath BaseAgent

Wait for the agent to be completely initialized, then launch the manager with the following command, where hostname is the name of the machine running the agent. If you launched the agent on the same machine, you can omit the hostname.


$ java -classpath classpath Client hostname

When launched, the manager application first creates the NotificationEmitter MBean and then registers itself as a listener. The manager then steps through the various notification forwarding situations that we have seen in this topic. Press <Enter> to step through the example when the application pauses.

You may also interact with the example through the HTML adaptor of the BaseAgent. Leave the agent application running and launch the manager again.

Interacting with the Notification Forwarding Mechanism
  1. Load the following URL in your browser and go to the MBean view of the NotificationEmitter MBean:

    http://hostname:8082/

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

  2. When the manager application pauses for the first time, invoke the sendNotifications method from your browser and enter a small integer as the parameter.

    You should see the listener handle your notifications in the manager's terminal window. Since the manager is still in push mode, they were forwarded immediately.

  3. Press <Enter> in the terminal window: the manager is now in pull mode with a pull period of 500 milliseconds. Through the MBean view, send 1000 notifications.

    If your agent's host is slow enough, or your manager's host fast enough, you may be able to see the manager pause briefly after it has processed all notifications from one period and before the next ones are forwarded.

  4. Press <Enter> in the terminal window: the manager will now forward notifications by request. Before pressing <Enter> again, have the MBean send 15 notifications.

    You should see the manager pull all of the notifications: the 30 triggered by the manager and the 15 we just triggered. They were all kept in the buffer, waiting for the manager's request to forward them. Remember that the sendNotifications operation resets the sequence numbering every time it is invoked.

  5. Press <Enter> in the terminal window: the manager will now set the cache size to 10 notifications and set the overflow mode to DISCARD_OLD. Before pressing <Enter> again, have the MBean send 15 more notifications.

    Only the last ten of our notifications could fit into the cache buffer, all the rest, including those already triggered by the manager, overflowed and were discarded. Press <Enter> to see that they are tallied in the overflow count.

  6. Press <Enter> in the terminal window: the cache size is still 10 notifications and the manager will now set the overflow mode to DISCARD_NEW. Before pressing <Enter> again, have the MBean send only 5 more notifications.

    The first ten of the manager-triggered notifications are received: all of the more recent notifications, including ours, overflowed the cache buffer and were lost. Press <Enter> to see that they are tallied in the overflow count: the 35 from the last step plus 25 more from this step, for a total of 60.

  7. Press <Enter> in the terminal window one last time to stop the Client application. Stop the agent application in the same manner when you are finished running the example.