Package elisa :: Package core :: Module bus :: Class Bus

Class Bus

source code


Python objects can register callbacks with the bus and be called when elisa.core.components.massage.Messages 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 Methods
 
__init__(self)
Initialize the Message queue and the callbacks dictionary.
source code
twisted.internet.defer.Deferred
deferred_dispatch(self)
Dequeue and dispatch each queued message.
source code
elisa.core.utils.defer.Deferred
start(self)
Start message dispatching: once started, messages sent over the bus are guaranteed to be dispatched.
source code
 
stop(self)
Stop message dispatching: messages sent over the bus will not be dispatched automatically anymore, they will be locally queued.
source code
elisa.core.utils.defer.Deferred
send_message(self, message, sender=None)
Send a message over the bus.
source code
 
register(self, callback, *message_types)
Register a new callback with the bus.
source code
 
unregister(self, callback)
Unregister a callback from the bus.
source code

Inherited from extern.log.log.Loggable: debug, doLog, error, info, log, logFunction, logObjectName, warning, warningFailure

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables

Inherited from extern.log.log.Loggable: logCategory

Instance Variables
dict, keys are callable objects and values are Message types lists callbacks
registered callbacks
Properties

Inherited from object: __class__

Method Details

__init__(self)
(Constructor)

source code 

Initialize the Message queue and the callbacks dictionary.

Overrides: object.__init__

deferred_dispatch(self)

source code 

Dequeue and dispatch each queued message. This method is called when the bus starts, to dispatch all the messages that were sent before startup.

This method can also be used to force dispatch on a bus you don't want to start, for instance for functional test purpose.

Returns: twisted.internet.defer.Deferred
a deferred fired when all messages have been dispatched

start(self)

source code 

Start message dispatching: once started, messages sent over the bus are guaranteed to be dispatched.

Returns: elisa.core.utils.defer.Deferred
a deferred fired when all queued messages have been dispatched

send_message(self, message, sender=None)

source code 

Send a message over the bus. The message is automatically dispatched if the Bus is running. Otherwise the message is locally queued until the Bus starts.

Parameters:
Returns: elisa.core.utils.defer.Deferred
a deferred fired when the message have been dispatched or queued

register(self, callback, *message_types)

source code 

Register a new callback with the bus. The given callback will be called when a message of one of the given types is dispatched on the bus.

Parameters:
  • callback (callable) - the callback to register
  • message_types (type or list of types) - Message types to filter on

unregister(self, callback)

source code 

Unregister a callback from the bus.

Parameters:
  • callback (callable) - the callback to register