The agents that are configured to be discovered must have an active DiscoveryResponder registered in their MBean server. The responder plays a role in both active and passive discovery:
When the start operation of a discovery responder is invoked, it sends out a multicast message indicating that it has been activated.
When the discovery responder is active, it automatically responds to discovery requests.
When the responder's MBean is unregistered or its stop operation is invoked, it sends out a multicast message to indicate that it will be deactivated.
Both types of messages are proprietary and their contents are not exposed to the user. These messages contain information about the MBean server, its delegate's information and a list of communicator MBeans, unless not requested by the discovery client.
In our example we create the discovery responder in the MBean server and then activate it.
// Set the domain name for the demo // String domain = "DiscoveryDemo:" ; // build the DiscoveryResponder MBean ObjectName // ObjectName discoveryResponderMBeanObjectName = new ObjectName(domain + "name=myDiscoveryResponder"); // Create and register the DiscoveryResponder MBean // try { ObjectInstance discoveryResponderObjectInstance = myMBeanServer.createMBean( "com.sun.jdmk.discovery.DiscoveryResponder", discoveryResponderMBeanObjectName) ; // we don't start the responder until our monitor is listening } catch(Exception e) { e.printStackTrace(); System.exit(1); } [...] try { myMBeanServer.invoke (discoveryResponderMBeanObjectName, "start", null, null) ; } catch(Exception e) { echo("\tDiscoveryResponder MBean was already started.") ; } |
The discovery responder has attributes for exposing a multicast group and a multicast port. These attributes define a multicast socket that the responder will use to receive discovery requests. It will also send activation and deactivation messages to this multicast group. When sending automatic responses to discovery requests, the time-to-live is provided by the discovery client. The responder's time-to-live attribute is only used when sending activation and deactivation messages.
We use the default settings of the discovery responder that are the multicast group 224.224.224.224 on port 9000 with time-to-live of 1. In order to modify these values, you need to set the corresponding attributes before starting the discovery responder MBean. You can also specify them in the class constructor. If the responder is active, you will need to stop it before trying to set any of these attributes. In that way, it will send a deactivation message using the old values and then an activation message with the new values.