• New Feature
  • Status: Resolved
  • 2 Major
  • Resolution: Won't Fix
  • ehcache-core
  • interfaces
  • Reporter: cdibarto
  • March 26, 2013
  • 0
  • Watchers: 2
  • June 06, 2013
  • April 22, 2013


net.sf.ehcache.distribution.RMICachePeers are created using the properties specified in the net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory. A net.sf.ehcache.distribution.ConfigurableRMIClientSocketFactory creates java.net.Sockets using an implementation of the createSocket method: public abstract Socket createSocket(InetAddress host, int port) throws IOException The comment in the source for this method states: If necessary this implementation can be changed to specify the outbound address to use * e.g. Socket socket = new Socket(host, port, localInterface , 0);’ This createSocket method signature: public abstract Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException provided by java.net.SocketFactory would be implemented to provide this implementation.
ConfigurableRMIClientSocketFactory creates Sockets using InetAddress.getLocalHost().getHostAddress() which returns the default localInterface of which is likely not the required interface for multi-homed machines. Because this value is placed into the RMI stub utilized by a client, it must contain a reachable hostname or IP address, otherwise a java.net ConnectException will be thrown as follows: java.net.ConnectException: Connection timed out: connect java.rmi.ConnectException: Connection refused to host: ; nested exception is: java.net.ConnectException: Connection timed out: connect at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601) at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198) at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184) at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:110) at net.sf.ehcache.distribution.RMICachePeer\_Stub.send(Unknown Source) at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.flushReplicationQueue(RMIAsynchronousCacheReplicator.java:307) at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.replicationThreadMain(RMIAsynchronousCacheReplicator.java:119) at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.access$100(RMIAsynchronousCacheReplicator.java:57) at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator$ReplicationThread.run(RMIAsynchronousCacheReplicator.java:371)

Rather than having users provide a custom implementation of this method the net.sf.ehcache.distribution.ConfigurableRMIClientSocketFactory should provide an implementation of createSocket with this signature: public abstract Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException The localHost parameter would be an additional optional property that if set within the cacheManagerPeerListenerFactory would be used for this implemented method. Alternatively, until this exists, the RMI system property java.rmi.server.hostname should be set to a reachable hostname or IP address. The java.rmi.server.hostname property is described as follows: The value of this property represents the host name string that should be associated with remote stubs for locally created remote objects, in order to allow clients to invoke methods on the remote object. The default value of this property is the IP address of the local host, in “dotted-quad” format.


Chris Dennis 2013-04-22

The proposal here doesn’t seem like a solution. If users want this functionality they can install a socket factory using RMISocketFactory.setSocketFactory(…).