twcsckernel.projectbase.rmi.socketfactory
Class ClientTwoWaySocketFactory

java.lang.Object
  extended by java.rmi.server.RMISocketFactory
      extended by twcsckernel.projectbase.rmi.socketfactory.ClientTwoWaySocketFactory
All Implemented Interfaces:
java.rmi.server.RMIClientSocketFactory, java.rmi.server.RMIServerSocketFactory

public class ClientTwoWaySocketFactory
extends java.rmi.server.RMISocketFactory

Socket factory for clients who want servers to be able to call them back even if the client's address/port are not reachable from the server. This happens with firewalls and dial-up networking, for example.

The factory provides two main capabilities:

The gateway registry allows a mapping to be made between two endpoints. For example, the endpoint cssassociates.com:3453 can be mapped to somewhereElse.com:2356. Client connections made to the first endpoint from RMI will actually be connected to the second endpoint. This situation occurs when a port on a firewall is "opened" and forwarded to a host within the firewall.

A signalling channel is a socket from the client to the server and carries the "two-way" protocol (for lack of a better name). The client establishes a signalling channel to the server, which must be running the ServerTwoWaySocketFactory. When the server needs to make a callback to the client, it requests a socket via the channel instead of trying to directly connect to the client. The client establishes a socket to the server for the server to use in the callback.

Author:
Tim Taylor -- tttaylor@cssassociates.com

Constructor Summary
ClientTwoWaySocketFactory()
           
 
Method Summary
 java.net.ServerSocket createServerSocket(int port)
           
 java.net.Socket createSocket(java.lang.String host, int port)
          Creates a socket to the specified host and port.
 void establishSignallingChannel(java.lang.String address, int port)
          Establish a two-way protocol signalling channel to the server at
 EndpointInfo getDirectEndpoint(java.lang.String host, int port)
          Returns the endpoint associated with the host and port.
 void registerGateway(java.lang.String host, int port, java.lang.String gateHost, int gatePort)
          Register a gateway.
 
Methods inherited from class java.rmi.server.RMISocketFactory
getDefaultSocketFactory, getFailureHandler, getSocketFactory, setFailureHandler, setSocketFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClientTwoWaySocketFactory

public ClientTwoWaySocketFactory()
Method Detail

registerGateway

public void registerGateway(java.lang.String host,
                            int port,
                            java.lang.String gateHost,
                            int gatePort)
Register a gateway. Client connections requested via createSocket for host:port will instead be made to gateHost:gatePort

Parameters:
host - The destination host.
port - The destination port.
gateHost - The gateway host (proxy, firewall, etc.).
gatePort - The gateway port.

establishSignallingChannel

public void establishSignallingChannel(java.lang.String address,
                                       int port)
                                throws java.io.IOException
Establish a two-way protocol signalling channel to the server at

Throws:
java.io.IOException

getDirectEndpoint

public EndpointInfo getDirectEndpoint(java.lang.String host,
                                      int port)
Returns the endpoint associated with the host and port. The endpoint returned is the endpoint to be directly contacted. If the host and port have an associated gateway endpoint, that endpoint is returned. Otherwise an endpoint for the provided host and port is returned.

Returns:
The endpoint to be connected to.

createSocket

public java.net.Socket createSocket(java.lang.String host,
                                    int port)
                             throws java.io.IOException
Creates a socket to the specified host and port. If a gateway has been registered using registerGateway then the socket will be connected to that gateway. Otherwise, the socket is connected directly to the specified host and port.

Specified by:
createSocket in interface java.rmi.server.RMIClientSocketFactory
Specified by:
createSocket in class java.rmi.server.RMISocketFactory
Throws:
java.io.IOException
See Also:
#registerGateway()

createServerSocket

public java.net.ServerSocket createServerSocket(int port)
                                         throws java.io.IOException
Specified by:
createServerSocket in interface java.rmi.server.RMIServerSocketFactory
Specified by:
createServerSocket in class java.rmi.server.RMISocketFactory
Returns:
a server socket for the specified port
Throws:
java.io.IOException


Copyright © 2005-2006 CS@PUT. All Rights Reserved.