neutron_lib.callbacks.manager module¶
-
class
neutron_lib.callbacks.manager.
Callback
(id, method, cancellable)¶ Bases:
tuple
-
cancellable
¶ Alias for field number 2
-
id
¶ Alias for field number 0
-
method
¶ Alias for field number 1
-
-
class
neutron_lib.callbacks.manager.
CallbacksManager
¶ Bases:
object
A callback system that allows objects to cooperate in a loose manner.
-
clear
()¶ Brings the manager to a clean slate.
-
publish
(resource, event, trigger, payload=None)¶ Notify all subscribed callback(s) with a payload.
Dispatch the resource’s event to the subscribed callbacks.
- Parameters
resource – The resource for the event.
event – The event.
trigger – The trigger. A reference to the sender of the event.
payload – The optional event object to send to subscribers. If passed this must be an instance of BaseEvent.
- Raises
neutron_lib.callbacks.exceptions.Invalid – if the payload object is not an instance of BaseEvent.
CallbackFailure – if the underlying callback has errors.
-
subscribe
(callback, resource, event, priority=55550000, cancellable=False)¶ Subscribe callback for a resource event.
The same callback may register for more than one event.
- Parameters
callback – the callback. It must raise or return a boolean.
resource – the resource. It must be a valid resource.
event – the event. It must be a valid event.
priority – the priority. Callbacks are sorted by priority to be called. Smaller one is called earlier.
cancellable – if the callback is “cancellable”, in case of returning an exception, the callback manager will raise a
CallbackFailure
exception.
-
unsubscribe
(callback, resource, event)¶ Unsubscribe callback from the registry.
- Parameters
callback – the callback.
resource – the resource.
event – the event.
-
unsubscribe_all
(callback)¶ Unsubscribe callback for all events and all resources.
- Parameters
callback – the callback.
-
unsubscribe_by_resource
(callback, resource)¶ Unsubscribe callback for any event associated to the resource.
- Parameters
callback – the callback.
resource – the resource.
-