my dog learned polymorphism*
The moose likes Distributed Java and the fly likes Service is a method or an object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Service is a method or an object?" Watch "Service is a method or an object?" New topic
Author

Service is a method or an object?

naveen chinthakunta
Greenhorn

Joined: Sep 26, 2005
Posts: 16
Hi all,

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?

Would be grateful to get responses.

Thanks n Regards,
navEEn
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
naveen chinthakunta
Greenhorn

Joined: Sep 26, 2005
Posts: 16
Hi,

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.

Thanks in advance.
navEEn
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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 ]
 
wood burning stoves
 
subject: Service is a method or an object?
 
Similar Threads
NX: RMI check available port or host number
Object that is Serializable and remote
Tomcat application connection problem with RMI
shut down rmiregistry
RemoteData Stub Error...