An application triggers a search operation by invoking the findMBeanServers or findCommunicators methods on an active DiscoveryClient object. Using the current settings, it will send the multicast request and block for the timeout period. At the end of the timeout period, these methods return the responses that were received.
Both methods return a vector of DiscoveryResponse objects. This class exposes methods for retrieving information about the MBean server and the registered communicator MBeans in the agent. The MBean server information is the same as that exposed by that agent's MBean server delegate. The communicators are identified by ConnectorAddress objects and indexed by object name in a hash table.
Both search methods return the information about the agent's MBean server. The hash table of communicator MBeans is always empty for discovery responses returned by the findMBeanServers method. Otherwise, you can extract object names and protocol information from the hash table. One way of distinguishing the communicator MBeans is to rely on the default names provided by the ServiceName class.
All discovery messages sent between components of the discovery service are compatible between applications running different versions of the Java platform or between versions 5.0 and 5.1 of the Java DMK. However, these different configurations are not compatible for subsequent management operations through connectors. You can use the getImplementationVersion method of the DiscoveryResponse object to determine both the Java platform and product version numbers.
In our example, we request all information about the agents and print out all information in the discovery responses.
private static void discover(String host) throws Exception { Vector v = null; if (host == null || host.equals("")) { v = discoveryClient.findCommunicators(); } else { v= discoveryClient.findCommunicators(host); } if (v.size() == 0) { echo("No connector server has been found."); return; } for (int i=0; i<v.size(); i++) { DiscoveryResponse dr = (DiscoveryResponse)v.get(i); JMXServiceURL url = null; // legacy servers Collection c = dr.getObjectList().values(); for (Iterator iter=c.iterator(); iter.hasNext();) { Object o = iter.next(); if (!(o instanceof ConnectorAddress)) { continue; } ConnectorAddress ca = (ConnectorAddress)o; if (ca.getConnectorType().equals("SUN RMI")) { url = new JMXServiceURL("jdmk-rmi", ((RmiConnectorAddress)ca).getHost(), ((RmiConnectorAddress)ca).getPort()); // Repeat for jdmk-http and jdmk-https connectors [...] } else { echo("Got an unknown protocol: "+ca.getConnectorType()); continue; } echo("\nFound a legacy server which is registered as a legacy MBean: " +url.getProtocol()+" "+url.getHost()+" "+url.getPort()); echo("Connecting to that server."); JMXConnector jc = JMXConnectorFactory.connect(url); echo("Its default domain is "+jc.getMBeanServerConnection().getDefaultDomain()); echo("Closing the connection to that server."); jc.close(); } // JMX-remote servers JMXServiceURL[] urls = dr.getServerAddresses(); echo(""); for (int ii=0; ii<urls.length; ii++) { echo("\nFound a server which is registered as a JMXConnectorServerMBean: " +urls[ii]); echo("Connecting to that server."); JMXConnector jc = JMXConnectorFactory.connect(urls[ii]); echo("Its default domain is "+jc.getMBeanServerConnection().getDefaultDomain()); echo("Closing the connection to that server."); jc.close(); } } } |
On the agent side, the discovery responder automatically replies to discovery requests. Any active, registered responder in the same multicast group that is reached within the given time-to-live of the request will respond. It will automatically gather the requested information about its MBean server and send the response. The settings of the responder do not affect its automatic reply to discovery requests. In 15.2.1 Discovery Responder we will cover how its settings control passive discovery.
The discovery client can search for agents via all the connector protocols supported by Java DMK, both current and legacy. Java DMK 5.1 introduces a new DiscoveryResponse method, getServerAddresses, which is used to get the addresses of any servers registered in an MBean server as a JMXConnectorServerMBean. The getServerAddresses method can discover servers that are either instances of the JMX Remote API JMXConnectorServer, or legacy servers wrapped to appear as such. This new method ensures compatibility between the following pairs of discovery clients and servers created using versions 5.0 and 5.1 of Java DMK.
A Java DMK 5.0 discovery client and a Java DMK 5.1 discovery server:
A 5.0 client can discover a 5.1 connector server, but only if it is a legacy server registered as a legacy MBean.
A Java DMK 5.1 discovery client and a Java DMK 5.0 discovery server:
The method DiscoveryResponse.getObjectlist() will return a hashtable of 5.0 connector servers.
The method DiscoveryResponse.getServerAddresses() will return an empty table.
A Java DMK 5.1 discovery client and a Java DMK 5.1 discovery server:
The method DiscoveryResponse.getServerAddresses() will return a table of the addresses of all the servers that are registered as either legacy or JMX Remote API JMXConnectorServerMBean MBeans.
The method DiscoveryResponse.getObjects() will return a vector of legacy servers that are registered as legacy MBeans.
All the above relations between versions are also true for the passive discovery monitor.
In active discovery, the discovery client controls all parameters of a search it initiates, including the response mode of the discovery responder. The discovery client determines whether responses are sent back on a different socket (unicast) or sent to the same multicast group. The default is unicast: if you want to use the multicast response mode, set the PointToPointResponse attribute to false before initiating the discovery.
When the PointToPointResponse boolean attribute is true, the discovery client specifies unicast mode in its discovery requests. The responder will create a datagram socket for sending the response only to the discovery client. As shown in the following diagram, each responder will send its response directly back to the discovery client. The datagram socket used by each responder is bound to its local host address; this cannot be customized.
When the PointToPointResponse boolean attribute is false, the discovery client specifies multicast mode in its requests. The discovery responder will use the existing multicast socket to send response, broadcasting it to the same multicast group as the request. As shown in the following diagram, every member of the multicast group will receive the message, but only the discovery client can make use of its contents. Multicast mode avoids having to open another socket for the response, but all of the responses will create traffic in each application's socket.