The examplesDir/Discovery directory contains the source file for the agent application that demonstrates the discovery service. This agent creates the discovery client, monitor and responder in the same MBean server, so it notifies itself when the responder is online and discovers its own presence. By launching several of these applications, you can see other agents being discovered.
Compile the file in this directory with the javac command. For example, on the Solaris platform with the Korn shell, you would type:
$ cd examplesDir/Discovery/ $ javac -classpath classpath *.java |
To run the discovery example, launch the agent application with the following command:
$ java -classpath classpath DiscoveryAgent |
The agent application registers an HTML adaptor on the default port (8082). Then press <Enter> to initialize the discovery components. The discovery service is now ready, except for the discovery responder which hasn't been started yet.
Press <Enter> a second time to activate the discovery responder.
The discovery monitor which has already been started receives the responder's activation message and triggers the notification listener. Our handler method prints out the information from the discovery response notification, indicating that the responder is ONLINE.
Press <Enter> again to invoke the findCommunicators method of the discovery client and display its results. The content of the discovery response is identical to the previous information, in particular, it contains the object name of the HTML adaptor in our application.
Leave the application running in this state.
Now launch another DiscoveryAgent application in another terminal window or on another host. You must specify a non-default port number for the HTML adaptor if running on the same host, for example:
$ java -classpath classpath DiscoveryAgent 8084 |
Both applications will be using the multicast group 224.224.224.224 and multicast port 9000, so they will detect each other's presence. Go through the steps of this second application: you should see the first application receive the activation message of the second responder. Then, the active discovery should detect both agents. If your agents are running on the same host, you can tell them apart by their unique MBeanServerId values in the response information.
Before stopping either of the discovery responders, you can interact with them through their HTML adaptors. Connect to the first agent by loading the following URL in a browser:
You can see the MBeans for all of the discovery components. From the MBean view of the discovery responder, call its stop operation, modify its TimeToLive attribute, and restart it. The discovery monitor in the other agent should detect the two events and signal them to our listener.
You can also initiate an active search through the discovery client's MBean: invoke either of its find methods. However, the HTML adaptor cannot display the contents of the resulting DiscoveryResponse object.
When you are finished, stop the discovery responders on both agents and then the applications themselves by pressing <Enter> twice in each terminal window. The second agent to be stopped should see the discovery responder of the first being deactivated.