![]() | |
Chapter 2: TroubleShooting Jini
2.1. The Chapter that Shouldn't ExistJini is advertised as ``network plug and play''. This carries the idea of ``zero administration'' where you buy a device, switch it on and voila it is there and available. Well, this may happen in the future, but right now there are a number of back-room games that you have to succeed at. Once you have won at these, ``network plug and play'' does work, but if you lose at any stage then it can be all uphill! What is hard is issues of getting the right files in the right places with the right permissions. About 50% of the messages in the Jini mailing list are all about these configuration problems. These shouldn't occur, and that is why this is ``The Chapter that Shouldn't Exist''. This is the second chapter in this book, so right now you shouldn't have managed to fail at anything! Each of the early sections contains instructions on what to do to get the example programs working, and include step-by-step instructions. So skip on to the next chapters, but come back here when things go wrong. Your luck may vary: I got quite a reasonable way on my first attempts without problems, and some are even luckier. Some aren't... 2.2. Java PackagesTypical error:
Most of the code in this tutorial is organised into packages. To run
the examples the classes must be accessible from your class path. For
example, one of the programs in the
(Note the `.', not a `/'.)
In order to find this class, the classpath must be set correctly for
the Java runtime. If you have copied the zip file
If you have downloaded the source files, then they are all in subdirectories
such as
An alternative to setting the
2.3. Jini and Java VersionsThere are four versions of Jini: 1.0, 1.1, 1.2 and the new 2.0. The core classes are all the same. This version of the book will only deal with the new 2.0. Jini 2.0 requires JDK 1.4 or later, not earlier versions of Java. The changes for 2.0 are listed in the document "jini2_0/doc/release-notes/new.html" 2.4. Jini PackagesTypical error
The Jini class files are all in
The jar file
If the Java compiler or runtime can't find a class in one of
these packages then you need to make sure that the
jini-core.jar is in your classpath.
The jar file
If the Java compiler or runtime can't find a class in one of
these packages then you need to make sure that the
jini-ext.jar is in your classpath.
The jar file A compile or run of a Jini application will typically have an environment set something like
2.5. HTTP Server
The most likely cause is that you aren't running an HTTP server on the machine
that java.rmi.server.codebase is pointing to. Note that using
localhost is a common error since it may refer to a different
machine to the intended one.
2.6. Network ConfigurationA long-term aim in pervasive computing is to have zero configuration, whereby you can plug devices into a network and things "just work". Jini goes a long way towards making this possible at the service level, but the current implementation relies heavily on a functioning network layer: problems with misconfiguration of the network can cause lots of problems to Jini. Typical error
This error can occur by using the new configuration mechanism, where a service is exported
by Jeri using
This finds the localhost, gets its host name and IP address and listens on any
available port. I lost several days over this as the hostname on one machine was incorrectly
set, and the Java network layer (by InetAddress.getLocalHost()) was
unable to determine the IP address of localhost and returned "0.0.0.0" -
and nothing could connect to that address!
The solution was to correctly set the hostname on that machine. Then services could
be found and run on that machine. Alternatively, 2.7. Could not obtain preferred value for...Jini can't find a class file. Something is wrong with the classpath or the codebase. This can occur if the codebase points to a directory, and the value is not terminated with a "/" 2.8. Lookup ServiceTypical error
The command rmid starts the ``activation system'' running.
If this cannot start properly or dies just after starting, you will get
this message. Usually it is caused by incorrect file permissions.
2.9. RMI StubsTypical error
Many of the examples export services as remote RMI objects.
These objects are subclasses of
This will create a FileClassifierImpl_Stub.class in the
rmi subdirectory. The stub class file needs to be accessible
to the Java runtime in the same way as the original class file.
Another typical error is
This arises when an object is trying to get a remote reference to the
FileClassifierImpl, and it is trying to load the class file for the
stub from an HTTP server.
What makes this one particularly annoying is that it may not be referring
to the FileClassifierImpl_Stub at all! The class will often implement
a remote interface such as RemoteFileClassifier. This in turn implements
the common class FileClassifier as in Figure 2.1.
FileClassifier may be ``well known'', with a class
file on each client and server. However, an interface such as
RemoteFileClassifier as well as the implementation files for
FileClassifierImpl may only be known to a particular server.
The HTTP server must carry not only the
class files for the stubs, but the class files for all superclasses and interfaces
that are not available to all - in this case, for RemoteFileClassifier
as well as FileClassfier.
2.10. Garbage CollectionTypical error
If the service has been garbage collected then there will be no server listening
for connections to it, so any connection request will be refused.
This error is more likely to happen with Jini 2.0, where objects may be
garbage collected if there are no active references.
The solution is to ensure that an active reference is kept to the service.
The 2.11. DebuggingDebugging a Jini application is difficult because there are so many bits to it, and these bits are all running separately: the server for a service, the client, lookup services, remote activation daemons and HTTP servers. There are a few (not many) errors within the Jini objects themselves, but more importantly many of these objects are implemented using multiple threads and the flow of execution is not always clear. There are no magic ``debug'' flags that can be turned on to show what is happening.
On either the client or service side, a debugger such as
The don't give complete information, but they do give some, and can at least
tell you if the application parts are still living!
The logging APIU can also be used for debugging, and is considered in a later chapter. 2.12. LoggingThe logging API introduced in Jini 1.4 has been adopted by Jini 2.0. This can also be used for debugging, and is discussed in its own chapter. 2.13. CopyrightIf you found this chapter of value, the full book is available from APress or Amazon . There is a review of the book at Java Zone . The current edition of the book does not yet deal with Jini 2.0, but the next edition will.
|