Java Reference
In-Depth Information
• The
IxcRegistry
cannot obtain an instance for the
XletContext
. This should never
happen, but if it does, the resulting
registry
will be
null
.
• Another Xlet has already bound a remote object to the name
XletLocationProducer.
Location
. That might happen if the Xlet is running in more than one context, or if
another Xlet uses the same name for something it wants to remote.
• The
IxcRegistry
fails to create a stub for the remoted class.
Of these failures, the most likely is a
StubException
, which can happen if you don't
implement your remote class correctly. To implement your remote class correctly, you
must ensure that
• The class implement
java.rmi.Remote
• Each remote object method declare
java.rmi.RemoteException
in its
throws
clause
• The type of each remote object method only accept and return primitive Java types
(including, of course,
void
) or those classes that extend
java.io.Serializable
These restrictions make sense when you think about them, because the IXC mecha-
nism must have a way to know that a remote object is remotable, can handle exceptions
encountered during the remote execution, and can pass objects from one Java class
loader to another during remote execution.
On the Xlet's exit, the Xlet unregisters the object from the
IxcRegistry
using
unbindAll
. This, too, can fail, but there's little the Xlet can do about these failures at exit
time, so the Xlet just logs the failures for debugging purposes. It's not strictly necessary
that the Xlet do this—the runtime will take care of it if it doesn't—but it's good practice.
■
Tip
When your Xlet exits, use
unbindAll
at this point rather than invoke
unbind
for each named object,
so that if you add additional objects to the registry, you won't need to add matching
unbind
requests.
Using a Shared Object
At any point, an Xlet can query the
IxcRegistry
for a remoted object by name using the
well-known name another Xlet used to register the object. Listing 9-9 shows a hypotheti-
cal consumer Xlet that uses the
Location
object shared by the
XletLocationProducer
.