This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am new to RMI and was going through some sample code. I have a doubt here. The Naming.rebind() method makes the server object available to the registry. From client I can access using Naming.lookup(), am I accessing the object or the methods only? What is the service in this context - object or a method?
Also the Naming.lookup() takes only the registry hostname. How does it differentiate between various services offered by the server and also various objects created by the server?
The actual network connection is through TCP/IP. Is the connection on a per call basis or some session is maintained?
I think you're confusing some terms about "object" and "methods" - what you are accessing from the registry is the Stub of your server - it's an object, and through it you can access the remote methods that your server provides. A "service" is an object that provides a set of methods to a client - it's not exactly the same as your server object, because you can't get at non-remote methods, but it's still an object.
The registry differentiates between different services provided by using different names - Naming.lookup() takes more than just the hostname - it also takes the name of the service you are looking up. The name used in Naming.lookup() by the client must agree with the name used when calling Naming.bind() by the server.
I'm not completely sure if this is the answer you are looking for about the "per-call basis" - but each RMI method call creates a new TCP/IP connection - any sort of "session" information would be maintained by the server object itself, not anything in the protocol or provided inherently by any RMI internals. You can find a lot more information about RMI internals in this article if you're interested in digging deeper.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joined: Sep 26, 2005
Thank you for the clarification. Now I get "service" and "objects" straight. But my doubt regarding Naming.lookup() persists. I was going through the Java 2 documentation, the lookup() method takes only the URL as the argument. Still not clear how the various services provided by the same server are distinguished.
Just looked at the JavaDoc for Naming - it's confusing if you just look at the lookup() method by itself. Read the documentation at the top for the entire Naming class - it explains how the URL is used... the host:port part tells what registry you are using - the name part specifies a specific service running in that registry.
[NP - edited to disable smilies] [ November 03, 2005: Message edited by: Nathan Pruett ]