【问题标题】:RMI cannot find bound object?RMI 找不到绑定对象?
【发布时间】:2011-02-08 17:34:13
【问题描述】:

我有以下 RMI 服务器:

public static void main(String[] args) {
    try{
        ChatSystemImpl chatSystem = new ChatSystemImpl();
        ChatSystem chatSystem_stub = (ChatSystem) UnicastRemoteObject.exportObject(chatSystem, 6001);

        Registry registry = LocateRegistry.getRegistry("localhost", 6001);
        registry.bind("ChatSystem1", chatSystem_stub);

        System.out.println("Server up.");
    }
    catch(Exception ex){
        ex.printStackTrace();
    }
}

当我运行它时,我得到:

ava.rmi.NoSuchObjectException: no such object in table
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:377)
    at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
    at fr.inp.ensimag.examples.chatsystem.Main.main(Main.java:30)

好吧,我不知道出了什么问题……现在盯着它看了超过 2 个小时。

这是界面(如果需要):

public interface ChatSystem extends Remote{
    void registerUser(UserInfo newUser) throws RemoteException;
    void unregisterUser(UserInfo user) throws RemoteException;
    boolean userExists(UserInfo user) throws RemoteException;
    void send(MessageInfo message) throws RemoteException;
}

实现有以下标题,正文只包含没有真正实现的方法,它们只是UnsupportedOperationException

public class ChatSystemImpl implements ChatSystem

ChatSystem 接口在其他项目中,然后是其余的源代码(如果它有任何重要性)。

谢谢。

【问题讨论】:

    标签: java rmi remote-access


    【解决方案1】:

    您的注册表未导出。这通常意味着您通过 LocateRegistry.createRegistry() 在 JVM 中运行它,并且您已经让它成为垃圾收集器。该方法的结果应存储在静态变量中。这也可能意味着您从未启动过注册表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-06
      • 1970-01-01
      • 2014-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多