forward.server
Class ForwardConnection

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

public class ForwardConnection
extends java.lang.Object

This is the implementation of the forwarding component between client and the protocol handler. The bandwidth limit is implemented here.


Field Summary
private  IStreamConnection m_clientConnection
          Stores the connection to the client.
private  java.lang.Thread m_clientReadThread
          Stores the instance of the data transfer thread for the client -> server direction.
private  boolean m_closeConnection
          Stores whether the ForwardConnection shall be closed.
private  ForwardScheduler m_parentScheduler
          Stores the scheduler, which controls this ForwardConnection.
private  IProtocolHandler m_serverConnection
          Stores the protocol handler, which processes the data or forwards them to the mixcascade.
private  java.lang.Thread m_serverReadThread
          Stores the instance of the data transfer thread for the server -> client direction.
private  java.lang.Thread m_timeoutThread
          Stores the instance of the thread, which checks for a timeout on the connection.
private  int m_transferFromClient
          Stores the amount of data which can be transfered on the client -> server direction this round.
private  int m_transferFromServer
          Stores the amount of data which can be transfered on the server -> client direction this round.
 
Constructor Summary
ForwardConnection(IStreamConnection a_clientConnection, ForwardScheduler a_parentScheduler)
          Creates a new ForwardConnection.
 
Method Summary
 void allowTransfer(int a_transferBytes)
          This method is called by the scheduler to submit, how many bytes can be transfered on this connection in the next round.
 void closeConnection()
          Closes the connection.
 int getAvailableBytes()
          Returns the sum of available bytes (bytes which we have already received, but waiting in the incoming buffers for the connection) for the client -> server direction and the server -> client direction.
 ForwardScheduler getParentScheduler()
          Returns the scheduler for this connection.
 java.lang.String toString()
          Returns a string representation of this connection It's the IP and the port of the client.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_clientConnection

private IStreamConnection m_clientConnection
Stores the connection to the client.


m_serverConnection

private IProtocolHandler m_serverConnection
Stores the protocol handler, which processes the data or forwards them to the mixcascade.


m_parentScheduler

private ForwardScheduler m_parentScheduler
Stores the scheduler, which controls this ForwardConnection.


m_closeConnection

private boolean m_closeConnection
Stores whether the ForwardConnection shall be closed. This indicates the internal threads, that they should come to the end.


m_transferFromClient

private int m_transferFromClient
Stores the amount of data which can be transfered on the client -> server direction this round.


m_transferFromServer

private int m_transferFromServer
Stores the amount of data which can be transfered on the server -> client direction this round.


m_clientReadThread

private java.lang.Thread m_clientReadThread
Stores the instance of the data transfer thread for the client -> server direction.


m_serverReadThread

private java.lang.Thread m_serverReadThread
Stores the instance of the data transfer thread for the server -> client direction.


m_timeoutThread

private java.lang.Thread m_timeoutThread
Stores the instance of the thread, which checks for a timeout on the connection.

Constructor Detail

ForwardConnection

public ForwardConnection(IStreamConnection a_clientConnection,
                         ForwardScheduler a_parentScheduler)
                  throws java.lang.Exception
Creates a new ForwardConnection. Also the internal threads for transfering the data and checking the timeout are created and started. Everything runs until this connection is closed by the scheduler or an error on the connection or while doing the protocol occurs. Then the closeConnection() method is called automatically. If there is an error while starting the protocol (DefaultProtocolHandler at the moment), no thread is started and an Exception is thrown. The client connection keeps open.

Parameters:
a_clientConnection - The Socket with the active connection to the client.
a_parentScheduler - The scheduler which controls this connection.
Throws:
java.lang.Exception
Method Detail

getAvailableBytes

public int getAvailableBytes()
Returns the sum of available bytes (bytes which we have already received, but waiting in the incoming buffers for the connection) for the client -> server direction and the server -> client direction.

Returns:
The sum of available bytes (both directions) for this connection.

getParentScheduler

public ForwardScheduler getParentScheduler()
Returns the scheduler for this connection.

Returns:
The scheduler for this connection.

closeConnection

public void closeConnection()
Closes the connection. The call is asynchronous, which means that it not waits until the end of the internal transfer threads. That is no problem because the internal threads will end immediately, but the wait for the end of the threads could result in a deadlock (if the thread himself has called closeConnection() -> thread waits for the end of closeConnection(), closeConnection() wait on the end of the thread). The connection is also removed from the connection list of the parent scheduler.


allowTransfer

public void allowTransfer(int a_transferBytes)
This method is called by the scheduler to submit, how many bytes can be transfered on this connection in the next round. This method splits the assigned bytes into the transfer capacities for both directions (client->server, server->client) and notifies the transfer threads.

Parameters:
a_transferBytes - The bytes which can be transfered on this connection in the next round.

toString

public java.lang.String toString()
Returns a string representation of this connection It's the IP and the port of the client.

Overrides:
toString in class java.lang.Object
Returns:
IP:port of the client.