This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 0xfb15c080b33946dbaac8d11aec2d18369aeb52bc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def toInt(s: String) = { | |
| try { | |
| Some(Integer.parseInt(s)) | |
| } catch { | |
| case e: Exception => None | |
| } | |
| } | |
| def square(i: Int) = i * i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int host = ... | |
| int port = ... | |
| String oldHost = TargettableRmiClientSocketFactory.getHost(); | |
| String oldPort = TargettableRmiClientSocketFactory.getPort(); | |
| try { | |
| TargettableRmiClientSocketFactory.setHost(host); | |
| TargettableRmiClientSocketFactory.setPort(port); | |
| // do RMI operation here | |
| } finally { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); } |