Java Dynamic Management Kit 5.1 Tutorial

15.2.3 Discovery Responder Notifications

When it receives a responder's activation or deactivation message, the discovery monitor sends notification objects of the DiscoveryResponderNotification class. This notification contains the new state of the discovery responder (ONLINE or OFFLINE) and a DiscoveryResponse object with information from the agent where the responder is located.

The listener could use this information to update a list of agents in the network. In our example, the listener is the agent application itself, and the handler method only prints out the information in the notification.

Example 15–5 Discovery Responder Notification Handler

private static class MyListener implements NotificationListener {
	   public void handleNotification(Notification notif, Object handback) {

	      try {
       		DiscoveryResponderNotification dn 
                               = (DiscoveryResponderNotification)notif;
            DiscoveryResponse dr = (DiscoveryResponse)dn.getEventInfo()  ;

		         JMXServiceURL url = null;

		         // legacy servers
		         Collection c = dr.getObjectList().values();
		         for (Iterator iter=c.iterator(); iter.hasNext();) {
		              Object o =;
		              if (!(o instanceof ConnectorAddress)) {
		              ConnectorAddress ca = (ConnectorAddress)o;
		              if (ca.getConnectorType().equals("SUN RMI")) {
			               url = new JMXServiceURL("jdmk-rmi",
		              // Repeat for jdmk-http and jdmk-https connectors

                  } else {

                  echo("\nFound a legacy server which is registered as
                       a legacy MBean: "
                       +url.getProtocol()+" "+url.getHost()+" "
		              echo("Connecting to that server.");
                  JMXConnector jc = JMXConnectorFactory.connect(url);

		         // JMX Remote API servers
		         JMXServiceURL[] urls = dr.getServerAddresses();
		         for (int ii=0; ii<urls.length; ii++) {
		              echo("\nFound a server which is registered as a 
                      JMXConnectorServerMBean: "
		              echo("Connecting to that server.");
		              JMXConnector jc = JMXConnectorFactory.connect(urls[ii]);
		              echo("Its default domain is 
	        } catch (Exception e) {
		         echo("Got unexpected exception: "+e);