what is the relay in RMI? [duplicate]
Asked Answered
A

1

-1

What is the relay in RMI ? I have been googling around for the call sequences but haven't got any satisfactory results. I am unable to understand the role of a stub on both client and server machine , what does RMI registery do after i start in the server machine ? When is the main server code like the following:

import java.net.*;
import java.rmi.*;

public class AddServer { // when is this code executed 
  public static void main(String args[]) {
    try {
      AddServerImpl addServerImpl = new AddServerImpl();
      Naming.rebind("AddServer",addServerImpl); // what is it doing ?
    } catch(Exception exc) {
        System.out.println("Exception : " + exc);
      }
  }
 }   

executed ?

What are the skeletons in RMI ?

I saw the following image image on wikipedia but can't understand how does it function and what is a stub and a skeleton and when is the interface implementation called ?

And who calls the remote method on the server machine which is actually called ?

Anthropophagi answered 21/12, 2011 at 6:2 Comment(1)
There is no 'relay' in RMI. The remainder of your question is a repost.Replica
A
0

I'm not really sure from your question what you know, and what you're unclear about.

Very simply:

1) RMI is a technology that allows different Java processes on a network communicate with each other.

2) Instead of explicitly sending network messages (for example, directly reading and writing sockets), RMI makes it makes it look like a standard method call to the RMI program.

RMI handles the details of packing the "method arguments" from the client and shipping them over the network, as well as the details of unpacking them at the receiving end so that the server can process them.

This all happens "under the covers", transparent to both the client and the server program.

3) The client side "under the covers" is the "stub"; the server side of "under the covers" is the client. The RMI registry simply lets the client "find" the server, and matches the right stub with the right skeleton.

4) The server's RMI runtime is always "listening" (for client requests), but individual server objects are only invoked as needed.

5) You cited a picture: but here's the complete explanation (including the picture):

http://en.wikipedia.org/wiki/Java_remote_method_invocation

6) If you still "don't get it", here's another link that might help:

http://docs.oracle.com/javase/tutorial/rmi/overview.html

--- ADDENDUM 12/21/2011 ---

Q: can you please explain skeleton

Q: when is the method Naming.rebind(...) invoked ?

Q: Also what does stub do on the server side ?

Quoting liberally from the Most Excellent Just Java 2, by Peter van der Linden

1) "RMI" (Remote Method Invocation) means that an object on one system can call a method in an object somewhere else on the system.

2) Your client object talks to a "stub". It looks like an object call to the client, but in fact the stub is responsible for getting the incoming arguments and transmitting them over to it's buddy on the server machine.

3) How does the client FIND it's buddy on the server machine? The client calls "java.rmi.Naming.Lookup()".

4) How does the server machine KNOW about your RMI server class? The Java server TOLD the registry by calling "java.rmi.Naming.bind()".

5) How does the server class know to get your client's remote invocation? There are several ways, but hopefully you simply made life easy for yourself by deriving your server class from java.rmi.server.UnicastRemoteObject.

6) What's a "skeleton"? It's the server-side analog of the client's "stub". It's just a bare bones routine that does nothing but unpack the data the client stub shipped over the network.

If it's still unclear, just type in an example and observe how it behaves.

Run it from a command line, and specify "java -Djava.rmi.server.logCalls=true..." in your server command line, to see the RMI calls that are being made.

'Hope that helps!

Allmon answered 21/12, 2011 at 6:17 Comment(2)
can you please explain skeleton and when is the method Naming.rebind(...) invoked ? Also what does stub do on the server side ?Anthropophagi
'The server side of "under the covers" is the client'?Replica

© 2022 - 2024 — McMap. All rights reserved.