core
Class Connection

java.lang.Object
  extended by core.Connection

public class Connection
extends java.lang.Object

A connection between two DTN nodes.


Constructor Summary
Connection(DTNHost fromNode, DTNHost toNode, int connectionSpeed)
          Creates a new connection between nodes and sets the connection state to "up".
 
Method Summary
 void abortTransfer()
          Aborts the transfer of the currently transferred message.
 void finalizeTransfer()
          Finalizes the transfer of the currently transferred message.
 Message getMessage()
          Gets the message that this connection is currently transferring.
 DTNHost getOtherNode(DTNHost node)
          Returns the node in the other end of the connection
 int getRemainingByteCount()
          Returns the amount of bytes to be transferred before ongoing transfer is ready or 0 if there's no ongoing transfer or it has finished already
 int getTotalBytesTransferred()
          Returns the total amount of bytes this connection has transferred so far (including all transfers).
 double getTransferDoneTime()
          Returns the time when the current transfer is done (if the connection doesn't break and the transfer is not aborted).
 boolean isInitiator(DTNHost node)
          Returns true if the given node is the initiator of the connection, false otherwise
 boolean isMessageTransferred()
          Returns true if the current message transfer is done
 boolean isReadyForTransfer()
          Returns true if the connection is ready to transfer a message (connection is up and there is no message being transferred).
 boolean isUp()
          Returns true if the connection is up
 void setUpState(boolean state)
          Sets the state of the connection.
 int startTransfer(DTNHost from, Message m)
          Sets a message that this connection is currently transferring.
 java.lang.String toString()
          Returns a String presentation of the connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Connection

public Connection(DTNHost fromNode,
                  DTNHost toNode,
                  int connectionSpeed)
Creates a new connection between nodes and sets the connection state to "up".

Parameters:
fromNode - The node that initiated the connection
toNode - The node in the other side of the connection
connectionSpeed - Transfer speed of the connection (Bps)
Method Detail

isUp

public boolean isUp()
Returns true if the connection is up

Returns:
state of the connection

isInitiator

public boolean isInitiator(DTNHost node)
Returns true if the given node is the initiator of the connection, false otherwise

Parameters:
node - The node to check
Returns:
true if the given node is the initiator of the connection

setUpState

public void setUpState(boolean state)
Sets the state of the connection.

Parameters:
state - True if the connection is up, false if not

startTransfer

public int startTransfer(DTNHost from,
                         Message m)
Sets a message that this connection is currently transferring. If message passing is controlled by external events, this method is not needed (but then e.g. finalizeTransfer() and isMessageTransferred() will not work either). Only a one message at a time can be transferred using one connection.

Parameters:
m - The message
Returns:
The value returned by MessageRouter.receiveMessage(Message, DTNHost)

abortTransfer

public void abortTransfer()
Aborts the transfer of the currently transferred message.


getTransferDoneTime

public double getTransferDoneTime()
Returns the time when the current transfer is done (if the connection doesn't break and the transfer is not aborted).

Returns:
the time when the current transfer is done

getRemainingByteCount

public int getRemainingByteCount()
Returns the amount of bytes to be transferred before ongoing transfer is ready or 0 if there's no ongoing transfer or it has finished already

Returns:
the amount of bytes to be transferred

finalizeTransfer

public void finalizeTransfer()
Finalizes the transfer of the currently transferred message. The message that was being transferred can not be retrieved from this connections after calling this method (using getMessage()).


isMessageTransferred

public boolean isMessageTransferred()
Returns true if the current message transfer is done

Returns:
True if the transfer is done, false if not

isReadyForTransfer

public boolean isReadyForTransfer()
Returns true if the connection is ready to transfer a message (connection is up and there is no message being transferred).

Returns:
true if the connection is ready to transfer a message

getMessage

public Message getMessage()
Gets the message that this connection is currently transferring.

Returns:
The message or null if no message is being transferred

getTotalBytesTransferred

public int getTotalBytesTransferred()
Returns the total amount of bytes this connection has transferred so far (including all transfers).


getOtherNode

public DTNHost getOtherNode(DTNHost node)
Returns the node in the other end of the connection

Parameters:
node - The node in this end of the connection
Returns:
The requested node

toString

public java.lang.String toString()
Returns a String presentation of the connection.

Overrides:
toString in class java.lang.Object