public abstract class Connection
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected int |
bytesTransferred
how many bytes this connection has transferred
|
protected NetworkInterface |
fromInterface |
protected DTNHost |
fromNode |
protected DTNHost |
msgFromNode |
protected Message |
msgOnFly |
protected NetworkInterface |
toInterface |
protected DTNHost |
toNode |
| Constructor and Description |
|---|
Connection(DTNHost fromNode,
NetworkInterface fromInterface,
DTNHost toNode,
NetworkInterface toInterface)
Creates a new connection between nodes and sets the connection
state to "up".
|
| Modifier and Type | Method and Description |
|---|---|
void |
abortTransfer()
Aborts the transfer of the currently transferred message.
|
protected void |
clearMsgOnFly()
Clears the message that is currently being transferred.
|
void |
finalizeTransfer()
Finalizes the transfer of the currently transferred message.
|
Message |
getMessage()
Gets the message that this connection is currently transferring.
|
NetworkInterface |
getOtherInterface(NetworkInterface i)
Returns the interface in the other end of the connection
|
DTNHost |
getOtherNode(DTNHost node)
Returns the node in the other end of the connection
|
abstract 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
|
abstract double |
getSpeed()
Gets the current connection speed
|
int |
getTotalBytesTransferred()
Returns the total amount of bytes this connection has transferred so far
(including all transfers).
|
boolean |
isInitiator(DTNHost node)
Returns true if the given node is the initiator of the connection, false
otherwise
|
abstract 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 |
isTransferring()
Returns true if the connections is transferring a message
|
boolean |
isUp()
Returns true if the connection is up
|
void |
setUpState(boolean state)
Sets the state of the connection.
|
abstract 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.
|
void |
update()
Calculate the current transmission speed from the information
given by the interfaces, and calculate the missing data amount.
|
protected DTNHost toNode
protected NetworkInterface toInterface
protected DTNHost fromNode
protected NetworkInterface fromInterface
protected DTNHost msgFromNode
protected Message msgOnFly
protected int bytesTransferred
public Connection(DTNHost fromNode, NetworkInterface fromInterface, DTNHost toNode, NetworkInterface toInterface)
fromNode - The node that initiated the connectionfromInterface - The interface that initiated the connectiontoNode - The node in the other side of the connectiontoInterface - The interface in the other side of the connectionpublic boolean isUp()
public boolean isTransferring()
public boolean isInitiator(DTNHost node)
node - The node to checkpublic void setUpState(boolean state)
state - True if the connection is up, false if notpublic abstract int startTransfer(DTNHost from, Message m)
finalizeTransfer() and
isMessageTransferred() will not work either). Only a one message
at a time can be transferred using one connection.m - The messageMessageRouter.receiveMessage(Message, DTNHost)public void update()
public void abortTransfer()
public abstract int getRemainingByteCount()
protected void clearMsgOnFly()
getMessage() will return null after this.public void finalizeTransfer()
getMessage()).public abstract boolean isMessageTransferred()
public boolean isReadyForTransfer()
public Message getMessage()
public abstract double getSpeed()
public int getTotalBytesTransferred()
public DTNHost getOtherNode(DTNHost node)
node - The node in this end of the connectionpublic NetworkInterface getOtherInterface(NetworkInterface i)
i - The interface in this end of the connectionpublic java.lang.String toString()
toString in class java.lang.Object