0
我有两个同行连接,虽然RMI。在RMI服务器端,我使用Spring inerfaces(http://www.studytrails.com/frameworks/spring/spring-remoting-rmi.jsp)。在RMI客户端,我需要启动它,了解服务器是否已启动。所以如果我使用spring,我的客户端不会启动,并且我有连接拒绝异常。春天RMI服务器和纯Java RMI客户
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="serviceName" value="RestoreRMIService" />
<property name="serviceInterface" value="br.com.eb.service.iscsi.RestoreService" />
<property name="service" ref="restoreService" />
</bean>
所以我尝试在客户端使用纯java RMI(http://www.javacoffeebreak.com/articles/javarmi/javarmi.html)。但是我得到了ClassCastException:com.sun.proxy。$ Proxy73不能转换为br.com.eb.service.iscsi.RestoreService。我beliave,因为我没有从我的RMI服务器存根。
我wnat纯Java RMI客户端上的,因为我需要能够重新启动服务器端。
protected void connectRMI() {
if (!rmiConected) {
try {
Registry registry = LocateRegistry.getRegistry(1099);
serviceRestore = (RestoreService) registry.lookup("RestoreRMIService");
// serviceRestore = (RestoreService) Naming.lookup("rmi://127.0.0.1/RestoreRMIService");
rmiConected = true;
} catch (ConnectException ce) {
System.err.println("Error: server not started");
rmiConected = false;
} catch (ConnectIOException cioe) {
System.err.println("Error: Cannot connect to server at 127.0.0.1");
rmiConected = false;
} catch (Exception e) {
e.printStackTrace();
}
}
}
我明白了,谢谢!我发现这个> http://stackoverflow.com/questions/1477121/reconnect-rmi-client-after-server-restart –
但如何使客户端开始与从服务器最多?因为这个bean不能连接... –