|
|||||||||
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
identifier for the buffer size setting ("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 java.lang.String |
MSG_TTL
identifier for the message TTL setting ("msgTtl"). |
protected int |
msgTtl
TTL for all messages |
static int |
RCV_OK
Receive return value for ok |
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 | |
---|---|
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. |
boolean |
createNewMessage(DTNHost to,
java.lang.String id,
int size,
int responseSize)
Creates a new message to the router. |
void |
deleteMessage(java.lang.String id,
boolean drop)
Deletes a message in the buffer. |
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(java.lang.String id)
Returns true if a message with given id has been received by this host as the final recipient (at least once). |
void |
messageAborted(java.lang.String id,
DTNHost from)
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. |
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. |
java.lang.String |
toString()
Returns a String presentation of this router |
abstract 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
public static final java.lang.String MSG_TTL
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
protected int msgTtl
Constructor Detail |
---|
public MessageRouter(Settings s)
B_SIZE
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 abstract 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(java.lang.String id)
id
- ID of the message we're interested
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 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.public void messageAborted(java.lang.String id, DTNHost from)
id
- Id of the message that was being transferredfrom
- Host the message was from (previous hop)public boolean createNewMessage(DTNHost to, java.lang.String id, int size, int responseSize)
to
- The host the message is toid
- Identifier of the message (should be unique). A message
with non-unique ID will replace an old message with the same ID
in this node's buffer and other nodes may reject the message because
they have "seen" a message with that ID before.size
- Size of the message (in bytes)responseSize
- Size of the requested response message or 0 if no
response is requested
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.public RoutingInfo getRoutingInfo()
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 |