CodyBugstein
CodyBugstein

Reputation: 23322

RMI Server vs. RMI Registry

On Oracle's FAQ page about Java RMI, it says:

While the Java Remote Method Invocation (Java RMI) server can theoretically be on any host, it is usually the same host as that on which the registry is running, and on a different port. Even if the server is mistaken about its hostname or IP address (or has a hostname that simply isn't resolvable by clients), it will still export all of its objects using that mistaken hostname, but you will see an exception every time you try to receive one of those objects.

I don't understand the difference between the RMI Server and the RMI Registry. I thought they were the same thing. How can the RMI Registry work if it wasn't a server of some sorts?

Upvotes: 3

Views: 7467

Answers (3)

user207421
user207421

Reputation: 310919

From the RMI Specification #2.4.3:

RMI server functions are provided by java.rmi.server.RemoteObject and its subclasses, java.rmi.server.RemoteServer and java.rmi.server.UnicastRemoteObject and java.rmi.activation.Activatable.

I believe that the terminology is confused and unnecessary. All this means is that every remote object is a server. It is best just to think of remote objects. The term 'the RMI server' appears exactly twice in the RMI Specification, and both times it is clearly referring to a remote object.

The Registry is a remote object as well. You acquire remote objects as return values of remote methods. The Registry solves the bootstrap problem of how do you get started.

In contrast to this, the Oracle FAQ you cited seems to be using the term 'RMI server' as a kind of program that 'hosts' remote objects: but there is no necessity for such a program to even exist. Many if not most remote objects just 'host' themselves. Describing such a program as a server is just a misuse of terminology.

How can the RMI Registry work if it wasn't a server of some sorts?

It is a remote object.

Upvotes: 0

hagrawal7777
hagrawal7777

Reputation: 14658

What is RMI registry:

RMI registry is a service where remote objects are registered and registered remote objects are looked up by RMI clients. If you want your object to be remotely accessible (could be many reason like you keep on updating the logic and not feasible to ship to the implementation each time, so allow remote invocation through RMI) then register it in a RMI registry and then a RMI client will look up the remote object (using remote reference of the object) and then can invoke the methods on the remote object.

Below is definition of registry from Oracle Javadoc

A registry is a remote object that maps names to remote objects. A server registers its remote objects with the registry so that they can be looked up. When an object wants to invoke a method on a remote object, it must first lookup the remote object using its name. The registry returns to the calling object a reference to the remote object, using which a remote method can be invoked.

What is RMI server:

RMI server is that actual server where the JVM is running and the object (remote object) is living. RMI client ultimately wants this object.

As per your concern, yes this server (RMI server) could be different from the server where RMI registry is running. And you could understand why! I could register object from different servers in same RMI registry and I can have that registry running on a totally different server. Please read more below for more explanation on this.

How do Java RMI clients contact remote Java RMI servers?

For an Java RMI client to contact a remote Java RMI server, the client must first hold a reference to the server (this is where RMI registry is coming into picture, to give you reference to the RMI server). The Naming.lookup method call is the most common mechanism by which clients initially obtain references to remote servers.

Every remote reference contains a server hostname and port number that allow clients to locate the VM that is serving a particular remote object (this is where RMI server is coming into picture). Once a Java 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.

Please do read this from same Oracle FAQs.

You can very well connect with the RMI registry but you may not be able to get the remote object and that's when people report java.net.UnknownHostException, which means that RMI registry is able to give the reference of remote object BUT RMI server which is actually hosting the remote object or running the JVM where object is living, is not found or client is not able to connect.

So, RMI registry and RMI server are 2 different things.

An analogy could be that HTTP server is used to provide access to HTTP resources (hyper text documents) which are available on a server. However, typically hypertext docs will be on same physical box as HTTP server but RMI registry can provide access to reference of remote objects which are on different server (RMI server).

Upvotes: 6

John Bollinger
John Bollinger

Reputation: 180276

An RMI server is a program that hosts remote objects. An RMI registry is a separate program that binds remote object names to instances. An RMI server makes remote objects accessible to clients by registering them in the registry; clients then obtain access via that same registry. An RMI registry is a lowercase-'s' "server", but it is not, ordinarily, an "RMI Server".

The relationship between an RMI server and RMI registry is analogous to the relationship between a web server and a DNS server that is authoritative for it.

Perhaps Oracle's getting started guide explains a bit better than does the FAQ.

Upvotes: 2

Related Questions