public abstract class ActiveRouter extends MessageRouter
getNextMessageToRemove(boolean)) and watching of sending connections (see
update()).| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DELETE_DELIVERED_S
Delete delivered messages -setting id ("deleteDelivered").
|
protected boolean |
deleteDelivered
should messages that final recipient marks as delivered be deleted
from message buffer
|
static java.lang.String |
RESPONSE_PREFIX
prefix of all response message IDs
|
protected java.util.ArrayList<Connection> |
sendingConnections
connection(s) that are currently used for sending
|
B_SIZE_S, DENIED_LOW_RESOURCES, DENIED_NO_SPACE, DENIED_OLD, DENIED_POLICY, DENIED_TTL, DENIED_UNSPECIFIED, MSG_TTL_S, msgTtl, Q_MODE_FIFO, Q_MODE_RANDOM, RCV_OK, SEND_QUEUE_MODE_S, TRY_LATER_BUSY| Modifier | Constructor and Description |
|---|---|
protected |
ActiveRouter(ActiveRouter r)
Copy constructor.
|
|
ActiveRouter(Settings s)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addToSendingConnections(Connection con)
Adds a connections to sending connections which are monitored in
the update.
|
protected boolean |
canStartTransfer()
Makes rudimentary checks (that we have at least one message and one
connection) about can this router start transfer.
|
void |
changedConnection(Connection con)
Called when a connection's state changes.
|
protected int |
checkReceiving(Message m,
DTNHost from)
Checks if router "wants" to start receiving message (i.e.
|
boolean |
createNewMessage(Message m)
Creates a new message to the router.
|
protected void |
dropExpiredMessages()
Drops messages whose TTL is less than zero.
|
protected Connection |
exchangeDeliverableMessages()
Exchanges deliverable (to final recipient) messages between this host
and all hosts this host is currently connected to.
|
protected java.util.List<Connection> |
getConnections()
Returns a list of connections this host currently has with other hosts.
|
protected java.util.List<util.Tuple<Message,Connection>> |
getMessagesForConnected()
Returns a list of message-connections tuples of the messages whose
recipient is some host that we're connected to at the moment.
|
protected Message |
getNextMessageToRemove(boolean excludeMsgBeingSent)
Returns the oldest (by receive time) message in the message buffer
(that is not being sent if excludeMsgBeingSent is true).
|
RoutingInfo |
getRoutingInfo()
Returns routing information about this router.
|
boolean |
hasEnergy()
Returns true if the node has energy left (i.e., energy modeling is
enabled OR (is enabled and model has energy left))
|
void |
init(DTNHost host,
java.util.List<MessageListener> mListeners)
Initializes the router; i.e.
|
boolean |
isSending(java.lang.String msgId)
Returns true if this router is currently sending a message with
msgId. |
boolean |
isTransferring()
Returns true if this router is transferring something at the moment or
some transfer has not been finalized.
|
protected boolean |
makeRoomForMessage(int size)
Removes messages from the buffer (oldest first) until
there's enough space for the new message.
|
protected void |
makeRoomForNewMessage(int size)
Tries to make room for a new message.
|
Message |
messageTransferred(java.lang.String id,
DTNHost from)
This method should be called (on the receiving host) after a message
was successfully transferred.
|
int |
receiveMessage(Message m,
DTNHost from)
Try to start receiving a message from another host.
|
boolean |
requestDeliverableMessages(Connection con)
Requests for deliverable message from this router to be sent trough a
connection.
|
protected void |
shuffleMessages(java.util.List<Message> messages)
Shuffles a messages list so the messages are in random order.
|
protected int |
startTransfer(Message m,
Connection con)
Tries to start a transfer of message using a connection.
|
protected void |
transferAborted(Connection con)
Method is called just before a transfer is aborted at
update()
due connection going down. |
protected void |
transferDone(Connection con)
Method is called just before a transfer is finalized
at
update(). |
protected Message |
tryAllMessages(Connection con,
java.util.List<Message> messages)
Goes trough the messages until the other node accepts one
for receiving (or doesn't accept any).
|
protected Connection |
tryAllMessagesToAllConnections()
Tries to send all messages that this router is carrying to all
connections this node has.
|
protected util.Tuple<Message,Connection> |
tryMessagesForConnected(java.util.List<util.Tuple<Message,Connection>> tuples)
Tries to send messages for the connections that are mentioned
in the Tuples in the order they are in the list until one of
the connections starts transferring or all tuples have been tried.
|
protected Connection |
tryMessagesToConnections(java.util.List<Message> messages,
java.util.List<Connection> connections)
Tries to send all given messages to all given connections.
|
void |
update()
Checks out all sending connections to finalize the ready ones
and abort those whose connection went down.
|
addApplication, addToMessages, compareByQueueMode, deleteMessage, getApplications, getBufferSize, getFreeBufferSize, getHost, getMessage, getMessageCollection, getNrofMessages, hasMessage, isBlacklistedMessage, isDeliveredMessage, isIncomingMessage, messageAborted, putToIncomingBuffer, removeFromIncomingBuffer, removeFromMessages, replicate, sendMessage, sortByQueueMode, toStringpublic static final java.lang.String DELETE_DELIVERED_S
protected boolean deleteDelivered
public static final java.lang.String RESPONSE_PREFIX
protected java.util.ArrayList<Connection> sendingConnections
public ActiveRouter(Settings s)
s - The settings objectprotected ActiveRouter(ActiveRouter r)
r - The router prototype where setting values are copied frompublic void init(DTNHost host, java.util.List<MessageListener> mListeners)
MessageRouterinit in class MessageRouterhost - The host this router is inmListeners - The message listenerspublic void changedConnection(Connection con)
changedConnection in class MessageRouter@con - The connection whose state changedpublic boolean requestDeliverableMessages(Connection con)
MessageRouterrequestDeliverableMessages in class MessageRoutercon - The connection to send the messages troughpublic boolean createNewMessage(Message m)
MessageRoutercreateNewMessage in class MessageRouterm - The message to createpublic int receiveMessage(Message m, DTNHost from)
MessageRouterreceiveMessage in class MessageRouterm - Message to put in the receiving bufferfrom - Who the message is frompublic Message messageTransferred(java.lang.String id, DTNHost from)
MessageRoutermessageTransferred in class MessageRouterid - Id of the transferred messagefrom - Host the message was from (previous hop)protected java.util.List<Connection> getConnections()
protected int startTransfer(Message m, Connection con)
m - The message to transfercon - The connection to useConnection.startTransfer(DTNHost, Message)protected boolean canStartTransfer()
protected int checkReceiving(Message m, DTNHost from)
m - The message to checkMessageRouter.receiveMessage(Message, DTNHost), i.e.
MessageRouter.RCV_OK if receiving seems to be OK,
TRY_LATER_BUSY if router is transferring, DENIED_OLD if the router
is already carrying the message or it has been delivered to
this router (as final recipient), or DENIED_NO_SPACE if the message
does not fit into bufferprotected boolean makeRoomForMessage(int size)
size - Size of the new message
transferred, the transfer is aborted before message is removedprotected void dropExpiredMessages()
protected void makeRoomForNewMessage(int size)
makeRoomForMessage(int) and ignores the return value.
Therefore, if the message can't fit into buffer, the buffer is only
cleared from messages that are not being sent.size - Size of the new messageprotected Message getNextMessageToRemove(boolean excludeMsgBeingSent)
excludeMsgBeingSent - If true, excludes message(s) that are
being sent from the oldest message check (i.e. if oldest message is
being sent, the second oldest message is returned)protected java.util.List<util.Tuple<Message,Connection>> getMessagesForConnected()
protected util.Tuple<Message,Connection> tryMessagesForConnected(java.util.List<util.Tuple<Message,Connection>> tuples)
tuples - The tuples to tryprotected Message tryAllMessages(Connection con, java.util.List<Message> messages)
con - Connection trough which the messages are sentmessages - A list of messages to tryprotected Connection tryMessagesToConnections(java.util.List<Message> messages, java.util.List<Connection> connections)
messages - The list of Messages to tryconnections - The list of Connections to tryprotected Connection tryAllMessagesToAllConnections()
MessageRouter.sortByQueueMode(List). See
tryMessagesToConnections(List, List) for sending details.protected Connection exchangeDeliverableMessages()
protected void shuffleMessages(java.util.List<Message> messages)
messages - The list to sort and shuffleprotected void addToSendingConnections(Connection con)
con - The connection to addupdate()public boolean isTransferring()
public boolean isSending(java.lang.String msgId)
msgId.msgId - The ID of the messagepublic boolean hasEnergy()
public void update()
update in class MessageRouteraddToSendingConnections(Connection)protected void transferAborted(Connection con)
update()
due connection going down. This happens on the sending host.
Subclasses that are interested of the event may want to override this.con - The connection whose transfer was abortedprotected void transferDone(Connection con)
update().
Subclasses that are interested of the event may want to override this.con - The connection whose transfer was finalizedpublic RoutingInfo getRoutingInfo()
MessageRoutergetRoutingInfo in class MessageRouter