ScriptMsgListener
Script accessible version of Dispatcher::IMessageListener. Often used in conjunction with EventManager.
Callbacks
void
onAdd()
Script callback when a listener is first created and registered.
void
onRemove()
Script callback when a listener is deleted.
bool
onMessageReceived(string queue, string event, string data)
Called when the listener has received a message.
bool
onMessageObjectReceived(string queue, Message msg)
Called when a message object (not just the message data) is passed to a listener.
void
onAddToQueue(string queue)
Callback for when the listener is added to a queue.
void
onRemoveFromQueue(string queue)
Callback for when the listener is removed from a queue.
Detailed Description
Script accessible version of Dispatcher::IMessageListener. Often used in conjunction with EventManager.
The main use of ScriptMsgListener is to allow script to listen formessages. You can subclass ScriptMsgListener in script to receivethe Dispatcher::IMessageListener callbacks.
Alternatively, you can derive from it in C++ instead of SimObject toget an object that implements Dispatcher::IMessageListener with scriptcallbacks. If you need to derive from something other then SimObject,then you will need to implement the Dispatcher::IMessageListenerinterface yourself.
// Create the EventManager. $MyEventManager = new EventManager() { queue = "MyEventManager"; }; // Create an event. $MyEventManager.registerEvent( "SomeCoolEvent" ); // Create a listener and subscribe. $MyListener = new ScriptMsgListener() { class = MyListener; }; $MyEventManager.subscribe( $MyListener, "SomeCoolEvent" ); function MyListener::onSomeCoolEvent( %this, %data ) { echo( "onSomeCoolEvent Triggered" ); } // Trigger the event. $MyEventManager.postEvent( "SomeCoolEvent", "Data" );
Callbacks
onAdd()
Script callback when a listener is first created and registered.
function ScriptMsgListener::onAdd(%this) { // Perform on add code here }
onRemove()
Script callback when a listener is deleted.
function ScriptMsgListener::onRemove(%this) { // Perform on remove code here }
onMessageReceived(string queue, string event, string data)
Called when the listener has received a message.
Parameters:
queue | The name of the queue the message was dispatched to |
event | The name of the event (function) that was triggered |
data | The data (parameters) for the message |
false to prevent other listeners receiving this message, true otherwise
onMessageObjectReceived(string queue, Message msg)
Called when a message object (not just the message data) is passed to a listener.
Parameters:
queue | The name of the queue the message was dispatched to |
msg | The message object |
false to prevent other listeners receiving this message, true otherwise
onAddToQueue(string queue)
Callback for when the listener is added to a queue.
The default implementation of onAddToQueue() and onRemoveFromQueue() provide tracking of the queues this listener is added to through the mQueues member. Overrides of onAddToQueue() or onRemoveFromQueue() should ensure they call the parent implementation in any overrides. Parameters:
queue | The name of the queue that the listener added to |
onRemoveFromQueue(string queue)
Callback for when the listener is removed from a queue.
The default implementation of onAddToQueue() and onRemoveFromQueue() provide tracking of the queues this listener is added to through the mQueues member. Overrides of onAddToQueue() or onRemoveFromQueue() should ensure they call the parent implementation in any overrides. Parameters:
queue | The name of the queue that the listener was removed from |