问题描述
RMI 中的中继是什么?我一直在搜寻通话顺序,但没有得到令人满意的结果.我无法理解客户端计算机和服务器计算机上 stub 的作用,在服务器计算机中启动 RMI registery 会做什么? 主服务器代码如下所示:
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);
}
}
}
已执行?
RMI中的骨架是什么?
我看到了下图图像在Wikipedia上,但无法理解它的功能以及什么是存根和框架以及何时将接口实现称为?
谁在服务器计算机上调用了实际上称为远程方法的远程方法?
从您的问题中我不能确定您知道什么以及不清楚的地方.
非常简单:
1)RMI是一种允许网络上的不同Java进程相互通信的技术.
2)RMI使它看起来像是对RMI程序的标准方法调用,而不是显式发送网络消息(例如,直接读取和写入套接字).
RMI处理从客户端打包方法参数"并通过网络传送它们的详细信息,以及在接收端解压缩它们的详细信息,以便服务器可以对其进行处理.
这一切都是在幕后"进行的,对客户端和服务器程序都是透明的.
3)客户端在幕后"是存根"; 幕后"的服务器端是客户端. RMI注册表仅允许客户端查找"服务器,然后将正确的存根与正确的框架进行匹配.
4)服务器的RMI运行时总是侦听"(针对客户端请求),但是仅根据需要调用单个服务器对象.
5)您引用了一张图片:但这是完整的说明(包括图片):
http://en.wikipedia.org/wiki/Java_remote_method_invocation
6)如果您仍然不理解",这是另一个可能会有所帮助的链接:
http://docs.oracle.com/javase/tutorial/rmi/overview.html
---附录12/21/2011 ---
自由引用最优秀的 Just Java 2 ,彼得·范德·林登(Peter van der Linden)
1)"RMI"(远程方法调用)表示一个系统上的对象可以在该系统其他位置的对象中调用方法.
2)您的客户端对象与存根"对话.看起来像是对客户端的对象调用,但实际上,存根负责获取传入的参数并将其传递给服务器计算机上的好友.
3)客户端 Find 是如何在服务器计算机上成为好友的?客户端调用"java.rmi.Naming.Lookup()".
4)服务器如何了解您的RMI服务器类? Java服务器通过调用"java.rmi.Naming.bind()"来 注册表.
5)服务器类如何知道如何获取客户端的远程调用?有几种方法,但是希望您可以通过从java.rmi.server.UnicastRemoteObject派生服务器类来简化生活.
6)什么是骨架"?它是客户端存根"的服务器端模拟.这只是一个简单的例程,除了解压缩客户端存根通过网络传送的数据外,什么也不做.
如果仍然不清楚,只需键入一个示例并观察其行为即可.
从命令行运行它,然后在服务器命令行中指定"java -Djava.rmi.server.logCalls = true ...",以查看正在进行的RMI调用.
'希望有帮助!
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 imageimageon 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 ?
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 ---
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!
这篇关于RMI中的中继是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!