Java:存根和骨架之间的区别 [英] Java: Difference between stub and skeleton

查看:26
本文介绍了Java:存根和骨架之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

存根和骨架有什么区别?据我所知,存根使用 java RMI 而骨架不使用.

解决方案

存根和骨架

<块引用>

RMI 使用标准机制(在 RPC 系统中使用)与远程对象进行通信:存根和骨架.远程对象的存根充当远程对象的客户端本地代表或代理.调用者调用本地存根上的一个方法,该存根负责对远程对象执行方法调用.在 RMI 中,远程对象的存根实现与远程对象实现的相同的远程接口集.


当调用存根的方法时,它会执行以下操作:

  • 启动与包含远程对象的远程 JVM 的连接,
  • 将参数编组(写入和传输)到远程 JVM,
  • 等待方法调用的结果,
  • 解组(读取)返回的返回值或异常,以及
  • 将值返回给调用者.
<块引用>

存根隐藏了参数的序列化和网络级通信,以便向调用者提供简单的调用机制.

在远程 JVM 中,每个远程对象可能有一个对应的骨架(在 Java 2 平台环境中,不需要骨架).

骨架负责将调用分派到实际的远程对象实现.


当骨架接收到传入的方法调用时,它会执行以下操作:

  • 解组(读取)远程方法的参数,
  • 调用实际远程对象实现上的方法,以及
  • 将结果(返回值或异常)编组(写入和传输)给调用者.
<块引用>

在 Java 2 SDK, Standard Edition, v1.2 中引入了一个额外的存根协议,它消除了在仅限 Java 2 平台的环境中对框架的需求.相反,通用代码用于执行 JDK1.1 中的骨架执行的职责.存根和骨架由 rmic 编译器生成.


参考:

What is the difference between stub and skeleton? As I know stub use java RMI and skeleton doesn't.

解决方案

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.


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.

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).

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.


Reference:

这篇关于Java:存根和骨架之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆