Java:存根和骨架之间的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22115195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java: Difference between stub and skeleton
提问by Gigal
What is the difference between stub and skeleton? As I know stub use java RMI and skeleton doesn't.
存根和骨架有什么区别?据我所知,存根使用 java RMI 而骨架不使用。
采纳答案by Ramesh Rajendran
Stubs and Skeletons
存根和骨架
RMI uses a standard mechanism (employed in RPC systems) for communicating with remote objects: stubs and skeletons. A stub for a remote object acts as a client's local representative or proxy for the remote object. The caller invokes a method on the local stub which is responsible for carrying out the method call on the remote object. In RMI, a stub for a remote object implements the same set of remote interfaces that a remote object implements.
RMI 使用标准机制(在 RPC 系统中使用)与远程对象进行通信:存根和骨架。远程对象的存根充当远程对象的客户端本地代表或代理。调用者调用本地存根上的一个方法,该存根负责对远程对象执行方法调用。在 RMI 中,远程对象的存根实现与远程对象实现的相同的远程接口集。
When a stub's method is invoked, it does the following:
当调用存根的方法时,它会执行以下操作:
- initiates a connection with the remote JVM containing the remote object,
- marshals (writes and transmits) the parameters to the remote JVM,
- waits for the result of the method invocation,
- unmarshals (reads) the return value or exception returned, and
- returns the value to the caller.
- 启动与包含远程对象的远程 JVM 的连接,
- 将参数编组(写入和传输)到远程 JVM,
- 等待方法调用的结果,
- 解组(读取)返回的返回值或异常,以及
- 将值返回给调用者。
The stub hides the serialization of parameters and the network-level communication in order to present a simple invocation mechanism to the caller.
In the remote JVM, each remote object may have a corresponding skeleton (in Java 2 platform-only environments, skeletons are not required).
存根隐藏了参数的序列化和网络级通信,以便向调用者提供简单的调用机制。
在远程 JVM 中,每个远程对象可能有一个对应的骨架(在 Java 2 平台环境中,不需要骨架)。
The skeleton is responsible for dispatching the call to the actual remote object implementation.
骨架负责将调用分派到实际的远程对象实现。
When a skeleton receives an incoming method invocation it does the following:
当骨架收到传入的方法调用时,它会执行以下操作:
- unmarshals (reads) the parameters for the remote method,
- invokes the method on the actual remote object implementation, and
- marshals (writes and transmits) the result (return value or exception) to the caller.
- 解组(读取)远程方法的参数,
- 调用实际远程对象实现上的方法,以及
- 将结果(返回值或异常)编组(写入和传输)给调用者。
In the Java 2 SDK, Standard Edition, v1.2 an additional stub protocol was introduced that eliminates the need for skeletons in Java 2 platform-only environments. Instead, generic code is used to carry out the duties performed by skeletons in JDK1.1. Stubs and skeletons are generated by the rmic compiler.
在 Java 2 SDK, Standard Edition, v1.2 中引入了一个额外的存根协议,它消除了在仅限 Java 2 平台的环境中对框架的需求。相反,通用代码用于执行 JDK1.1 中的骨架执行的职责。存根和骨架由 rmic 编译器生成。