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. Then, we create different connector servers that will discover the agent passively, due to its active discovery responder.
public class Responder { public static void main(String[] args) { try { MBeanServer myMBeanServer = MBeanServerFactory.createMBeanServer(); echo("\nCreate and register a DiscoveryResponder MBean."); ObjectName dc = new ObjectName("DiscoveryExample:name=DiscoveryResponder"); myMBeanServer.createMBean("com.sun.jdmk.discovery.DiscoveryResponder", dc); myMBeanServer.invoke(dc, "start", null, null); // Create an HtmlAdaptorServer on the default port. [...] // Create JMX Remote API connector servers JMXServiceURL url; JMXConnectorServer server; ObjectName on; // rmi url = new JMXServiceURL("rmi", null, 0); server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, myMBeanServer); server.start(); url = server.getAddress(); on = new ObjectName("jmx-remote:protocol=rmi"); myMBeanServer.registerMBean(server, on); // Create RMI/IIOP connector server [...] // Create JMXMP connector server [...] // stop/start the responder to send a notification myMBeanServer.invoke(dc, "stop", null, null); Thread.sleep(100); myMBeanServer.invoke(dc, "start", null, null); // Create wrapped legacy RMI and HTTP connector servers [...] // Repeat for the other current and legacy connector protocols [...] // stop/start the responder to allow a Monitor to find them myMBeanServer.invoke(dc, "stop", null, null); Thread.sleep(100); myMBeanServer.invoke(dc, "start", null, null); [...] echo("All servers have been registered."); echo("\n>>> Press return to exit."); System.in.read(); System.exit(0); } catch (Exception e) { e.printStackTrace(); } } |
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.