peer2me.network
Class NodeConnection

java.lang.Object
  extended bypeer2me.network.NodeConnection

public class NodeConnection
extends java.lang.Object

This class contains a thread that runs on each connected node and listens for incoming data packages and sends data packages out. It is created and started in NodeConnection.startNodeConnection().

Author:
Torbjørn Vatn & Steinar A. Hestnes

Constructor Summary
NodeConnection(javax.microedition.io.StreamConnection connection, Node node)
          Constructor.
 
Method Summary
 void closeConnection()
          This method closes the input- and output streams and the connection.
 javax.microedition.io.StreamConnection getConnection()
          This method returns the connection object.
 int getSendQueueSize()
          This method return the size of the sendQue.
 void openInputStream()
          This method sets a boolean that controls whether or not the InputStream are allowed to listen for incoming data.
 void openOutputStream()
          This method sets a boolean that controls whether or not the OutputStream are allowed to send data.
 void processIncomingData()
          This method receives incoming datapackages from remote nodes.
 void processSendQueue()
          This method sends datapackages to remote nodes.
 void sendDataPackage(DataPackage dataPackage)
          This method is called by the sendMessage() method in the Network class when a data package is sent to the Node associated with this NodeConnection.
 void setConnection(javax.microedition.io.StreamConnection connection)
          This method updates the connection object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeConnection

public NodeConnection(javax.microedition.io.StreamConnection connection,
                      Node node)
Constructor. This constructor is called from the constructor in class Node.

Parameters:
connection - The connection to the node
node - The node that owns this NodeConnection
Method Detail

getSendQueueSize

public int getSendQueueSize()
This method return the size of the sendQue.

Returns:
The size of the sendQue

processIncomingData

public void processIncomingData()
This method receives incoming datapackages from remote nodes. It is called in an infinite loop in the private class InputThread in this class.


processSendQueue

public void processSendQueue()
This method sends datapackages to remote nodes. It processes the que of unsent datapackages. It is called in an infinite loop in the private class OutputThread in this class.


sendDataPackage

public void sendDataPackage(DataPackage dataPackage)
This method is called by the sendMessage() method in the Network class when a data package is sent to the Node associated with this NodeConnection.

Parameters:
dataPackage - The DataPackage to send

getConnection

public javax.microedition.io.StreamConnection getConnection()
This method returns the connection object.

Returns:
An object representing the connection to the remote node

setConnection

public void setConnection(javax.microedition.io.StreamConnection connection)
This method updates the connection object. It is used when the existing connection is closed and a new open connection is needed.

Parameters:
connection - The connection to the remote node

openInputStream

public void openInputStream()
This method sets a boolean that controls whether or not the InputStream are allowed to listen for incoming data. The value is toggled from ConnectionListener.run().


openOutputStream

public void openOutputStream()
This method sets a boolean that controls whether or not the OutputStream are allowed to send data. The value is toggled from NodeConnection.sendDataPackage()


closeConnection

public void closeConnection()
This method closes the input- and output streams and the connection. It is called from Group.shutdownGroup() to clean up during shutdown.