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, int ttl)
          Creates a new Message.
 
Method Summary
 void addNodeOnPath(DTNHost node)
          Adds a new node on the list of nodes this message has passed
 int compareTo(Message m)
          Compares two messages by their ID (alphabetically).
protected  void copyFrom(Message m)
          Deep copies message data from other message.
 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
 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 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.
 java.lang.String toString()
          Returns a string representation of the message
 
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,
               int ttl)
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)
ttl - Time-to-live (minutes) of this message, or INFINITE_TTL for infinite time
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)

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

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