|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectrouting.MessageRouter
routing.ActiveRouter
public abstract class ActiveRouter
Superclass of active routers. Contains convenience methods (e.g.
getOldestMessage(boolean)
) and watching of sending connections (see
update()
).
Field Summary | |
---|---|
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 |
static int |
TTL_CHECK_INTERVAL
how often TTL check (discarding old messages) is performed |
Fields inherited from class routing.MessageRouter |
---|
B_SIZE_S, DENIED_NO_SPACE, DENIED_OLD, DENIED_TTL, DENIED_UNSPECIFIED, MSG_TTL_S, msgTtl, Q_MODE_FIFO, Q_MODE_RANDOM, RCV_OK, SEND_QUEUE_MODE_S, TRY_LATER_BUSY |
Constructor Summary | |
---|---|
protected |
ActiveRouter(ActiveRouter r)
Copy constructor. |
|
ActiveRouter(Settings s)
Constructor. |
Method Summary | |
---|---|
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)
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<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 |
getOldestMessage(boolean excludeMsgBeingSent)
Returns the oldest (by receive time) message in the message buffer (that is not being sent if excludeMsgBeingSent is true). |
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 Tuple<Message,Connection> |
tryMessagesForConnected(java.util.List<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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DELETE_DELIVERED_S
protected boolean deleteDelivered
public static final java.lang.String RESPONSE_PREFIX
public static int TTL_CHECK_INTERVAL
protected java.util.ArrayList<Connection> sendingConnections
Constructor Detail |
---|
public ActiveRouter(Settings s)
s
- The settings objectprotected ActiveRouter(ActiveRouter r)
r
- The router prototype where setting values are copied fromMethod Detail |
---|
public void init(DTNHost host, java.util.List<MessageListener> mListeners)
MessageRouter
init
in class MessageRouter
host
- The host this router is inmListeners
- The message listenerspublic void changedConnection(Connection con)
changedConnection
in class MessageRouter
con
- The connection that changedpublic boolean requestDeliverableMessages(Connection con)
MessageRouter
requestDeliverableMessages
in class MessageRouter
con
- The connection to send the messages trough
public boolean createNewMessage(Message m)
MessageRouter
createNewMessage
in class MessageRouter
m
- The message to create
public int receiveMessage(Message m, DTNHost from)
MessageRouter
receiveMessage
in class MessageRouter
m
- Message to put in the receiving bufferfrom
- Who the message is from
public Message messageTransferred(java.lang.String id, DTNHost from)
MessageRouter
messageTransferred
in class MessageRouter
id
- 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 use
Connection.startTransfer(DTNHost, Message)
protected boolean canStartTransfer()
protected int checkReceiving(Message m)
m
- The message to check
MessageRouter.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 removed
protected 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 getOldestMessage(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<Tuple<Message,Connection>> getMessagesForConnected()
protected Tuple<Message,Connection> tryMessagesForConnected(java.util.List<Tuple<Message,Connection>> tuples)
tuples
- The tuples to try
protected Message tryAllMessages(Connection con, java.util.List<Message> messages)
con
- Connection trough which the messages are sentmessages
- A list of messages to try
protected Connection tryMessagesToConnections(java.util.List<Message> messages, java.util.List<Connection> connections)
messages
- The list of Messages to tryconnections
- The list of Connections to try
protected 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 message
public void update()
update
in class MessageRouter
addToSendingConnections(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 finalized
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |