Hello,
I am using a combination of Spring Remoting and Scheduling with Quartz Timer. Both are using RMI as a communication stack. The RMI server is located in sydney while the client is located in the US. This incurs large network lag which causes my RMI method calls to timeout. I am able to do a lookup on the RMI object and receive a stub reference to it with no problem but as soon as I try to invoke a remote method on that stub it eventually times out.
Thinking it was truly a timeout issue I implemented a Custom socket factory for RMI using
RMISocketFactory.setSocketFactory(new TimeoutSocketFactory(120000));
Here is the custom TimeoutSocketFactory:
public class TimeoutSocketFactory extends RMISocketFactory {
private int timeout;
private static final Logger log = Logger.getLogger(TimeoutSocketFactory.class);
public TimeoutSocketFactory(int timeout) {
this.timeout = timeout;
}
public Socket createSocket(String host, int port) throws IOException {
log.debug("Creating timeout socket with value - " + timeout);
Socket ret = getDefaultSocketFactory().createSocket(host, port);
ret.setSoTimeout(timeout);
return ret;
}
public ServerSocket createServerSocket(int port) throws IOException {
ServerSocket ss = getDefaultSocketFactory().createServerSocket(port);
ss.setSoTimeout(timeout);
return ss;
}
}
I implemented the custom socket factory both on the RMI server and on the RMI client. This had no effect on the time outs that occured when trying to make an RMI call to the server even though the sockets were being built by this custom class (have logging in place).
Is there something else I need to do to increase the timeout period? And how do I know if it's a server or a client issue?
Thanks,
Anthony Bargnesi
[Exception StackTrace]
java.rmi.ConnectException: Connection refused to host: 172.16.10.97; nested exception is:
java.net.ConnectException: Connection timed out: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:574)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:94)
at org.springframework.remoting.rmi.RmiInvocationWrapper_Stub.invoke(Unknown Source)
at com.aquent.rmi.test.RMIClient.connectService(RMIClient.java:46)
at com.aquent.rmi.test.RMIClient.main(RMIClient.java:81)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:507)
at java.net.Socket.connect(Socket.java:457)
at java.net.Socket.<init>(Socket.java:365)
at java.net.Socket.<init>(Socket.java:178)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at com.aquent.rmi.test.TimeoutFactory.createSocket(TimeoutFactory.java:21)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:569)