Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How does the RMI Registry work?

 
Sean Keane
Ranch Hand
Posts: 582
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am just getting into RMI and I've a very basic question I was wondering if anyone could help me out with?

The setup that I have at the moment for testing my sample RMI programs is as follows:

1. Start rmiregistry on my localhost (ensuring class files are not available on CLASSPATH or current directory).
2. Start my webserver to dynamically deliver class files
3. Start my server
4. Start my client


Question One:

Now, my question is, how does the server know where the rmiregistry is located in order to communicate with it?

My server code has something like:

If I am understanding this right, then when I call rebind, then it is communicating with the rmiregistry process that is running on my localhost in order to store the mapping of "my_object" to "myObject".

Then in my client I have something like this:

So I can understand how the client would be able to access the rmiregistry, as I have provided it with a URL. Where the URL is telling the lookup method that my RMI registry is running on my localhost.

But how does the server code know where the rmiregistry is running when I executed namingContext.rebind("rmi:my_object", myObject) ?



Question Two:

Now, when my client communicates with the rmiregistry, how does the rmiregistry know where the class files are?

I start the server with this command here:

java -Djava.rmi.server.codebase=http://localhost:8080/ Server

I'm assuming that the JVM argument java.rmi.server.codebase is setting the location that the rmiregistry process should search for the class files. But the rmiregistry process could be running on a separate machine? It is definitely running in a different JVM. So how does setting the JVM argument when starting my Server actually tell the rmiregistry process where to look?


Cheers,

Sean
 
Sean Keane
Ranch Hand
Posts: 582
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question One:

When I look at the JavaDoc for the rebind method on the InitialContext it doesn't have very much info about how this is working in the background. But the general description of the class contains this:

When a URL string (a String of the form scheme_id:rest_of_name) is passed as a name parameter to any method, a URL context factory for handling that scheme is located and used to resolve the URL. If no such factory is found, the initial context specified by "java.naming.factory.initial" is used. Similarly, when a CompositeName object whose first component is a URL string is passed as a name parameter to any method, a URL context factory is located and used to resolve the first name component. See NamingManager.getURLContext() for a description of how URL context factories are located.


This doesn't make any sense to me. But is this describing how the rmiregistry process is found? I haven't created a URL context factory nor have I set java.naming.factory.initial - confused!!!

The comment "See NamingManager.getURLContext() for a description of how URL context factories are located. " has led me to NamingManager, but I can't find anything useful there either that explains to me how this is working.

Any ideas folks?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic