Notifiable

class negmas.events.Notifiable[source]

Bases: object

An 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, callback)[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 (str) – Notification type as specificed in the type member of the Notification class

  • callback (Callable[[Notification, str], bool]) – 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)[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.

Return type:

list[Callable[[Notification, str], bool]]

on_notification(notification, notifier)[source]

Called when a notification is received and is not handled by any registered handler

Parameters:
  • notification (Notification) – The notification received

  • notifier (str) – The notifier ID

Return type:

None

Remarks:

  • override this method to provide a catch-all notification handling method.

on_notification_(notification, notifier)[source]

Called when a notification is received. Do NOT directly override this method

Parameters:
Return type:

bool

Returns:

remove_handler(notification_type, callback)[source]

Removes a notification handler from the list of handlers of the given type.

Parameters:
  • notification_type (str) – Notification type as specificed in the type member of the Notification class

  • callback (Callable[[Notification, str], bool]) – 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

Return type:

bool

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).