public class AsyncMessageEngine extends DelayMessageEngine
The AsyncMessageEngine
is an asynchronous alternative to JBotSim's default MessageEngine
.
It is made to work either as AsyncMessageEngine.Type.FIFO
or AsyncMessageEngine.Type.NONFIFO
. Currently, for each new message:
AsyncMessageEngine.Type.NONFIFO
mode uses the provided average duration to compute the delay (f
function discussed thereafter);AsyncMessageEngine.Type.FIFO
mode also uses the f
function to compute a theoretical delay, but also
takes the current maximum delay time between the two nodes in order to guaranty a proper FIFO behavior.In both cases, the f
function used to draw the random delay, which follows an exponential
distribution law of rate 1./
, is computed as such:getAverageDuration()
f(r) = -log(1-r) *
, where getAverageDuration()
r
is a value
returned by Math.random()
.
Modifier and Type | Class and Description |
---|---|
static class |
AsyncMessageEngine.Type
Delivery queue type.
|
Modifier and Type | Field and Description |
---|---|
protected int |
averageDuration |
static int |
DEFAULT_AVERAGE_DURATION
The default average duration; value: 10.
|
static AsyncMessageEngine.Type |
DEFAULT_TYPE
The default delivery queue type; value:
AsyncMessageEngine.Type.FIFO . |
protected AsyncMessageEngine.Type |
type |
currentTime, DEFAULT_DELAY, DELAY_INSTANT, delayedMessages
debug, topology
Constructor and Description |
---|
AsyncMessageEngine(Topology topology)
Creates a
AsyncMessageEngine object. |
AsyncMessageEngine(Topology topology,
int averageDuration,
AsyncMessageEngine.Type type)
Creates a
AsyncMessageEngine object. |
Modifier and Type | Method and Description |
---|---|
protected int |
computeDelayFunction(int lambda)
Computes the next value for the delay function.
|
protected int |
drawDelayFIFO(Message message)
Draws a delay for the provided
Message , in the FIFO case. |
protected int |
drawDelayNONFIFO(Message message)
Draws a delay for the provided
Message , in the non-FIFO case. |
int |
getAverageDuration()
Gets the desired average number of rounds needed for a message to be delivered to its destination.
|
protected int |
getCurrentMaximumDeliveryDate(Node sender,
Node destination)
Retrieves the current maximum delivery date for messages between the provided sender and destination.
|
int |
getDelay()
Deprecated.
|
protected int |
getDelayForMessage(Message message)
Computes the delay which should be applied to the provided
Message . |
protected int |
getDeliveryDateForMessage(Message message)
Computes the delivery date (round number) for the provided
Message . |
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)
|
void |
setAverageDuration(int averageDuration)
Sets the desired average number of rounds needed for a message to be delivered to its destination.
|
void |
setDelay(int delay)
Deprecated.
|
protected boolean |
shouldCleanDeliveryDates() |
cacheMessageAtTime, cacheMessagesAtTime, cacheNewMessages, disableLinksContinuityChecks, getCurrentDeliveryDate, getMessagesForCurrentDate, getMessagesToSend, removeIrrelevantMessages, reset, setSpeed, shouldCheckLinksContinuity
clearMailboxes, clearMailboxes, clearSendQueues, clearSendQueues, collectMessages, collectMessages, collectMessages, deliverMessage, deliverMessages, isMessageStillRelevant, removeIrrelevantMessages, removeNextMessageIfIrrelevant, requeueIfNeeded, requeueMessage, setDebug, setTopology
public static final int DEFAULT_AVERAGE_DURATION
public static final AsyncMessageEngine.Type DEFAULT_TYPE
AsyncMessageEngine.Type.FIFO
.protected int averageDuration
protected AsyncMessageEngine.Type type
public AsyncMessageEngine(Topology topology)
Creates a AsyncMessageEngine
object.
The default used are:
DEFAULT_AVERAGE_DURATION
as default average duration;DEFAULT_TYPE
as default type.topology
- the Topology
to use.public AsyncMessageEngine(Topology topology, int averageDuration, AsyncMessageEngine.Type type)
Creates a AsyncMessageEngine
object.
topology
- the Topology
to use.averageDuration
- the desired average number of rounds needed for a message to be delivered to its
destination, as an integer.type
- the AsyncMessageEngine.Type
of the delivery queue.public void onClock()
MessageEngine
onClock
in interface MessageEngine
onClock
in class DelayMessageEngine
protected boolean shouldCleanDeliveryDates()
protected boolean noCachingNeeded(List<Message> newMessages)
DelayMessageEngine
Tests whether the provided list of Messages
should be cached or not.
noCachingNeeded
in class DelayMessageEngine
newMessages
- a List
containing new Messages
.true
if the provided messages should not be cached.protected Map<Integer,List<Message>> prepareNewMessagesForCaching(List<Message> newMessages)
DelayMessageEngine
prepareNewMessagesForCaching
in class DelayMessageEngine
newMessages
- a List
containing new Messages
.Map
containing Lists
of Messages
indexed by the date at which they
should be delivered.DelayMessageEngine.getCurrentDeliveryDate()
protected int getDeliveryDateForMessage(Message message)
Computes the delivery date (round number) for the provided Message
.
message
- the Message
needing a delivery date.protected int getCurrentMaximumDeliveryDate(Node sender, Node destination)
Retrieves the current maximum delivery date for messages between the provided sender and destination.
protected int getDelayForMessage(Message message)
DelayMessageEngine
Computes the delay which should be applied to the provided Message
.
getDelayForMessage
in class DelayMessageEngine
message
- the Message
needing a delay.protected int drawDelayNONFIFO(Message message)
Draws a delay for the provided Message
, in the non-FIFO case.
message
- the Message
needing a delay.protected int drawDelayFIFO(Message message)
Draws a delay for the provided Message
, in the FIFO case.
message
- the Message
needing a delay.protected int computeDelayFunction(int lambda)
Computes the next value for the delay function.
lambda
- the lambda parameter, as an integer.public int getAverageDuration()
public void setAverageDuration(int averageDuration)
averageDuration
- the desired average number of rounds needed for a message to be delivered to its
destination, as an Integer.@Deprecated public void setDelay(int delay)
setAverageDuration(int)
.setDelay
in class DelayMessageEngine
delay
- the number of round a message should be delayed, as an integer.setAverageDuration(int)
@Deprecated public int getDelay()
getAverageDuration()
.getDelay
in class DelayMessageEngine
getAverageDuration()