Many developers find themselves struggling to get a JINI service available within the lookup service. There are a number of common problems which I will present in this article. I will then describe an approach which you can use to determine exactly which problem you're facing. Hopefully, this information will allow you to locate the issue and fix it.
There are several reasons a service may fail to register with a lookup service:
Reggie being separated by a firewall that isn't passing multicast or perhaps because multicast isn't enabled on either the machine running Reggie or the machine running the service.Reggie codebase containing a hostname which is not resolvable by the machine attempting to register its service.Reggie is blocked in some fashion.These problems can also prevent a client locating a Reggie instance causing a service lookup to fail. Assuming the client has located the Reggie instance there is one further problem which can occur:
Reggie has an incorrectly specified codebase, typically with an unresolvable hostname or an incorrect path.Two other things that can cause lookup to fail:
The client side codebase problem is relatively easy to eliminate. We need to test the validity of the URL's the client must download code from. For this, all that's required is a browser installed on the client machine. For each codebase URL (there should be one string of URL's for Reggie and one for the service) - type it into the browser and verify that URL is valid. In the case of .jar's you should be able to download the .jar. In the case of a directory, you should be able to view the directory hierarchy containing your .class's.
Failure to resolve any of these URL's points to a hostname resolution or incorrect path. If you can ping the hostname, chances are you have an incorrect path specified in the service.
Unlike client-side codebase problems, service-side codebase problems occur only when the Reggie codebase is unresolvable by the service attempting to register. Note that if the service itself has an incorrect codebase, this will only manifest itself at client lookup time. Reggie doesn't access/use a service's codebase.
You should check the Reggie codebase in the same way as you would for the client-side issues, using a browser.
Before going on to check for multicast problems (see below), you need to ensure that your client/service groups intersect with those defined for your Reggie instance. This should be relatively easy to do - simply check the relevant configuration files. Alternatively, configure your client/service and Reggie to join all groups which can be achieved by passing in or configuring DiscoveryGroupManagement.ALL_GROUPS. If registration/lookup still fails, first ensure that your codebases are valid and only then investigate the possibility of multicast issues.
Multicast network issues will prevent group-based discovery methods from functioning correctly. To determine if this is the issue, configure your client or service to use a LookupLocator rather than group registration. If service registration or client lookup functions correctly, the problem is related to multicast. Check that:
Reggie machine has multicast enabled.The various services in the JINI starter kit determine the default IP address/hostname embedded in the proxy using something like...
InetAddress.getLocalHost();
... from which the hostname is extracted. Reggie also uses the above for such things as it's advertisements. If the resulting hostname is not resolvable via DNS, the local hosts file or some other mechanism, one will encounter connectivity and lookup issues.
The solution is either to configure the chosen service to use IP addresses (via configuration variables in it's .config file or to ensure the hostname is resolvable. In the case of the services in the JINI starter kit, the JavaDoc provides the necessary detail.
Dynamic discovery of lookup services and the services they contain is asynchronous by nature and can cause problems for client programmers. Particular attention should be paid to the fact that many of the lookup methods are non-blocking and can fail to return a matching service simply because the infrastructure hadn't been running for long enough to receive advertisements from available lookup services.
In these cases, programmers should either switch to using blocking methods (which often accept a wait duration) or make use of a ServiceDiscoveryListener which can be used to trigger client operations once a suitable service has been discovered asynchronously.
A list of tools and their uses:
ServiceDiscoveryManager and JoinManager produce significant logging information in respect of their actions which can be exceedingly useful for debugging. See Appendix A for suggestions on use/configuration.Enabling logging in client or service is achieved by adding this to the JVM command-line:
-Djava.util.logging.config.file=logging.properties
logging.properties should look something like this:
handlers= java.util.logging.ConsoleHandler .level=ALL # Limit the message that are printed on the console to INFO and above. java.util.logging.ConsoleHandler.level = FINEST java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter ############################################################ # Facility specific properties. # Provides extra control for each logger. ############################################################ # For example, set the com.xyz.foo logger to only log SEVERE # messages: #net.jini.loader.pref.PreferredClassProvider.level = ALL #net.jini.jeri.tcp.client.level = FINEST #net.jini.jeri.BasicInvocationHandler.level = FINEST #net.jini.jeri.connection.ConnectionManager.level = FINEST #net.jini.lookup.ServiceDiscoveryManager.level = FINEST net.jini.lookup.JoinManager = FINEST
The additional commented-out levels may also be useful under some circumstances (see the JINI JavaDoc for more information on these).
There are two basic varieties of codebase URL. The first references in a .jar (for example http://dredd:8080/reggie-dl.jar whilst the second references a tree of .class files arranged in a directory structure to match their packages.
It is this second form that needs a little attention. For whatever reason, the specific structure of this kind of codebase specification is very important. You must ensure that you terminate the URL with a "/" so this...
http://dredd/myclasses/
...is correct whilst this will likely result in code-downloading problems...
http://dredd/myclasses
© Copyright 2005 Dan Creswell