Java Dynamic Management Kit 4.2 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 connector server.

Instructions
  1. 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
    
  2. Wait for the agent to be completely initialized, then launch the manager in another window 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.

  3. Press <Enter> when the application pauses to step through the various notification forwarding situations that we have seen in this topic.

  4. Press <Enter> one last time in the manager window to exit the application.

    Leave the agent application running if you wish interact with the example through the HTML adaptor of the BaseAgent.

Interacting with the Notification Forwarding Mechanism
  1. Launch the manager in another window 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
    
  2. 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 browser preference settings. Any browser on your local network can also connect to this agent using this URL.

  3. When the manager application pauses for the first time, invoke the sendNotifications method from your browser with 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.

  4. Press <Enter> in the manger 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.

  5. Press <Enter> in the manager window: the agent 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.

  6. Press <Enter> in the manager's window: the cache size will now be set to 10 notifications and 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.

  7. Press <Enter> in the manager's window: the cache size is still 10 notifications and the overflow mode will be set 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.

  8. Press <Enter> in the manager's window one last time to stop the Client application. Press <Enter> in the other window to stop the agent application when you are finished running the example.