Part of elisa.core.bus View In Hierarchy
Python objects can register callbacks with the bus and be called when
elisa.core.components.massage.Message
s are sent by other
objects.
Here is a simple example:
bus = Bus() def my_cb(message, sender): print 'Got message %r from %r' % (message, sender) bus.register(my_cb) bus.send_message(Message())
Messages dispatching empties the message queue and call the registered callbacks. Messages filtering is also supported, just pass a Message type class to bus.register(), like this:
bus.register(my_cb, Message)
You can filter on multiple Message types by supplying a list to bus.register():
bus.register(my_cb, (FooMessage, DataMessage))
Instance Variables | callbacks | registered callbacks (type: dict, keys are callable objects and values are Message types lists ) |
Line # | Kind | Name | Docs |
---|---|---|---|
60 | Method | __init__ | Initialize the Message queue and the callbacks dictionary. |
82 | Method | start | Start message dispatching: once started, messages sent over the bus |
93 | Method | stop | Stop message dispatching: messages sent over the bus will not be |
101 | Method | send_message | Send a message over the bus. The message is automatically |
123 | Method | register | Register a new callback with the bus. The given callback will be |
148 | Method | unregister | Unregister a callback from the bus. |
76 | Method | _dispatch_queued_msgs | Undocumented |
163 | Method | _dispatch | Dispatch messages to registered callbacks and empty the |
Queued messages are dispatched inside a separate thread.
Bus
is running. Otherwise
the message is locally queued until the Bus
starts.
MT safe.
Parameters | message | the message to send
(type: elisa.core.components.message.Message
) |
sender | the sender object. None by default. Will be passed to receiver callbacks. (type: object ) |
MT safe.
Parameters | callback | the callback to register (type: callable ) |
message_types | Message types to filter on (type: type or list of types ) |