Noel Enete
LookupDiscovery


How to find the lookup services by group name.

LookupDiscovery


Each instance of this class initiates a search for nearby lookup services. The search continues as long as it is active (until the terminate() method is sent to it).

As qualifying lookup services are encountered, the LookupDiscovery object calls the discovered() method of each registered DiscoveryListener with a DiscoveryEvent that has one ServiceRegistrar object for each lookup service it has found. As the LookupDiscovery object learns that qualifying lookup services have gone away, it calls the discarded() method of each registered DiscoveryListener with the same information.

The lookup services are members of groups. When instantiating the LookupDiscovery object, you must specify the groups you want and only those lookup services are returned.

If a service requester attempts to call a discovered lookup service and receives a RemoteException, the requester is expected to call the discarded() method of the LookupDiscovery object to report the problem. The LookupDiscovery object then propagates the news to all the DiscoveryListeners.

DiscoveryListener (interface)


Classes implement the DiscoveryListener interface when they want to know when lookup services become available and when they go away (discovered() and discarded() methods respectively).

Implementers must register their object with a LookupDiscovery object using addDiscoveryListener() to get the updates.

When a service goes away, the discarded() method is not immediately called because the LookupDiscovery object is not polling the service and does not know it has gone away. The discarded() method is only called when a service requester attempts to call the service and receives a RemoteException. Then by convention, the service requester is expected to call the discarded() method of its LookupDiscover object and it propagates the message to all the listeners.

DiscoveryEvent


This is the object that is passed to the DiscoveryListener methods when a new lookup service is discovered or when one goes away.

It only has one method, getRegistrars() which returns an array of ServiceRegistrar objects. Each ServiceRegistrar object is used to access a single lookup service.

Example


Since the LookupDiscovery object continues to look for lookup services long after it has been instantiated, this example includes a call to join() in the main() method to pause the example long enough to discover the reggie lookup service.

The next call in main() has very little practical value in this example but it serves as documentation for how to terminate the discovery activity of a LookupDiscovery object.

To exit this example, press ctrl-c.





Figure 1: LookupDiscoveryExample


Since there is only one lookup service active (reggie), there is only one lookup service discovered.

Run Instructions


To run this example:
  • Start Jini from the JiniExample1 directory using the r1.bat, r2.bat, and r3.bat files.
  • Recompile this example using the c.bat file to move the files into Jini's lib directory.
  • Then start the client from \java \nuggets \pages \examples \LookupDiscoveryExample \client-side (removing the spaces) using r.bat.



by Noel Enete . . . www.enete.com . . . noel@enete.com