Toto 1.0.10 documentation

Events

«  Task Queues   ::   Contents   ::   Built-in Methods  »

Events

Toto’s event framework is used to allow external events to affect client requests, or to run scheduled tasks after a specified signal is received. It can be used to send messages to active requests, even between multiple server processes. The event framework can also be used outside of Toto to send messages to running Toto servers.

class toto.events.EventManager(address=None)[source]

Instances will listen on address for incoming events.

classmethod EventManager.instance()[source]

Returns the shared instance of EventManager, instantiating on the first call.

EventManager.start_listening()[source]

Starts listening for incoming events on EventManager.address.

Remote Servers

EventManager.register_server(address)[source]

Add a server located at address. This server will now be included in the recipient list whenever send() is called.

EventManager.remove_server(address)[source]

Remove the server located at address from the recipient list for all future calls to send().

EventManager.remove_all_servers()[source]

Clear the recipient list for all future calls to send.

EventManager.refresh_server_queue()[source]

Reload and shuffle the registered server queue used for round-robin load balancing of non-broadcast events.

Handlers

EventManager.register_handler(event_name, event_handler, run_on_main_loop=False, request_handler=None, persist=False)[source]

Register event_handler to run when event_name is received. Handlers are meant to respond to a single event matching event_name only. If run_on_main_loop is True the handler will be executed on Tornado’s main IOLoop (required if the handler will write to a response stream). If request_handler is set, event_handler will not fire once request_handler has finished. Set persist to True to automatically requeue event_handler each time it is executed.

EventManager.remove_handler(handler_sig)[source]

Disable and remove the handler matching handler_sig.

Transmission

EventManager.send_to_server(address, event_name, event_args)[source]

Send a message with event_name and event_args only to the server listening at address. address must have previously been passed to register_server. This is more efficient than send if you only intent to send the event to a single server and know the address in advance.

EventManager.send(event_name, event_args, broadcast=True)[source]

Send a message with event_name and event_args to all servers previously registered with register_server(). If broadcast is false, the event will be sent to only a single server. Non-broadcast events are round-robin load balanced between registered servers.

«  Task Queues   ::   Contents   ::   Built-in Methods  »