vanetsim.scenario
Class KnownMessages

java.lang.Object
  extended by vanetsim.scenario.KnownMessages

public class KnownMessages
extends java.lang.Object

This class stores various messages in multiple separate arrays:

The arrays are not resized on every operation. Deletion of an element only changes the corresponding size variable, addition only leads to a larger array if there's not enough space left.


Constructor Summary
KnownMessages()
           
KnownMessages(Vehicle vehicle)
          Constructor.
 
Method Summary
 void addMessage(Message message, boolean doExecute, boolean doForward)
          Adds a message.
 void checkOutdatedMessages(boolean addToOld)
          Checks for outdated messages and deletes them.
 void clear()
          Clears everything from this data structure.
 void deleteAllFloodingForwardMessages(boolean addToOld)
          Deletes all forward messages which are in flooding/broadcast mode and optionally adds them to the old messages.
 void deleteAllForwardMessages(boolean addToOld)
          Deletes all forward messages and optionally adds them to the old messages.
 void deleteForwardMessage(int position, boolean addToOld)
          Deletes a forward message and optionally adds it to the old messages.
 int getFailedForwardCount()
          Gets the amount of messages which failed to be forwarded.
 Message[] getForwardMessages()
          Gets all messages which shall be forwarded.
 int getOldMessagesSize()
          Gets the amount of old messages stored.
 int getSize()
          Gets the amount of known messages stored (=forward messages).
 boolean hasNewMessages()
          Returns if there are news messages which need to be processed.
 void processMessages()
          Process messages.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KnownMessages

public KnownMessages(Vehicle vehicle)
Constructor.

Parameters:
vehicle - the vehicle this data structure belongs to

KnownMessages

public KnownMessages()
Method Detail

addMessage

public void addMessage(Message message,
                       boolean doExecute,
                       boolean doForward)
Adds a message.

Parameters:
message - the message
doExecute - true if you want the message to be executed, else false
doForward - true if you want the message to be forwarded, else false

deleteForwardMessage

public void deleteForwardMessage(int position,
                                 boolean addToOld)
Deletes a forward message and optionally adds it to the old messages.

Parameters:
position - the position
addToOld - true to add it to the old messages, else false

deleteAllForwardMessages

public void deleteAllForwardMessages(boolean addToOld)
Deletes all forward messages and optionally adds them to the old messages.

Parameters:
addToOld - true to add all to the old messages, else false

deleteAllFloodingForwardMessages

public void deleteAllFloodingForwardMessages(boolean addToOld)
Deletes all forward messages which are in flooding/broadcast mode and optionally adds them to the old messages.

Parameters:
addToOld - true to add the removed flooding messages to the old messages, else false

processMessages

public void processMessages()
Process messages. Note that this function is not synchronized! You need to make sure that no other thread uses any function on this object at the same time!


checkOutdatedMessages

public void checkOutdatedMessages(boolean addToOld)
Checks for outdated messages and deletes them. Note that this function is not synchronized! You need to make sure that no other thread uses any function on this object at the same time!

Parameters:
addToOld - true to add all to outdated forward messages to the old messages, else false

getForwardMessages

public Message[] getForwardMessages()
Gets all messages which shall be forwarded. Note that there might be garbage at the end so use the getSize()-methode to get the real size!

Returns:
the array with all messages

hasNewMessages

public boolean hasNewMessages()
Returns if there are news messages which need to be processed.

Returns:
true if there are new messages, else false

getSize

public int getSize()
Gets the amount of known messages stored (=forward messages).

Returns:
the size

getOldMessagesSize

public int getOldMessagesSize()
Gets the amount of old messages stored.

Returns:
the size

getFailedForwardCount

public int getFailedForwardCount()
Gets the amount of messages which failed to be forwarded.

Returns:
the size

clear

public void clear()
Clears everything from this data structure.