![]() |
|||
![]() |
![]() ![]() |
![]() |
![]() ![]() |
![]() |
![]() ![]() |
![]() |
| ||||||
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. 15.2.2 Discovery MonitorThe 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 224.224.224.224 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
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. 15.2.3 Discovery Responder NotificationsWhen 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
15.3 Running the Discovery ExampleThe examplesDir/current/Discovery directory contains the source file for the application that demonstrates the discovery service.
|
$ javac -classpath classpath *.java |
Start the Client.
$ java -classpath classpath Client |
You will be prompted to press Enter to discover connector servers, to provide the host name of a machine where servers are running or to exit the discovery component. However, there are not yet any servers to discover, because the Responder has not yet been started.
In a second terminal window, start the Monitor
$ java -classpath classpath Monitor |
You will see confirmation that the monitor has started, and that it is passively listening for notifications,
In a third terminal window, start the Responder.
$ java -classpath classpath Responder |
You will see the creation of the different connector servers. Then you will be invited to create further connector servers by pressing Enter.
In the window in which you started the Monitor, you will see the connector servers created by Responder being discovered.
Press Enter in the terminal window in which you started the Client.
You will see the Client discovering the connector servers created by the Responder, and connecting to them to retrieve information about them, before closing the connections.
You can continue discovering and connecting to connector servers for as long as the Responder is active.
When you have finished, stop the Responder, the Monitor and the Client.
![]() ![]() |