public class MessageDispatcher extends Object implements Telegraph
MessageDispatcher is in charge of the creation, dispatch, and management of telegrams.| Modifier and Type | Class and Description |
|---|---|
static interface |
MessageDispatcher.PendingMessageCallback
A
PendingMessageCallback is used by the scanQueue method
of the MessageDispatcher to report its pending messages individually. |
| Constructor and Description |
|---|
MessageDispatcher()
Creates a
MessageDispatcher |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(Telegraph listener,
int msg)
Registers a listener for the specified message code.
|
void |
addListeners(Telegraph listener,
int... msgs)
Registers a listener for a selection of message types.
|
void |
addProvider(TelegramProvider provider,
int msg)
Registers a provider for the specified message code.
|
void |
addProviders(TelegramProvider provider,
int... msgs)
Registers a provider for a selection of message types.
|
void |
clear()
Removes all the telegrams from the queue and the registered listeners for all the messages.
|
void |
clearListeners()
Removes all the registered listeners for all the message codes.
|
void |
clearListeners(int... msgs)
Unregisters all the listeners for the given message codes.
|
void |
clearListeners(int msg)
Unregisters all the listeners for the specified message code.
|
void |
clearProviders()
Removes all the registered providers for all the message codes.
|
void |
clearProviders(int... msgs)
Unregisters all the providers for the given message codes.
|
void |
clearProviders(int msg)
Unregisters all the providers for the specified message code.
|
void |
clearQueue()
Removes all the telegrams from the queue and releases them to the internal pool.
|
void |
dispatchMessage(float delay,
int msg)
Sends a message to all registered listeners, with the specified delay but no extra info.
|
void |
dispatchMessage(float delay,
int msg,
Object extraInfo)
Sends a message to all registered listeners, with the specified delay and extra info.
|
void |
dispatchMessage(float delay,
Telegraph sender,
int msg)
Sends a message to all registered listeners, with the specified delay but no extra info.
|
void |
dispatchMessage(float delay,
Telegraph sender,
int msg,
boolean needsReturnReceipt)
Sends a message to all registered listeners, with the specified delay but no extra info.
|
void |
dispatchMessage(float delay,
Telegraph sender,
int msg,
Object extraInfo)
Sends a message to all registered listeners, with the specified delay and extra info.
|
void |
dispatchMessage(float delay,
Telegraph sender,
int msg,
Object extraInfo,
boolean needsReturnReceipt)
Sends a message to all registered listeners, with the specified delay and extra info.
|
void |
dispatchMessage(float delay,
Telegraph sender,
Telegraph receiver,
int msg)
Sends a message to the specified receiver, with the specified delay but no extra info.
|
void |
dispatchMessage(float delay,
Telegraph sender,
Telegraph receiver,
int msg,
boolean needsReturnReceipt)
Sends a message to the specified receiver, with the specified delay but no extra info.
|
void |
dispatchMessage(float delay,
Telegraph sender,
Telegraph receiver,
int msg,
Object extraInfo)
Sends a message to the specified receiver, with the specified delay but no extra info.
|
void |
dispatchMessage(float delay,
Telegraph sender,
Telegraph receiver,
int msg,
Object extraInfo,
boolean needsReturnReceipt)
Given a message, a receiver, a sender and any time delay, this method routes the message to the correct agents (if no delay)
or stores in the message queue to be dispatched at the correct time.
|
void |
dispatchMessage(int msg)
Sends an immediate message to all registered listeners, with no extra info.
|
void |
dispatchMessage(int msg,
Object extraInfo)
Sends an immediate message to all registered listeners, with extra info.
|
void |
dispatchMessage(Telegraph sender,
int msg)
Sends an immediate message to all registered listeners, with no extra info.
|
void |
dispatchMessage(Telegraph sender,
int msg,
boolean needsReturnReceipt)
Sends an immediate message to all registered listeners, with no extra info.
|
void |
dispatchMessage(Telegraph sender,
int msg,
Object extraInfo)
Sends an immediate message to all registered listeners, with extra info.
|
void |
dispatchMessage(Telegraph sender,
int msg,
Object extraInfo,
boolean needsReturnReceipt)
Sends an immediate message to all registered listeners, with extra info.
|
void |
dispatchMessage(Telegraph sender,
Telegraph receiver,
int msg)
Sends an immediate message to the specified receiver with no extra info.
|
void |
dispatchMessage(Telegraph sender,
Telegraph receiver,
int msg,
boolean needsReturnReceipt)
Sends an immediate message to the specified receiver with no extra info.
|
void |
dispatchMessage(Telegraph sender,
Telegraph receiver,
int msg,
Object extraInfo)
Sends an immediate message to the specified receiver with extra info.
|
void |
dispatchMessage(Telegraph sender,
Telegraph receiver,
int msg,
Object extraInfo,
boolean needsReturnReceipt)
Sends an immediate message to the specified receiver with extra info.
|
boolean |
handleMessage(Telegram msg)
Handles the telegram just received.
|
boolean |
isDebugEnabled()
Returns true if debug mode is on; false otherwise.
|
void |
removeListener(Telegraph listener,
int... msgs)
Unregister the specified listener for the selection of message codes.
|
void |
removeListener(Telegraph listener,
int msg)
Unregister the specified listener for the specified message code.
|
void |
scanQueue(MessageDispatcher.PendingMessageCallback callback)
Scans the queue and passes pending messages to the given callback in any particular order.
|
void |
setDebugEnabled(boolean debugEnabled)
Sets debug mode on/off.
|
void |
update()
Dispatches any delayed telegrams with a timestamp that has expired.
|
public boolean isDebugEnabled()
public void setDebugEnabled(boolean debugEnabled)
public void addListener(Telegraph listener, int msg)
listener - the listener to addmsg - the message codepublic void addListeners(Telegraph listener, int... msgs)
listener - the listener to addmsgs - the message codespublic void addProvider(TelegramProvider provider, int msg)
msg - the message codeprovider - the provider to addpublic void addProviders(TelegramProvider provider, int... msgs)
provider - the provider to addmsgs - the message codespublic void removeListener(Telegraph listener, int msg)
listener - the listener to removemsg - the message codepublic void removeListener(Telegraph listener, int... msgs)
listener - the listener to removemsgs - the message codespublic void clearListeners(int msg)
msg - the message codepublic void clearListeners(int... msgs)
msgs - the message codespublic void clearListeners()
public void clearProviders(int msg)
msg - the message codepublic void clearProviders(int... msgs)
msgs - the message codespublic void clearProviders()
public void clearQueue()
public void clear()
public void dispatchMessage(int msg)
This is a shortcut method for dispatchMessage(0,
null, null, msg, null, false)
msg - the message codepublic void dispatchMessage(Telegraph sender, int msg)
This is a shortcut method for dispatchMessage(0,
sender, null, msg, null, false)
sender - the sender of the telegrammsg - the message codepublic void dispatchMessage(Telegraph sender, int msg, boolean needsReturnReceipt)
This is a shortcut method for dispatchMessage(0,
sender, null, msg, null, needsReturnReceipt)
sender - the sender of the telegrammsg - the message codeneedsReturnReceipt - whether the return receipt is needed or notIllegalArgumentException - if the sender is null and the return receipt is neededpublic void dispatchMessage(int msg,
Object extraInfo)
This is a shortcut method for dispatchMessage(0,
null, null, msg, extraInfo, false)
msg - the message codeextraInfo - an optional objectpublic void dispatchMessage(Telegraph sender, int msg, Object extraInfo)
This is a shortcut method for dispatchMessage(0,
sender, null, msg, extraInfo, false)
sender - the sender of the telegrammsg - the message codeextraInfo - an optional objectpublic void dispatchMessage(Telegraph sender, int msg, Object extraInfo, boolean needsReturnReceipt)
This is a shortcut method for dispatchMessage(0,
sender, null, msg, extraInfo, needsReturnReceipt)
sender - the sender of the telegrammsg - the message codeextraInfo - an optional objectneedsReturnReceipt - whether the return receipt is needed or notIllegalArgumentException - if the sender is null and the return receipt is neededpublic void dispatchMessage(Telegraph sender, Telegraph receiver, int msg)
This is a shortcut method for dispatchMessage(0,
sender, receiver, msg, null, false)
sender - the sender of the telegramreceiver - the receiver of the telegram; if it's null the telegram is broadcasted to all the receivers
registered for the specified message codemsg - the message codepublic void dispatchMessage(Telegraph sender, Telegraph receiver, int msg, boolean needsReturnReceipt)
This is a shortcut method for dispatchMessage(0,
sender, receiver, msg, null, needsReturnReceipt)
sender - the sender of the telegramreceiver - the receiver of the telegram; if it's null the telegram is broadcasted to all the receivers
registered for the specified message codemsg - the message codeneedsReturnReceipt - whether the return receipt is needed or notIllegalArgumentException - if the sender is null and the return receipt is neededpublic void dispatchMessage(Telegraph sender, Telegraph receiver, int msg, Object extraInfo)
This is a shortcut method for dispatchMessage(0,
sender, receiver, msg, extraInfo, false)
sender - the sender of the telegramreceiver - the receiver of the telegram; if it's null the telegram is broadcasted to all the receivers
registered for the specified message codemsg - the message codeextraInfo - an optional objectpublic void dispatchMessage(Telegraph sender, Telegraph receiver, int msg, Object extraInfo, boolean needsReturnReceipt)
This is a shortcut method for dispatchMessage(0,
sender, receiver, msg, extraInfo, needsReturnReceipt)
sender - the sender of the telegramreceiver - the receiver of the telegram; if it's null the telegram is broadcasted to all the receivers
registered for the specified message codemsg - the message codeextraInfo - an optional objectneedsReturnReceipt - whether the return receipt is needed or notIllegalArgumentException - if the sender is null and the return receipt is neededpublic void dispatchMessage(float delay,
int msg)
This is a shortcut method for dispatchMessage(delay, null, null, msg, null, null)
delay - the delay in secondsmsg - the message codepublic void dispatchMessage(float delay,
Telegraph sender,
int msg)
This is a shortcut method for dispatchMessage(delay, sender, null, msg, null, false)
delay - the delay in secondssender - the sender of the telegrammsg - the message codepublic void dispatchMessage(float delay,
Telegraph sender,
int msg,
boolean needsReturnReceipt)
This is a shortcut method for dispatchMessage(delay, sender, null, msg, null, needsReturnReceipt)
delay - the delay in secondssender - the sender of the telegrammsg - the message codeneedsReturnReceipt - whether the return receipt is needed or notIllegalArgumentException - if the sender is null and the return receipt is neededpublic void dispatchMessage(float delay,
int msg,
Object extraInfo)
This is a shortcut method for dispatchMessage(delay, null, null, msg, extraInfo, false)
delay - the delay in secondsmsg - the message codeextraInfo - an optional objectpublic void dispatchMessage(float delay,
Telegraph sender,
int msg,
Object extraInfo)
This is a shortcut method for dispatchMessage(delay, sender, null, msg, extraInfo, false)
delay - the delay in secondssender - the sender of the telegrammsg - the message codeextraInfo - an optional objectpublic void dispatchMessage(float delay,
Telegraph sender,
int msg,
Object extraInfo,
boolean needsReturnReceipt)
This is a shortcut method for dispatchMessage(delay, sender, null, msg, extraInfo, needsReturnReceipt)
delay - the delay in secondssender - the sender of the telegrammsg - the message codeextraInfo - an optional objectneedsReturnReceipt - whether the return receipt is needed or notIllegalArgumentException - if the sender is null and the return receipt is neededpublic void dispatchMessage(float delay,
Telegraph sender,
Telegraph receiver,
int msg)
This is a shortcut method for dispatchMessage(delay, sender, receiver, msg, null, false)
delay - the delay in secondssender - the sender of the telegramreceiver - the receiver of the telegram; if it's null the telegram is broadcasted to all the receivers
registered for the specified message codemsg - the message codepublic void dispatchMessage(float delay,
Telegraph sender,
Telegraph receiver,
int msg,
boolean needsReturnReceipt)
This is a shortcut method for dispatchMessage(delay, sender, receiver, msg, null, needsReturnReceipt)
delay - the delay in secondssender - the sender of the telegramreceiver - the receiver of the telegram; if it's null the telegram is broadcasted to all the receivers
registered for the specified message codemsg - the message codeneedsReturnReceipt - whether the return receipt is needed or notIllegalArgumentException - if the sender is null and the return receipt is neededpublic void dispatchMessage(float delay,
Telegraph sender,
Telegraph receiver,
int msg,
Object extraInfo)
This is a shortcut method for dispatchMessage(delay, sender, receiver, msg, extraInfo, false)
delay - the delay in secondssender - the sender of the telegramreceiver - the receiver of the telegram; if it's null the telegram is broadcasted to all the receivers
registered for the specified message codemsg - the message codeextraInfo - an optional objectpublic void dispatchMessage(float delay,
Telegraph sender,
Telegraph receiver,
int msg,
Object extraInfo,
boolean needsReturnReceipt)
delay - the delay in secondssender - the sender of the telegramreceiver - the receiver of the telegram; if it's null the telegram is broadcasted to all the receivers
registered for the specified message codemsg - the message codeextraInfo - an optional objectneedsReturnReceipt - whether the return receipt is needed or notIllegalArgumentException - if the sender is null and the return receipt is neededpublic void update()
This method must be called regularly from inside the main game loop to facilitate the correct and timely dispatch of any
delayed messages. Notice that the message dispatcher internally calls GdxAI.getTimepiece().getTime() to get the current AI time and properly dispatch delayed messages. This means that
update the timepiece the delayed messages won't be dispatched.public void scanQueue(MessageDispatcher.PendingMessageCallback callback)
Typically this method is used to save (serialize) pending messages and restore (deserialize and schedule) them back on game loading.
callback - The callback used to report pending messages individually.public boolean handleMessage(Telegram msg)
false since usually the message dispatcher never
receives telegrams. Actually, the message dispatcher implements Telegraph just because it can send return receipts.handleMessage in interface Telegraphmsg - The telegramfalse.Copyright © 2017. All rights reserved.