|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectrouting.MessageRouter
public abstract class MessageRouter
Superclass for message routers.
Field Summary | |
---|---|
static java.lang.String |
B_SIZE_S
Message buffer size -setting id ("bufferSize"). |
static int |
DENIED_NO_SPACE
Receive return value for not enough space in the buffer for the msg |
static int |
DENIED_OLD
Receive return value for an old (already received) message |
static int |
DENIED_TTL
Receive return value for messages whose TTL has expired |
static int |
DENIED_UNSPECIFIED
Receive return value for unspecified reason |
static java.lang.String |
MSG_TTL_S
Message TTL -setting id ("msgTtl"). |
protected int |
msgTtl
TTL for all messages |
static int |
Q_MODE_FIFO
Setting value for FIFO queue mode |
static int |
Q_MODE_RANDOM
Setting value for random queue mode |
static int |
RCV_OK
Receive return value for OK |
static java.lang.String |
SEND_QUEUE_MODE_S
Message/fragment sending queue type -setting id ("sendQueue"). |
static int |
TRY_LATER_BUSY
Receive return value for busy receiver |
Constructor Summary | |
---|---|
protected |
MessageRouter(MessageRouter r)
Copy-constructor. |
|
MessageRouter(Settings s)
Constructor. |
Method Summary | |
---|---|
void |
addApplication(Application app)
Adds an application to the attached applications list. |
protected void |
addToMessages(Message m,
boolean newMessage)
Adds a message to the message buffer and informs message listeners about new message (if requested). |
abstract void |
changedConnection(Connection con)
Informs the router about change in connections state. |
protected int |
compareByQueueMode(Message m1,
Message m2)
Gives the order of the two given messages as defined by the current queue mode |
boolean |
createNewMessage(Message m)
Creates a new message to the router. |
void |
deleteMessage(java.lang.String id,
boolean drop)
Deletes a message from the buffer and informs message listeners about the event |
java.util.Collection<Application> |
getApplications(java.lang.String ID)
Returns all the applications that want to receive messages for the given application ID. |
int |
getBufferSize()
Returns the size of the message buffer. |
int |
getFreeBufferSize()
Returns the amount of free space in the buffer. |
protected DTNHost |
getHost()
Returns the host this router is in |
protected Message |
getMessage(java.lang.String id)
Returns a message by ID. |
java.util.Collection<Message> |
getMessageCollection()
Returns a reference to the messages of this router in collection. |
int |
getNrofMessages()
Returns the number of messages this router has |
RoutingInfo |
getRoutingInfo()
Returns routing information about this router. |
protected boolean |
hasMessage(java.lang.String id)
Checks if this router has a message with certain id buffered. |
void |
init(DTNHost host,
java.util.List<MessageListener> mListeners)
Initializes the router; i.e. |
protected boolean |
isDeliveredMessage(Message m)
Returns true if a full message with same ID as the given message has been received by this host as the final recipient (at least once). |
protected boolean |
isIncomingMessage(java.lang.String id)
Returns true if a message with the given ID is one of the currently incoming messages, false if not |
void |
messageAborted(java.lang.String id,
DTNHost from,
int bytesRemaining)
This method should be called (on the receiving host) when a message transfer was aborted. |
Message |
messageTransferred(java.lang.String id,
DTNHost from)
This method should be called (on the receiving host) after a message was successfully transferred. |
protected void |
putToIncomingBuffer(Message m,
DTNHost from)
Puts a message to incoming messages buffer. |
int |
receiveMessage(Message m,
DTNHost from)
Try to start receiving a message from another host. |
protected Message |
removeFromIncomingBuffer(java.lang.String id,
DTNHost from)
Removes and returns a message with a certain ID from the incoming messages buffer or null if such message wasn't found. |
protected Message |
removeFromMessages(java.lang.String id)
Removes and returns a message from the message buffer. |
abstract MessageRouter |
replicate()
Creates a replicate of this router. |
boolean |
requestDeliverableMessages(Connection con)
Requests for deliverable message from this router to be sent trough a connection. |
void |
sendMessage(java.lang.String id,
DTNHost to)
Start sending a message to another host. |
protected java.util.List |
sortByQueueMode(java.util.List list)
Sorts/shuffles the given list according to the current sending queue mode. |
java.lang.String |
toString()
Returns a String presentation of this router |
void |
update()
Updates router. |
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 B_SIZE_S
public static final java.lang.String MSG_TTL_S
public static final java.lang.String SEND_QUEUE_MODE_S
public static final int Q_MODE_RANDOM
public static final int Q_MODE_FIFO
public static final int RCV_OK
public static final int TRY_LATER_BUSY
public static final int DENIED_OLD
public static final int DENIED_NO_SPACE
public static final int DENIED_TTL
public static final int DENIED_UNSPECIFIED
protected int msgTtl
Constructor Detail |
---|
public MessageRouter(Settings s)
B_SIZE_S
setting. Default value is Integer.MAX_VALUE.
s
- The settings objectprotected MessageRouter(MessageRouter r)
r
- Router to copy the settings from.Method Detail |
---|
public void init(DTNHost host, java.util.List<MessageListener> mListeners)
host
- The host this router is inmListeners
- The message listenerspublic void update()
public abstract void changedConnection(Connection con)
con
- The connection that changedprotected Message getMessage(java.lang.String id)
id
- ID of the message
protected boolean hasMessage(java.lang.String id)
id
- Identifier of the message
protected boolean isDeliveredMessage(Message m)
m
- message we're interested of
public java.util.Collection<Message> getMessageCollection()
public int getNrofMessages()
public int getBufferSize()
public int getFreeBufferSize()
protected DTNHost getHost()
public void sendMessage(java.lang.String id, DTNHost to)
id
- Id of the message to sendto
- The host to send the message topublic boolean requestDeliverableMessages(Connection con)
con
- The connection to send the messages trough
public int receiveMessage(Message m, DTNHost from)
m
- Message to put in the receiving bufferfrom
- Who the message is from
public Message messageTransferred(java.lang.String id, DTNHost from)
id
- Id of the transferred messagefrom
- Host the message was from (previous hop)
protected void putToIncomingBuffer(Message m, DTNHost from)
m
- The message to putfrom
- Who the message was from (previous hop).protected Message removeFromIncomingBuffer(java.lang.String id, DTNHost from)
id
- ID of the messagefrom
- The host that sent this message (previous hop)
protected boolean isIncomingMessage(java.lang.String id)
id
- ID of the message
protected void addToMessages(Message m, boolean newMessage)
m
- The message to addnewMessage
- If true, message listeners are informed about a new
message, if false, nothing is informed.protected Message removeFromMessages(java.lang.String id)
id
- Identifier of the message to remove
public void messageAborted(java.lang.String id, DTNHost from, int bytesRemaining)
id
- Id of the message that was being transferredfrom
- Host the message was from (previous hop)bytesRemaining
- Nrof bytes that were left before the transfer
would have been ready; or -1 if the number of bytes is not knownpublic boolean createNewMessage(Message m)
m
- The message to create
public void deleteMessage(java.lang.String id, boolean drop)
id
- Identifier of the message to deletedrop
- If the message is dropped (e.g. because of full buffer) this
should be set to true. False value indicates e.g. remove of message
because it was delivered to final destination.protected java.util.List sortByQueueMode(java.util.List list)
list
- The list to sort or shuffle
protected int compareByQueueMode(Message m1, Message m2)
m1
- The first messagem2
- The second message
public RoutingInfo getRoutingInfo()
public void addApplication(Application app)
app
- The application to attach to this router.public java.util.Collection<Application> getApplications(java.lang.String ID)
ID
- The application ID or null
for all apps.
public abstract MessageRouter replicate()
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |