Java Dynamic Management Kit 5.1 Tutorial

15.2.2 Discovery Monitor

The discovery monitor is a notification broadcaster: when it receives an activation or deactivation message from a discovery responder, it sends a discovery responder notification to its listeners. Once its parameters are configured and the monitor is activated, the discovery is completely passive. You can add or remove listeners at any time.

The DiscoveryMonitor MBean has multicast group and multicast port attributes that determine the multicast socket where it will receive responder messages. Like the other components of the discovery service, the default multicast group is and the default port is 9000. You can specify other values for the group and port either in the constructor or through attribute setters when the monitor is off-line.

Example 15–4 shows a discovery monitor being started, and then a listener being added.

Example 15–4 Instantiating and Starting a Discovery Monitor

public class Monitor {
    public static void main(String[] args) throws Exception {

       echo("Create a DiscoveryMonitor.");
	      DiscoveryMonitor dm = new DiscoveryMonitor();

	      echo("Add a listener to receive monitor notifications.");
	      dm.addNotificationListener(new MyListener(), null, null);
	      echo("Waiting for new server notifications ...");

	      echo("\nType any key to stop the monitor.");;

	      echo("\nThe monitor has been stopped.");


The discovery monitor must be activated with the start operation before it will receive responder messages and send notifications. If it is being used as an MBean, it will be stopped automatically if it is unregistered from its MBean server. If it is not used as an MBean, as is the case here, you should invoke its stop method before your application exits.