简体   繁体   English

是否有相当于 CORBA IOR 的 Java RMI?

[英]Is there a Java RMI equivalent of a CORBA IOR?

CORBA has the nice feature that every reference to a remote object can be transformed into a string, the Interoperable Object Reference (IOR), that abstracts details like protocol, host, port, etc., needed to access the remove object. CORBA 有一个很好的特性,即对远程对象的每个引用都可以转换为字符串,即互操作对象引用 (IOR),它抽象了访问删除对象所需的协议、主机、端口等细节。 One can pass such IORs inside emails, files, databases, etc. and recreate the object stub inside a completely different process and it works.可以在电子邮件、文件、数据库等中传递此类 IOR,并在完全不同的进程中重新创建对象存根,并且它可以工作。

Is there an equivalent of an IOR in Java RMI? Java RMI 中是否有等效的 IOR?

No there isn't.不,没有。 An RMI remote reference is an opaque stub. RMI 远程引用是一个不透明的存根。 You can call toString() on it, and see all kinds of interesting stuff, but you can't do anything useful with the string.您可以对其调用 toString() ,并查看各种有趣的内容,但是您不能对字符串做任何有用的事情。

RMI protocol (the actual protocol is called JRMP, and RMI is an API that could use other protocols, but I'll use the term RMI for ease of communication) is based on Java serialization, and RMI remote references are transported as serialized objects just like other data transported over RMI. RMI 协议(实际协议称为 JRMP,RMI 是可以使用其他协议的 API,但为了便于通信,我将使用术语 RMI)基于 Java 序列化,并且 RMI 远程引用作为序列化对象传输就像其他通过 RMI 传输的数据一样。 Java serialization format itself is specified , so it can be used across different JVM implementations. Java 序列化格式本身是指定的,因此它可以跨不同的 JVM 实现使用。

So an RMI equivalent of a CORBA IOR is a serialized representation of an RMI remote reference.因此,相当于 CORBA IOR 的 RMI 是 RMI 远程引用的序列化表示。 It is not a strict equivalent since CORBA IOR has textual representation, but one can introduce a binary to textual encoding, like Base64.它不是严格的等价物,因为 CORBA IOR 具有文本表示,但可以将二进制引入文本编码,如 Base64。

An example where this is used is JMX.使用它的一个示例是 JMX。 JMX can work over different protocols, including RMI and IIOP, and defines an URL format that, apart from supporting regular access via naming server, can also support direct access without naming server. JMX 可以工作在不同的协议上,包括 RMI 和 IIOP,并定义了一种 URL 格式,除了支持通过命名服务器进行常规访问外,还可以支持不使用命名服务器的直接访问。 Here is how this URL looks like for RMI and for IIOP:下面是这个 URL 在 RMI 和 IIOP 中的样子:

// JRMP encoded form
service:jmx:rmi://localhost/stub/rO0ABXNyAC5qYXZheC5tYW5hZ2VtZW50LnJlbW90ZS5ybWkuUk1JU2VydmVySW1wbF9TdHViAAAAAAAAAAICAAB4cgAaamF2YS5ybWkuc2VydmVyLlJlbW90ZVN0dWLp/tzJi+FlGgIAAHhyABxqYXZhLnJtaS5zZXJ2ZXIuUmVtb3RlT2JqZWN002G0kQxhMx4DAAB4cHc5AAtVbmljYXN0UmVmMgAADjE2LjE5Mi4xMjAuMTI5AAANcQAAAAAAAAAIAOgIQgAAAPlXjcJugAEAeA==

// IIOP encoded form
service:jmx:iiop://localhost/ior/IOR:000000000000003b524d493a6a617661782e6d616e6167656d656e742e72656d6f74652e726d692e524d495365727665723a303030303030303030303030303030300000000000010000000000000068000102000000000f31362e3139322e3132302e31323900000d93000000000019afabcb0000000002578f08b80000000800000000000000000a0000000000000100000001000000200000000000010001000000020501000100010020000101090000000100010100

Here is an example how it can be used.这是一个如何使用它的示例。 It this example we are starting an RMI based JMX server and getting its encoded RMI reference that we then decode and deserialize.在这个例子中,我们启动了一个基于 RMI 的 JMX 服务器并获取其编码的 RMI 引用,然后我们对其进行解码和反序列化。 (This is done just for demonstration, JMX client does all that automatically.) (这只是为了演示,JMX 客户端会自动完成所有这些。)

import sun.management.jmxremote.ConnectorBootstrap;

import javax.management.remote.JMXConnectorServer;
import javax.management.remote.rmi.RMIServer;
import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.util.Base64;

public class Console1 {
    public static void main(String[] args) throws Exception {
        JMXConnectorServer jmxConnectorServer = ConnectorBootstrap.startLocalConnectorServer();
        String encodedJmxRmiReference = jmxConnectorServer.getAddress().getURLPath().substring("/stub/".length());
        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(Base64.getDecoder().decode(encodedJmxRmiReference)));
        RMIServer jmxRmiReference = (RMIServer) in.readObject();
        System.out.println(jmxRmiReference.getVersion());
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM