gpt4 book ai didi

RMI 绑定(bind)问题(从 Windows RMI 服务器到 Ubuntu RMI 注册表)

转载 作者:行者123 更新时间:2023-12-01 06:21:18 29 4
gpt4 key购买 nike

我有一个 RMI 服务器,当在本地主机上运行时,它可以正确绑定(bind)到 RMI 注册表(以证明设置正确)。执行此操作的代码是:

 private void exposeTickHistoryRemoteProvider(TickHistoryRemoteInterface aTickHistoryServer) {
if (System.getSecurityManager() == null) {
SecurityManager mySecurityManager = getSecurityManager();
System.setSecurityManager(mySecurityManager);
}
String rmiServerHostname = System.getProperties().getProperty("java.rmi.server.hostname");
try {
TickHistoryRemoteInterface stub =
(TickHistoryRemoteInterface) UnicastRemoteObject.exportObject(aTickHistoryServer, 0);
Registry registry = LocateRegistry.getRegistry(rmiServerHostname);
String[] services = registry.list();
registry.rebind(RMI_SERVICENAME_REUTERS_TICKHISTORY_SERVER, stub);
log.info(RMI_SERVICENAME_REUTERS_TICKHISTORY_SERVER + " bound");
} catch (Exception e) {
log.error(RMI_SERVICENAME_REUTERS_TICKHISTORY_SERVER + " exception:" + e.toString());
e.printStackTrace();
}
}

我的本​​地主机正在运行带有以下 Java 版本的 Windows:

C:\eclipse>java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode)

现在,我的问题是我想绑定(bind)到在另一台计算机上运行的 RMIRegistry(运行 Ubuntu 10.04,使用 OpenJDK IcedTea6 1.8.1,java 版本 1.6.0_18)。

在这台 Ubuntu 机器上,我的 CLASSPATH 中没有任何内容(echo $CLASSPATH),并且正在运行 OpenJDK RMIRegistry(与 Ubuntu 捆绑的相反):

sudo /usr/lib/jvm/java-6-openjdk/jre/bin/rmiregistry &

现在,在上面的代码中,当变量 rmiServerHostname 为“localhost”且 RMIRegistry 在我的 Windows 本地主机上运行时,代码可以正常工作(RMI 服务器代码绑定(bind)到 RMI 注册表)。但是,当 rmiServerHostname 是我的远程 Ubuntu 计算机(“deity”)时,我在“重新绑定(bind)”调用时抛出以下异常:

 java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: com.relative.tickhistory.provider.TickHistoryRemoteInterface
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: com.relative.tickhistory.provider.TickHistoryRemoteInterface

如果我终止 RMIRegistry,我会收到不同的错误消息(我希望如此):

 java.rmi.ConnectException: Connection refused to host: deity; nested exception is: 
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.list(Unknown Source)

我假设 RMIRegistry 的这些实现(Windows Java6 和 Ubuntu OpenJDK 6)之间没有不兼容性...但是,我不确定如何深入了解这一点。特别是因为我知道代码可以正常工作(在第一个 Windows/localhost 示例中)。

<小时/>

到目前为止的进展

非常感谢您的有用回复。我知道我在 rmiServerHostname (在我的本地主机上运行)和 rmiRegistryHostname (在“deity”上运行)之间感到困惑。我已经修改了代码,如下所示,但仍然遇到同样的问题(请注意“Registryregistry = LocateRegistry.getRegistry(rmiRegistryHostname)”行中的更改):

    String rmiServerCodebase = System.getProperties().getProperty("java.rmi.server.codebase");
String rmiServerHostname = System.getProperties().getProperty("java.rmi.server.hostname");
String rmiRegistryHostname = "deity";
System.out.println("rmiServerCodebase=" + rmiServerCodebase + "; rmiServerHostname=" + rmiServerHostname);
try {
TickHistoryRemoteInterface stub =
(TickHistoryRemoteInterface) UnicastRemoteObject.exportObject(aTickHistoryServer, 0);
Registry registry = LocateRegistry.getRegistry(rmiRegistryHostname);

打印语句的输出是(注意,我的本地主机是“RTPC-16”)

"rmiServerCodebase=file:///C:/workspace/DEV/ReutersTickHistoryServer/ReutersTickHistoryInterface.jar; rmiServerHostname=RTPC-16"

该文件确实存在:

C:\>dir c:\workspace\DEV\ReutersTickHistoryServer\ReutersTickHistoryInterface.jar
Volume in drive C is OS
Volume Serial Number is 7AEB-A105

Directory of c:\workspace\DEV\ReutersTickHistoryServer

22/10/2010 12:21 PM 9,467 ReutersTickHistoryInterface.jar
1 File(s) 9,467 bytes

所以,再次总结一下:

  • 当 RMIRegistry 和 RMIServer 位于同一物理主机(例如本地主机)上时,此代码有效
  • 当我尝试在单独的主机上运行 RMIRegistry 进程时,就会出现问题(即,RMIRegistry 在“deity”上运行,正如我希望的那样,而 RMIServer 在我的本地主机上运行) RTPC-16')
  • 我在客户端和服务器上捆绑了 RMI 接口(interface)代码库(“ReutersTickHistoryInterface.jar”),因此我没有预料到 RMI 需要传输任何类定义 - RMI 只需在客户端上创建 stub 类并处理实际的 RMI 调用

最佳答案

您还滥用了 java.rmi.server.hostname。这不是它的目的。由于此代码绑定(bind)到注册表,并且只有当注册表在同一主机上运行时才能执行此操作,因此在获取用于绑定(bind)或取消绑定(bind)的注册表引用时,您应该只使用“localhost”。

关于RMI 绑定(bind)问题(从 Windows RMI 服务器到 Ubuntu RMI 注册表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4030730/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com