Forcing RMI to use sotimeout set by socket factory

This commit is contained in:
Markus Kreusch 2017-11-16 15:29:11 +01:00
parent 02f3f5ad53
commit 9ff710ddf5
No known key found for this signature in database
GPG Key ID: 1EE9C2089D33B557
2 changed files with 18 additions and 4 deletions

2
.gitignore vendored
View File

@ -20,4 +20,4 @@ out/
*.iml
# Temporary file created by test launcher
main/launcher/ipcPort.tmp
main/launcher/.ipcPort.tmp

View File

@ -10,6 +10,8 @@ import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
@ -250,9 +252,21 @@ abstract class InterProcessCommunicator implements InterProcessCommunicationProt
@Override
public Socket createSocket(String host, int port) throws IOException {
Socket socket = new Socket(host, port);
socket.setSoTimeout(1000); // 1s
return socket;
return new SocketWithFixedTimeout(host, port, 1000);
}
}
private static class SocketWithFixedTimeout extends Socket {
public SocketWithFixedTimeout(String host, int port, int timeoutInMs) throws UnknownHostException, IOException {
super(host, port);
super.setSoTimeout(timeoutInMs);
}
@Override
public synchronized void setSoTimeout(int timeout) throws SocketException {
// do nothing, timeout is fixed
}
}