Wednesday, December 5, 2007

RMI lookupds using 192.168.0.3 instead of localhost

When my Transporta was trying to connect to XCS for the session store bean, it was trying to connect to 192.168.0.3 (my ip address when connected to wireless at home). This was puzzling as I had set the java.naming.provider.url to localhost:1199. I event tried making it 127.0.0.1 thinking maybe there was a problem with the resolving of name localhost, or I thought maybe somewhere the lookup was being cached.

The problem was resolved by restarting XCS and is explained as follows: with RMI, the client asks uses java.naming.provider.url for a remote reference, the server responds with a server hostname and port to use to get that object. XCS was sending back its server hostname of 192.168.0.3, it hadn't updated itself since my ip changed.

From http://java.sun.com/j2se/1.4.2/docs/guide/rmi/faq.html#nethostname

For an RMI client to contact a remote RMI server, the client must first hold a reference to the server. The Naming.lookup method call is the most common mechanism by which clients initially obtain references to remote servers. Remote references may be obtained by other means, for example: all remote method calls can return remote references. This is what Naming.lookup does; it uses a well-known stub to make a remote method call to the rmiregistry, which sends back the remote reference to the object requested by the lookup method.

Every remote reference contains a server hostname and port number that allow clients to locate the VM that is serving a particular remote object. Once an RMI client has a remote reference, the client will use the hostname and port provided in the reference to open a socket connection to the remote server.

No comments: