[英]RMI Binding Issue (from Windows RMI Server to Ubuntu RMI Registry)
我有一個RMI服務器,該服務器在localhost上運行時可正確綁定到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)
現在,我的問題是我想綁定到另一台計算機上運行的RMIRegistry(運行Ubuntu 10.04,使用OpenJDK IcedTea6 1.8.1,Java版本1.6.0_18)。
在這台Ubuntu計算機上,我的CLASSPATH中沒有任何內容(回顯$ CLASSPATH),並且正在運行OpenJDK RMIRegistry(與Ubuntu捆綁在一起的相對):
sudo /usr/lib/jvm/java-6-openjdk/jre/bin/rmiregistry &
現在,在上面的代碼中,當變量rmiServerHostname為“ localhost”且RMIRegistry在我的Windows localhost上運行時,該代碼可以正常工作(RMI服務器代碼綁定到RMI注冊表)。 但是,當rmiServerHostname是我的遠程Ubuntu計算機(“神”)時,在“重新綁定”調用上會引發以下異常:
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(在'神'上運行)之間感到困惑。 我已經使用以下代碼修改了代碼,但是仍然遇到相同的問題(請注意“注冊表注冊表= 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
因此,再次總結一下:
另外,您正在濫用java.rmi.server.hostname。 那不是它的目的。 由於此代碼綁定到注冊表,並且僅當注冊表在同一主機上運行時才可以這樣做,因此在獲取用於綁定或解除綁定的注冊表參考時,應僅使用“ localhost”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.