> * Is there a clean way to shutdown a registry created locally in the
> server code?
Yes. Unexport it. Make sure you keep the Registry reference returned by
LocateRegistry.createRegistry, then you can just pass that to
UnicastRemoteObject.unexportObject().
> * Why does rmiregistry need to have access to the class definitions of
> the interfaces?
Because it receives the stub via an RMI call. That means that it has to
be able to deserialize the stub, and to deserialize the stub it needs
the remote interfaces, and the closure of any other application classes
the remote interface depends on.
> I as understand it, the rmiregistry simply should register the name
> "hello" for the server and resolve the name "hello" as a reference to
> something on the server for the client.
It doesn't do that. It resolves the name as a remote stub which it is
holding in its own JVM space (in a Map<String, Remote>). The stub in
turn contains stuff that refers to the remote server object, i.e. its
{IP, port}, its objectID.
Christian Hvid - 14 Aug 2007 13:34 GMT
On Aug 14, 3:07 am, Esmond Pitt <esmond.p...@nospam.bigpond.com>
wrote:
> > * Is there a clean way to shutdown a registry created locally in the
> > server code?
>
> Yes. Unexport it. Make sure you keep the Registry reference returned by
> LocateRegistry.createRegistry, then you can just pass that to
> UnicastRemoteObject.unexportObject().
I did a bit of experimenting - this does not work:
private static Registry registry;
...
registry = LocateRegistry.createRegistry(2001);
...
public void shutdown() throws RemoteException {
UnicastRemoteObject.unexportObject(registry, true);
}
But this did:
public void shutdown() throws RemoteException {
UnicastRemoteObject.unexportObject(this, true);
}
Maybe that was what you meant?
Anyway; what are good (simple) design practices for a basic RMI
application like this?
Is creating the registry as in the example ok or is there some other
approach I should look at?
Esmond Pitt - 15 Aug 2007 02:51 GMT
> Maybe that was what you meant?
No, it isn't what I meant. The former does indeed work subject to what I
said: 'registry' must be the value returned by
LocateRegistry.createRegistry() (because that is the actual Registry
remote object). If it has subsequently become the value returned by
LocateRegistry.getRegistry() it won't work (because that is a Registry
stub).
> Is creating the registry as in the example ok or is there some other
> approach I should look at?
I prefer creating the Registry inside the server JVM if possible: that
way you avoid a number of headaches such as the shutdown problem and the
Registry classpath problem.