public class DelayMessageEngine extends DefaultMessageEngine
The DelayMessageEngine
is responsible for the regular transmission of the available
Messages
from any sender Node
of the Topology
to their destination.
By default, Messages
sent during round n are delivered at the beginning of round
n+1; provided that the corresponding arc (a Link
going, at least, from the
Message
's source Node
to its destination) actually exists at the beginning of round n+1.
The previously explained default delivery duration (DEFAULT_DELAY
) is said instantaneous
(DELAY_INSTANT
).
The DelayMessageEngine
allows you to modify this duration by specifying the
amount of rounds Messages
should take to be delivered, using setDelay(int)
.
Link
checksBy default, each round, the DelayMessageEngine
checks for each Message
that the corresponding Link
is still present. If not, the Message
is dropped.
The time spent doing this rises with the delay and the number of Nodes
and Messages
.
Depending on your case, you might want to disable this using disableLinksContinuityChecks()
.
Modifier and Type | Field and Description |
---|---|
protected int |
currentTime |
static int |
DEFAULT_DELAY
The default number of round before message delivery; value: 1.
|
static int |
DELAY_INSTANT
The delay value to use for the shortest delivery time possible; value: 1.
|
protected Map<Integer,List<Message>> |
delayedMessages |
debug, topology
Constructor and Description |
---|
DelayMessageEngine(Topology topology)
Creates a
DelayMessageEngine . |
DelayMessageEngine(Topology topology,
int delay)
Creates a
DelayMessageEngine . |
Modifier and Type | Method and Description |
---|---|
protected void |
cacheMessageAtTime(Map<Integer,List<Message>> messagesMap,
Message message,
int deliveryTime)
Caches a specific
Message at it's planned delivery time (round number). |
protected void |
cacheMessagesAtTime(List<Message> messages,
int deliveryTime)
|
protected void |
cacheNewMessages(List<Message> messages)
|
void |
disableLinksContinuityChecks()
|
protected int |
getCurrentDeliveryDate()
Computes the delivery date (round number) for a
Message collected at the start of the current
round. |
int |
getDelay()
Gets the number of round a message should be delayed.
|
protected int |
getDelayForMessage(Message message)
Computes the delay which should be applied to the provided
Message . |
protected List<Message> |
getMessagesForCurrentDate()
Retrieves the list of
Messages which should be delivered during the current round, from the
internal storage. |
protected List<Message> |
getMessagesToSend(List<Message> newMessages,
Collection<Node> existingNodes)
|
protected boolean |
noCachingNeeded(List<Message> newMessages)
Tests whether the provided list of
Messages should be cached or not. |
void |
onClock()
Method responsible for the delivery of the
Messages . |
protected Map<Integer,List<Message>> |
prepareNewMessagesForCaching(List<Message> newMessages)
|
protected void |
removeIrrelevantMessages(Collection<Node> existingNodes)
Removes any irrelevant messages from the cached delayed messages, according to the
Collection of
existing Nodes . |
void |
reset()
Resets the
DelayMessageEngine . |
void |
setDelay(int delay)
Sets the number of round a message should be delayed.
|
void |
setSpeed(int speed)
Deprecated.
Please use
setDelay(int) instead. |
boolean |
shouldCheckLinksContinuity()
|
clearMailboxes, clearMailboxes, clearSendQueues, clearSendQueues, collectMessages, collectMessages, collectMessages, deliverMessage, deliverMessages, isMessageStillRelevant, removeIrrelevantMessages, removeNextMessageIfIrrelevant, requeueIfNeeded, requeueMessage, setDebug, setTopology
public static final int DELAY_INSTANT
setDelay(int)
,
getDelay()
,
Constant Field Valuespublic static final int DEFAULT_DELAY
setDelay(int)
,
getDelay()
,
Constant Field Valuesprotected int currentTime
public DelayMessageEngine(Topology topology)
Creates a DelayMessageEngine
.
By default, the messages sent during one round are actually during the next.
topology
- the Topology
to use.public DelayMessageEngine(Topology topology, int delay)
Creates a DelayMessageEngine
.
topology
- the Topology
to use.delay
- the number of round a message should be delayed, as an integer.@Deprecated public void setSpeed(int speed)
setDelay(int)
instead.Sets the number of round a message should be delayed.
speed
- the number of round a message should be delayed, as an integer.public void setDelay(int delay)
Sets the number of round a message should be delayed.
Any value below DELAY_INSTANT
(i.e. 1) will be replaced by
DELAY_INSTANT
.
delay
- the number of round a message should be delayed, as an integer.getDelay()
public int getDelay()
Gets the number of round a message should be delayed.
setDelay(int)
public boolean shouldCheckLinksContinuity()
Specifies whether a Message
should be removed if the corresponding Link
disappears at some
point during its waiting delay.
Note: Whatever the status, the link presence will be checked at sending time and delivery time.
true
if intermediate checks and removal should be performed; false
otherwise.disableLinksContinuityChecks()
public void disableLinksContinuityChecks()
shouldCheckLinksContinuity()
public void onClock()
MessageEngine
onClock
in interface MessageEngine
onClock
in class DefaultMessageEngine
protected List<Message> getMessagesToSend(List<Message> newMessages, Collection<Node> existingNodes)
protected boolean noCachingNeeded(List<Message> newMessages)
Tests whether the provided list of Messages
should be cached or not.
protected void removeIrrelevantMessages(Collection<Node> existingNodes)
Removes any irrelevant messages from the cached delayed messages, according to the Collection
of
existing Nodes
.
existingNodes
- the Collection
of existing Nodes
.DefaultMessageEngine.removeIrrelevantMessages(ListIterator, Collection)
protected void cacheNewMessages(List<Message> messages)
messages
- a List
containing new Messages
.prepareNewMessagesForCaching(List)
,
cacheMessagesAtTime(List, int)
protected Map<Integer,List<Message>> prepareNewMessagesForCaching(List<Message> newMessages)
protected void cacheMessageAtTime(Map<Integer,List<Message>> messagesMap, Message message, int deliveryTime)
Caches a specific Message
at it's planned delivery time (round number).
protected List<Message> getMessagesForCurrentDate()
Retrieves the list of Messages
which should be delivered during the current round, from the
internal storage.
protected int getDelayForMessage(Message message)
Computes the delay which should be applied to the provided Message
.
message
- the Message
needing a delay.protected int getCurrentDeliveryDate()
Computes the delivery date (round number) for a Message
collected at the start of the current
round.
public void reset()
Resets the DelayMessageEngine
.
Message
(ready to be sent, "in the air" or ready to be received) handled by the
DelayMessageEngine
is discarded.reset
in interface MessageEngine
reset
in class DefaultMessageEngine