【问题标题】:How to pass the remote reference of an exported RMI-IIOP object如何传递导出的 RMI-IIOP 对象的远程引用
【发布时间】:2015-02-22 15:13:49
【问题描述】:

假设我想将以下 RMI-IIOP 导出对象的远程引用传递给接收器(这是另一个远程对象):

public interface MyInterface extends Remote
{
    public void send(Receiver receiver);

    public String sayHello();

}

public class MyObject implements MyInterface
{
    public MyObject()
    {
        PortableRemoteObject.exportObject(this); // I know I could extend PortableRemoteObject instead
    }

    public void send(Receiver receiver)
    {
        // which one is correct?

        /* 1. */ receiver.receive(this);
        /* 2. */ receiver.receive(this.toStub());
        /* 3. */ // other things, such as narrow...
    }

    public String sayHello() { return "hello"; }
}

这是接收方法的实现:

public void receive(Remote remote)
{
    MyInterface myObjectRef = (MyInterface) PortableRemoteObject.narrow(remote, MyInterface.class);
    System.out.println(myObjectRef.sayHello());
}

目标是 sayHello() 方法的正确远程调用。

谢谢。

【问题讨论】:

    标签: java rmi iiop


    【解决方案1】:

    它们是等价的。 RMI 的语义规定导出的远程对象作为它们自己的存根传递。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-29
      • 1970-01-01
      • 2013-07-06
      相关资源
      最近更新 更多