forward.server
Class ForwardServerManager

java.lang.Object
  extended by forward.server.ForwardServerManager

public class ForwardServerManager
extends java.lang.Object

This class manages the whole forwarding server and supplies some important methods to other classes. This class is a singleton.


Field Summary
static int CLIENT_CONNECTION_TIMEOUT
          This is the timeout for all socket methods on the client connection.
static int CLIENT_DUMMYTRAFFIC_INTERVAL
          This is the interval, we need dummy traffic from the client (in milliseconds).
private  ForwardCascadeDatabase m_allowedCascadesDatabase
          Stores the database with with the MixCascades, where connections can be forwarded to.
private  int m_dummyTrafficInterval
          Stores the dummy traffic interval (in ms), if we need dummy traffic for holding a connection while phases of inactivity.
private  ForwardScheduler m_forwardScheduler
          Stores the associated ForwardScheduler.
private static ForwardServerManager ms_fsmInstance
          Stores the instance of ForwardServerManager (Singleton).
 
Constructor Summary
private ForwardServerManager()
          This creates a new instance of ForwardManager.
 
Method Summary
 java.lang.Object addListenSocket(int a_portNumber)
          This opens a listen socket at the specified portnumber.
 java.lang.Object addServerManager(IServerManager a_manager)
          Adds an ServerManager.
 ForwardCascadeDatabase getAllowedCascadesDatabase()
          Returns the database with the MixCascades, where connections are allowed to be forwarded to.
 int getCurrentlyForwardedConnections()
          Returns the number of currently forwarded connections.
 int getDummyTrafficInterval()
          Returns the dummy traffic interval.
static ForwardServerManager getInstance()
          Returns the instance of ForwardServerManager (Singleton).
 ForwardSchedulerStatistics getSchedulerStatistics()
          Returns the statistics instance of the scheduler.
 void removeAllServerManagers()
          Removes all ServerManagers from the list of associated ServerManagers of the internal ForwardScheduler.
 void removeServerManager(java.lang.Object a_serverManagerId)
          Removes one ServerManager from the list of associated ServerManagers of this ForwardScheduler.
 void setDummyTrafficInterval(int a_interval)
          This sets the dummy traffic interval.
 void setMaximumNumberOfConnections(int a_maxNumberOfConnections)
          Changes the number of simultaneously forwarded client connections.
 void setNetBandwidth(int a_netBandwidth)
          Changes the maximum bandwidth (net bandwidth, without TCP/IP headers...) which can be used by all client connections together.
 void shutdownForwarding()
          This method must be called, when forwarding shall come to an end.
 void startForwarding()
          This method starts the forwarding code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLIENT_CONNECTION_TIMEOUT

public static final int CLIENT_CONNECTION_TIMEOUT
This is the timeout for all socket methods on the client connection. We need a timeout there because we have no keepalive option. Without a timeout, a physical interruption on the connection would result in a open connection until the server shutdown. The default value is 200 seconds. So if the client creates dummy traffic every 180 seconds, there should be no problem.

See Also:
Constant Field Values

CLIENT_DUMMYTRAFFIC_INTERVAL

public static final int CLIENT_DUMMYTRAFFIC_INTERVAL
This is the interval, we need dummy traffic from the client (in milliseconds). This value should be a little bit smaller than the CLIENT_CONNECTION_TIMEOUT, so if the client produces the dummy traffic with this rate, the connection keeps open and there should be no problem with timeouts. The default value is dummy traffic every 180 seconds.

See Also:
Constant Field Values

ms_fsmInstance

private static ForwardServerManager ms_fsmInstance
Stores the instance of ForwardServerManager (Singleton).


m_dummyTrafficInterval

private int m_dummyTrafficInterval
Stores the dummy traffic interval (in ms), if we need dummy traffic for holding a connection while phases of inactivity. If this value is -1, no dummy traffic is needed.


m_allowedCascadesDatabase

private ForwardCascadeDatabase m_allowedCascadesDatabase
Stores the database with with the MixCascades, where connections can be forwarded to.


m_forwardScheduler

private ForwardScheduler m_forwardScheduler
Stores the associated ForwardScheduler. If this value is null, forwarding is disabled.

Constructor Detail

ForwardServerManager

private ForwardServerManager()
This creates a new instance of ForwardManager. Forwarding is disabled (m_forwardScheduler is set to null).

Method Detail

getInstance

public static ForwardServerManager getInstance()
Returns the instance of ForwardServerManager (Singleton). If there is no instance, there is a new one created.

Returns:
The ForwardServerManager instance.

setDummyTrafficInterval

public void setDummyTrafficInterval(int a_interval)
This sets the dummy traffic interval. If a connection has to take a proxy server, that proxy maybe closes the connection after some time of inactivity. So there is the need of doing some dummy traffic. This method doesn't have any effect on the local system, but any new connecting client will get this value in the connection offer, so he has to create the dummy traffic for us. Already established connections are not concerned by the change of this value. The maximum dummy traffic interval is defined in CLIENT_DUMMYTRAFFIC_INTERVAL. We need dummy traffic with at least that rate because of the timeout rule for any client connection. So bigger intervals or disabling dummy traffic result in dummy traffic with that default interval.

Parameters:
a_interval - The dummy traffic interval (in milliseconds) or -1, if dummy traffic is disabled.

getDummyTrafficInterval

public int getDummyTrafficInterval()
Returns the dummy traffic interval. Sometimes dummy traffic is needed for holding a connection while phases of inactivity.

Returns:
The dummy traffic interval in milliseconds or -1, if no dummy traffic is needed.

getAllowedCascadesDatabase

public ForwardCascadeDatabase getAllowedCascadesDatabase()
Returns the database with the MixCascades, where connections are allowed to be forwarded to.

Returns:
The database of allowed MixCascades.

setMaximumNumberOfConnections

public void setMaximumNumberOfConnections(int a_maxNumberOfConnections)
Changes the number of simultaneously forwarded client connections. If the new number is less than the old one and there are more forwarded connections at the moment, we closes some randomly choosed connections. If forwarding is not enabled while the call of this function, nothing happens.


setNetBandwidth

public void setNetBandwidth(int a_netBandwidth)
Changes the maximum bandwidth (net bandwidth, without TCP/IP headers...) which can be used by all client connections together. If forwarding is not enabled while the call of this function, nothing happens.

Parameters:
a_netBandwidth - The maximum bandwidth for all client connections together (= average upstream = average downstream) in bytes/sec.

addListenSocket

public java.lang.Object addListenSocket(int a_portNumber)
This opens a listen socket at the specified portnumber. Clients can connect to this socket and the associated ForwardScheduler will manage that forwarded connections. It is possible that the ForwardScheduler manages more than one listening socket. If forwarding is not enabled while the call of this function, nothing happens and the result is false.

Parameters:
a_portNumber - The portnumber where the new server socket will listen on.
Returns:
An Object with the ID of the created ServerManager, which can be used to close that ServerManager. If there occured an error while opening the socket or there is no ForwardingScheduler running (normally because the forwarding server is not running), null is returned.

addServerManager

public java.lang.Object addServerManager(IServerManager a_manager)
Adds an ServerManager. Clients can connect to it as it starts Listning on his own Endpoint and the associated ForwardScheduler will manage that forwarded connections. If forwarding is not enabled while the call of this function, nothing happens and the result is false.


removeServerManager

public void removeServerManager(java.lang.Object a_serverManagerId)
Removes one ServerManager from the list of associated ServerManagers of this ForwardScheduler. The shutdown() method is called on that ServerManager and it is removed from the internal list. Active forwarded connections are not affected by this call. If the ForwardScheduler isn't running or it doesn't know any ServerManager with the specified ID, nothing is done.

Parameters:
a_serverManagerId - The ID of the ServerManager to close, see IServerManager.getId().

removeAllServerManagers

public void removeAllServerManagers()
Removes all ServerManagers from the list of associated ServerManagers of the internal ForwardScheduler. The shutdown() method is called on every ServerManager. There can't be opened new connections until at least one server manager is added to the list. Active forwarded connections are not affected by this call.


shutdownForwarding

public void shutdownForwarding()
This method must be called, when forwarding shall come to an end. This method blocks until all connections, sockets and threads are closed. If forwarding is not enabled while the call of this function, nothing happens.


startForwarding

public void startForwarding()
This method starts the forwarding code. The initial bandwidth is set to 0 bytes/sec, the maximum number of forwarded connections is set to 0 and there are no ServerManagers bound to the ForwardScheduler. So the corresponding methods must be called to change those values. If the forwarding code is already running, nothing is done.


getSchedulerStatistics

public ForwardSchedulerStatistics getSchedulerStatistics()
Returns the statistics instance of the scheduler. If no scheduler is running, null is returned.

Returns:
The statistics instance of the scheduler or null, if no scheduler is running.

getCurrentlyForwardedConnections

public int getCurrentlyForwardedConnections()
Returns the number of currently forwarded connections. If no scheduler is running, 0 is returned.

Returns:
The number of currently forwarded connections.