JINI services are not located by address, rather they are located by searching for a particular type of service such as Printer, ServiceRegistrar, JavaSpace or TransactionManager. Thus a "server" wishing to offer JINI client's a service ensures that it's proxy/stub implements the appropriate interface.
Of course, given that we search for services by type, it's entirely possible that a single lookup will return more than one matching service (though we can just ask for one match) which provides us with some basic functionality for implementing load-balancing or failover.
[JINI services are identified uniquely by their ServiceID but these are wholly inadequate for locating and identifying services as they can change over time due to failure etc.]
We're going to look at three different methods of performing lookup, starting with a very simple, static example and finishing with a fully dynamic version. All the examples search for a JavaSpace instance but you can change that should you wish.
[All examples rely on DiscoveryUtil.java]
LookupWithLocator makes use of a LookupLocator (which can accept a URL of the form jini://host:port/ or a hostname/port combination) to contact a LookupService (LUS). This is the simplest way to perform a lookup but requires us to know beforehand the name (or IP address) and port of the LUS we wish to contact - not very dynamic!
LookupWithDiscovery improves on LookupWithLocator by supporting fully dynamic LUS discovery which removes the need for prior knowledge of address information. However, there's still a problem because, when a LUS is found it is only searched once for appropriate service matches. New service instances may be registered with an LUS at any time, so it's possible LookupWithDiscovery will "miss" a potential service match because it's already checked the LUS in question and the service wasn't registered at that time.
The ultimate solution to the lookup problem comes in the form of LookupWithSDM which uses ServiceDiscoveryManager:
Thus, LookupWithSDM, unlike LookupWithDiscovery, will not "miss" newly registered services.
Having obtained a proxy for a service, you will need to perform proxy verification. Some details to get you started on this can be found here.
You can download all the source code together with compiled classes and example command-lines here.
© Copyright 2003 Dan Creswell