util.rmi
Class VpnSocketFactory

java.lang.Object
  extended by java.rmi.server.RMISocketFactory
      extended by util.rmi.VpnSocketFactory
All Implemented Interfaces:
Serializable, RMIClientSocketFactory, RMIServerSocketFactory

public class VpnSocketFactory
extends RMISocketFactory
implements Serializable

This class allows the usage of a custom RMI Socket Factory for all registry services. It is intended to replace the standard rmiregistry tool in the case of a VPN network, where the server is accessed by local clients within a local subnetwork, which is part of a bigger VPN network. These clients connect to the server using its 'true' IP address, they must be fast and reliable. Other clients connecting via the VPN address are intended mainly for monitoring purpose. Their connection is slow and prone to failures.

On startup, the System property VPNHOSTS is searched, and if pointing to a resolvable resource, this resource is loaded as a String-toString mapping. If the property is not set, DEFVPNMAP is used. The only thing that chances is the client socket factory, in a way that, if originating from within the local subnet, determined by comparing the main server IP with the local host name of the client and matching for the first three IP bytes, nothing is changed, but if connecting from the outside, the mapping address is used.

On STELLA, this class is used for the servers in Tenerife: 161.72.132.72 links to 141.33.210.38
161.72.132.71 links to 141.33.210.34

For problems related to java.rmi.ServerError see

See Also:
RegistryLister, Serialized Form

Nested Class Summary
static class VpnSocketFactory.Rmiregistry
          Starts an RMI-registry on the default port, setting the default socket factory to our implementation.
 
Field Summary
private static RMISocketFactory def
          The default socket factory that was active before we get selected.
private static String[][] DEFVPNMAP
          Default mapping of IP server addresses to VPN hosts, new 2011.
static String JAVAHOST
          The java system property java.rmi.server.hostname.
private static InetAddress local
          The local IP address.
private static VpnSocketFactory mysockfac
          The only running instance, created at class-load.
private static long serialVersionUID
           
static String VPNHOSTS
          The name of the system property that points to a valid mapping.
private  Map<String,String> vpnmap
          The mapping to use for IP server names to VPN connect names.
 
Constructor Summary
private VpnSocketFactory()
          On construct, we scan for the VPNHOSTS property.
 
Method Summary
 ServerSocket createServerSocket(int port)
          The server socket is unchanged from the defaults.
 Socket createSocket(String host, int port)
          Creates the client socket.
 boolean equals(Object obj)
           
static Remote exportObject(Remote obj)
          We replace the unicast export by a unicast export using our factory.
static Remote exportObject(Remote obj, int port)
          We replace the unicast export by a unicast export using our factory.
private static Map<String,String> fileLoad(File file)
          Loads properties from the given file.
private static Map<String,String> fileLoad(String filename)
          Loads properties from the given file.
private static Map<String,String> fromResourceBundle(ResourceBundle prop)
          Scans a resource bundle for it's keys and re-maps them.
private  String getDomain(InetAddress ip)
          From the inet address supplied, we grep the domain as a string.
 int hashCode()
           
private static Map<String,String> load(InputStream in)
          Loads properties from an input stream.
private static Map<String,String> load(URL url)
          Loads properties from an URL.
private static Map<String,String> scanSystem(String key)
          Scans a system resource and returns it as a String-toString mapping.
 
Methods inherited from class java.rmi.server.RMISocketFactory
getDefaultSocketFactory, getFailureHandler, getSocketFactory, setFailureHandler, setSocketFactory
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VPNHOSTS

public static final String VPNHOSTS
The name of the system property that points to a valid mapping.

See Also:
Constant Field Values

JAVAHOST

public static final String JAVAHOST
The java system property java.rmi.server.hostname.

See Also:
Constant Field Values

DEFVPNMAP

private static final String[][] DEFVPNMAP
Default mapping of IP server addresses to VPN hosts, new 2011.


def

private static final RMISocketFactory def
The default socket factory that was active before we get selected.


serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

local

private static InetAddress local
The local IP address.


vpnmap

private Map<String,String> vpnmap
The mapping to use for IP server names to VPN connect names.


mysockfac

private static VpnSocketFactory mysockfac
The only running instance, created at class-load.

Constructor Detail

VpnSocketFactory

private VpnSocketFactory()
On construct, we scan for the VPNHOSTS property. If not present, we use the default mapping in DEFVPNMAP.

Method Detail

exportObject

public static Remote exportObject(Remote obj)
                           throws RemoteException
We replace the unicast export by a unicast export using our factory.

Throws:
RemoteException

exportObject

public static Remote exportObject(Remote obj,
                                  int port)
                           throws RemoteException
We replace the unicast export by a unicast export using our factory.

Throws:
RemoteException

scanSystem

private static Map<String,String> scanSystem(String key)
Scans a system resource and returns it as a String-toString mapping.


fromResourceBundle

private static Map<String,String> fromResourceBundle(ResourceBundle prop)
Scans a resource bundle for it's keys and re-maps them.


fileLoad

private static Map<String,String> fileLoad(String filename)
Loads properties from the given file. The file is given as a filename. If the filename is null null is returned. If the file cannot be read an empty properties object is returned.


fileLoad

private static Map<String,String> fileLoad(File file)
Loads properties from the given file. The file is given as a file object. If the filename is null, null is returned. If the file cannot be read an empty properties object is returned.


load

private static Map<String,String> load(URL url)
Loads properties from an URL.


load

private static Map<String,String> load(InputStream in)
Loads properties from an input stream. The input stream is not closed.


createServerSocket

public ServerSocket createServerSocket(int port)
                                throws IOException
The server socket is unchanged from the defaults.

Specified by:
createServerSocket in interface RMIServerSocketFactory
Specified by:
createServerSocket in class RMISocketFactory
Throws:
IOException

createSocket

public Socket createSocket(String host,
                           int port)
                    throws IOException
Creates the client socket. If the client is connecting from the outside, the server name is replaced to its VPN equivalent.

Specified by:
createSocket in interface RMIClientSocketFactory
Specified by:
createSocket in class RMISocketFactory
Throws:
IOException

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

getDomain

private String getDomain(InetAddress ip)
From the inet address supplied, we grep the domain as a string. This string are the first three bytes of the address, not considering a name.