Notifiable
- class negmas.events.Notifiable[source]
Bases:
objectAn object that can be notified
Methods Summary
add_handler(notification_type, callback)Adds a notification handler to the list of handlers of the given type.
handlers(notification_type)Gets the list of handlers registered for some notification type.
on_notification(notification, notifier)Called when a notification is received and is not handled by any registered handler
on_notification_(notification, notifier)Called when a notification is received.
remove_handler(notification_type, callback)Removes a notification handler from the list of handlers of the given type.
Methods Documentation
- add_handler(notification_type: str, callback: Callable[[Notification, str], bool])[source]
Adds a notification handler to the list of handlers of the given type. These handlers will be called in the order in which they are received
- Parameters:
notification_type – Notification type as specificed in the type member of the Notification class
callback – The callback which must receive a Notification object and a string and returns a boolean. If True is returned from one callback, the remaining callbacks will not be called
Returns:
- handlers(notification_type: str) list[Callable[[Notification, str], bool]][source]
Gets the list of handlers registered for some notification type. This list can be modified in place to change the order of handlers for example. It is NOT a copy.
- on_notification(notification: Notification, notifier: str) None[source]
Called when a notification is received and is not handled by any registered handler
- Parameters:
notification – The notification received
notifier – The notifier ID
Remarks:
override this method to provide a catch-all notification handling method.
- on_notification_(notification: Notification, notifier: str) bool[source]
Called when a notification is received. Do NOT directly override this method
- Parameters:
notification
notifier
Returns:
- remove_handler(notification_type: str, callback: Callable[[Notification, str], bool]) bool[source]
Removes a notification handler from the list of handlers of the given type.
- Parameters:
notification_type – Notification type as specificed in the type member of the Notification class
callback – The callback which must receive a Notification object and a string and returns a boolean. If True is returned from one callback, the remaining callbacks will not be called
- Returns:
Whether or not the handler was in the list of handlers for this type. In all cases, the handler will not be called after this call (either it was not there or it will be removed).