core
Class Message

java.lang.Object
  extended by core.Message
All Implemented Interfaces:
java.lang.Comparable<Message>

public class Message
extends java.lang.Object
implements java.lang.Comparable<Message>

A message that is created at a node or passed between nodes.


Field Summary
static int INFINITE_TTL
          Value for infinite TTL of message
 
Constructor Summary
Message(DTNHost from, DTNHost to, java.lang.String id, int size)
          Creates a new Message.
 
Method Summary
 void addNodeOnPath(DTNHost node)
          Adds a new node on the list of nodes this message has passed
 void addProperty(java.lang.String key, java.lang.Object value)
          Adds a generic property for this message.
 int compareTo(Message m)
          Compares two messages by their ID (alphabetically).
protected  void copyFrom(Message m)
          Deep copies message data from other message.
 java.lang.String getAppID()
           
 double getCreationTime()
          Returns the time when this message was created
 DTNHost getFrom()
          Returns the node this message is originally from
 int getHopCount()
          Returns the amount of hops this message has passed
 java.util.List<DTNHost> getHops()
          Returns a list of nodes this message has passed so far
 java.lang.String getId()
          Returns the ID of the message
 java.lang.Object getProperty(java.lang.String key)
          Returns an object that was stored to this message using the given key.
 double getReceiveTime()
          Returns the time when this message was received
 Message getRequest()
          Returns the message this message is response to or null if this is not a response message
 int getResponseSize()
          Returns the size of the requested response message or 0 if no response is requested.
 int getSize()
          Returns the size of the message (in bytes)
 DTNHost getTo()
          Returns the node this message is originally to
 int getTtl()
          Returns the time to live (minutes) of the message or Integer.MAX_VALUE if the TTL is infinite.
 int getUniqueId()
          Returns an ID that is unique per message instance (different for replicates too)
 boolean isResponse()
          Returns true if this message is a response message
 Message replicate()
          Returns a replicate of this message (identical except for the unique id)
static void reset()
          Resets all static fields to default values
 void setAppID(java.lang.String appID)
           
 void setReceiveTime(double time)
          Sets the time when this message was received.
 void setRequest(Message request)
          If this message is a response to a request, sets the request message
 void setResponseSize(int size)
          Sets the requested response message's size.
 void setTtl(int ttl)
          Sets the initial TTL (time-to-live) for this message.
 java.lang.String toString()
          Returns a string representation of the message
 void updateProperty(java.lang.String key, java.lang.Object value)
          Updates a value for an existing property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INFINITE_TTL

public static final int INFINITE_TTL
Value for infinite TTL of message

See Also:
Constant Field Values
Constructor Detail

Message

public Message(DTNHost from,
               DTNHost to,
               java.lang.String id,
               int size)
Creates a new Message.

Parameters:
from - Who the message is (originally) from
to - Who the message is (originally) to
id - Message identifier (must be unique for message but will be the same for all replicates of the message)
size - Size of the message (in bytes)
Method Detail

getFrom

public DTNHost getFrom()
Returns the node this message is originally from

Returns:
the node this message is originally from

getTo

public DTNHost getTo()
Returns the node this message is originally to

Returns:
the node this message is originally to

getId

public java.lang.String getId()
Returns the ID of the message

Returns:
The message id

getUniqueId

public int getUniqueId()
Returns an ID that is unique per message instance (different for replicates too)

Returns:
The unique id

getSize

public int getSize()
Returns the size of the message (in bytes)

Returns:
the size of the message

addNodeOnPath

public void addNodeOnPath(DTNHost node)
Adds a new node on the list of nodes this message has passed

Parameters:
node - The node to add

getHops

public java.util.List<DTNHost> getHops()
Returns a list of nodes this message has passed so far

Returns:
The list as vector

getHopCount

public int getHopCount()
Returns the amount of hops this message has passed

Returns:
the amount of hops this message has passed

getTtl

public int getTtl()
Returns the time to live (minutes) of the message or Integer.MAX_VALUE if the TTL is infinite. Returned value can be negative if the TTL has passed already.

Returns:
The TTL (minutes)

setTtl

public void setTtl(int ttl)
Sets the initial TTL (time-to-live) for this message. The initial TTL is the TTL when the original message was created. The current TTL is calculated based on the time of

Parameters:
ttl - The time-to-live to set

setReceiveTime

public void setReceiveTime(double time)
Sets the time when this message was received.

Parameters:
time - The time to set

getReceiveTime

public double getReceiveTime()
Returns the time when this message was received

Returns:
The time

getCreationTime

public double getCreationTime()
Returns the time when this message was created

Returns:
the time when this message was created

setRequest

public void setRequest(Message request)
If this message is a response to a request, sets the request message

Parameters:
request - The request message

getRequest

public Message getRequest()
Returns the message this message is response to or null if this is not a response message

Returns:
the message this message is response to

isResponse

public boolean isResponse()
Returns true if this message is a response message

Returns:
true if this message is a response message

setResponseSize

public void setResponseSize(int size)
Sets the requested response message's size. If size == 0, no response is requested (default)

Parameters:
size - Size of the response message

getResponseSize

public int getResponseSize()
Returns the size of the requested response message or 0 if no response is requested.

Returns:
the size of the requested response message

toString

public java.lang.String toString()
Returns a string representation of the message

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the message

copyFrom

protected void copyFrom(Message m)
Deep copies message data from other message. If new fields are introduced to this class, most likely they should be copied here too (unless done in constructor).

Parameters:
m - The message where the data is copied

addProperty

public void addProperty(java.lang.String key,
                        java.lang.Object value)
                 throws SimError
Adds a generic property for this message. The key can be any string but it should be such that no other class accidently uses the same value. The value can be any object but it's good idea to store only immutable objects because when message is replicated, only a shallow copy of the properties is made.

Parameters:
key - The key which is used to lookup the value
value - The value to store
Throws:
SimError - if the message already has a value for the given key

getProperty

public java.lang.Object getProperty(java.lang.String key)
Returns an object that was stored to this message using the given key. If such object is not found, null is returned.

Parameters:
key - The key used to lookup the object
Returns:
The stored object or null if it isn't found

updateProperty

public void updateProperty(java.lang.String key,
                           java.lang.Object value)
                    throws SimError
Updates a value for an existing property. For storing the value first time, addProperty(String, Object) should be used which checks for name space clashes.

Parameters:
key - The key which is used to lookup the value
value - The new value to store
Throws:
SimError

replicate

public Message replicate()
Returns a replicate of this message (identical except for the unique id)

Returns:
A replicate of the message

compareTo

public int compareTo(Message m)
Compares two messages by their ID (alphabetically).

Specified by:
compareTo in interface java.lang.Comparable<Message>
See Also:
String.compareTo(String)

reset

public static void reset()
Resets all static fields to default values


getAppID

public java.lang.String getAppID()
Returns:
the appID

setAppID

public void setAppID(java.lang.String appID)
Parameters:
appID - the appID to set