Skip to content

Instantly share code, notes, and snippets.

View satishsrinivasan's full-sized avatar

Satish Srinivasan satishsrinivasan

View GitHub Profile
0xfb15c080b33946dbaac8d11aec2d18369aeb52bc
def toInt(s: String) = {
try {
Some(Integer.parseInt(s))
} catch {
case e: Exception => None
}
}
def square(i: Int) = i * i
int host = ...
int port = ...
String oldHost = TargettableRmiClientSocketFactory.getHost();
String oldPort = TargettableRmiClientSocketFactory.getPort();
try {
TargettableRmiClientSocketFactory.setHost(host);
TargettableRmiClientSocketFactory.setPort(port);
// do RMI operation here
} finally {
public class TargettableRmiClientSocketFactory implements RMIClientSocketFactory, Serializable
{
private static final ThreadLocal<String> IP_ADDRESS = new ThreadLocal<String>();
private static final ThreadLocal<Integer> PORT = new ThreadLocal<Integer>();
private RMIClientSocketFactory delegate; // initialised in constructor to something sensible
public static String getHost() { return IP_ADDRESS.get(); }
public static Integer getPort() { return PORT.get(); }
public static void setHost(String host) { IP_ADDRESS.set(host); }