Class TCPEntity

java.lang.Object
  extended by TCPEntity
All Implemented Interfaces:
java.lang.Runnable

public class TCPEntity
extends java.lang.Object
implements java.lang.Runnable

A TCPEntity represents a TCP connection thread in the Transport layer. Each TCPEntity is associated with a specific socket on a specific host. It delegates packet handling to a reliable data transfer protocol.

When created, a TCPEntity is given a name. When setup, it is given a partner, which is the TCPEntity at the other end of the socket connection, and an RDTProtocol, which specifies the reliable data transfer protocol that it should use. In reality, of course, the partner TCPEntity would be replaced by just the host internet ID and port number of the partner.

Internal View

A TCPEntity provides a context in which reliable data transfer protocol code can be executed in a single thread. It provides all necessary synchronization with other threads. It also, through its nested Context class, provides services that the reliable data transfer protocol can use to control the TCPEntity and to interface with the demultiplexer and reassembler on the receive side, and the segmenter and multiplexer on the send side.


Nested Class Summary
 class TCPEntity.Context
          A Context is created by a TCPEntity and passed to its RDTProtocol during set up of the TCPEntity.
 
Constructor Summary
TCPEntity(java.lang.String nm)
          new TCPEntity(nm) returns a new TCPEntity named nm.
 
Method Summary
 void disconnect()
          tcpe.disconnect() is invoked to get tcpe to disconnect from its communication partner.
 java.lang.String getReceivedMessage()
          tcpe.getReceivedMessage() returns the message received by tcpe.
 void receivePacket(Packet pkt)
          tcpe.receivePacket(pkt) is invoked to get tcpe to handle a packet from its connection partner.
 void run()
          Do not invoke this method externally - it is automatically invoked at the end of the setUp() method.
 void sendData(int id)
          tcpe.sendData(id) sends a new data packet with identification number id from tcpe to its communication partner.
 java.lang.Thread setUp(TCPEntity prtnr, RDTProtocol proto)
          tcpe.setUp(prtnr, proto) sets up tcpe for communication with prtnr using the reliable data transfer protocol proto.
 java.lang.String toString()
          tcpe.toString() returns the name of tcpe.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TCPEntity

public TCPEntity(java.lang.String nm)
new TCPEntity(nm) returns a new TCPEntity named nm.

Method Detail

setUp

public java.lang.Thread setUp(TCPEntity prtnr,
                              RDTProtocol proto)
tcpe.setUp(prtnr, proto) sets up tcpe for communication with prtnr using the reliable data transfer protocol proto. The Thread used by tcpe is returned.


sendData

public void sendData(int id)
tcpe.sendData(id) sends a new data packet with identification number id from tcpe to its communication partner.

This method is the segmenter's interface to the TCPEntity. It is invoked to schedule a segment for packetization and delivery. The id parameter is just a stand-in for the real data in a segment. It is used by the Logger for recording purposes.


receivePacket

public void receivePacket(Packet pkt)
tcpe.receivePacket(pkt) is invoked to get tcpe to handle a packet from its connection partner.

This method is the demultiplexer's interface to the TCPEntity.


getReceivedMessage

public java.lang.String getReceivedMessage()
tcpe.getReceivedMessage() returns the message received by tcpe.


disconnect

public void disconnect()
tcpe.disconnect() is invoked to get tcpe to disconnect from its communication partner. The disconnect is only done after pending tasks have been done.


toString

public java.lang.String toString()
tcpe.toString() returns the name of tcpe.

Overrides:
toString in class java.lang.Object

run

public void run()
Do not invoke this method externally - it is automatically invoked at the end of the setUp() method.

tcpe.run() repeatedly looks for tasks from the scheduler and executes them. This method is the top-level code executed by the protocol thread. When the method terminates, the thread terminates.

Specified by:
run in interface java.lang.Runnable