Accessing remote object after unbind
I'm working on a server, multi-client application where I want the client to throw an exception whenever the client cannot reach the server. I thought the cases where this may occur were the following:
-- The RMI registry is no longer running on the server machine.
-- The server object is no longer present (has become null)
-- The server object has been removed from the RMI registry through Naming.unbind().
The final case has caused me the most fits during testing. I've noticed that if a client has a remote reference to the server object, the client can still make method calls on it even if the server object no longer exists within the RMI registry.
One fix would be to have the client obtain a remote reference to the server object before any remote method call; receiving a NotBoundException if the server object has been removed from the registry.
Yet is there another way that a client can notice if the server object no longer exists within RMI registry?
Thanks.
[1030 byte] By [
jhwhetza] at [2007-10-3 2:57:57]

> -- The RMI registry is no longer running on the
> server machine.
> -- The server object is no longer present (has become
> null)
This can't happen. Naming.lookup() never return null, they throw NotBoundException instead (even if someone at the server deliberately binds null).
> -- The server object has been removed from the RMI
> registry through Naming.unbind().
There is at least one more more case you need to consider:
-- the remote object has been unexported but left in the Registry (or the client still has a reference from before): this will cause a NoSuchObjectException.
> The final case has caused me the most fits during
> testing. I've noticed that if a client has a remote
> reference to the server object, the client can still
> make method calls on it even if the server object no
> longer exists within the RMI registry.
I'm not clear about your objective here. This can certainly happen but if you're just trying to enumerate the possible exceptions this isn't even an exception.
ejpa at 2007-7-14 20:47:19 >

Thanks ejp!
The problem with my final case was that I didn't know the difference between unbinding and unexporting remote objects. I thought that was an object had been unbound via the Naming.unbind() call, all previous refererences could no longer contact the remote object. Instead, it appears that if one unbinds a remote object, then any entity trying to obtain a new reference will get a NotBoundException while previous references will function normally.
The case that I was really shooting for was the case you mentioned in the reply. I was able to replicate that case by replacing my Naming.unbind() call with UnicastRemoteObject.unexportObject().
Again, thanks again for your help with the nuisances of RMI.