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不能連接... –