-
Notifications
You must be signed in to change notification settings - Fork 5
Serverpool Policy
The Policy is an important class that controls the way Connections exchange messages with the Pool bus.
When the pool gets a new message from a Connection, it calls the appropriate server's policy().input(message, connection, broadcast) callback, discarding the return value (if the callback wants to put messages in the bus, it calls the broadcast function given as its third arg). Similarly, when the Pool is contemplating outputting a message to a connection, it will call policy.output(message, connection, broadcast), and the callback can send the message to the connection by calling connection.queue.server_push(message).
An important thing to notice here is that the arguments for input and output are more or less the same. Both callback types are capable of pushing to the pool and to the connection. Do not mishandle this power, for it is indeed mighty.
Methods:
* __init__(inputs={},outputs={}) # Optionally takes dicts to convert into SubPolicies.
* input(message, connection, broadcast) # Calls an internally stored callback with these arguments.
* output(message, connection, broadcast) # Calls an internally stored callback with these arguments.
Properties:
* inputs # Note the plural, differentiating it from the function. This is a SubPolicy.
* outputs # Another subpolicy.
A subclass of dict, providing type checking of keys, thread safety, a few helper functions and a default property. It's a set of callbacks, keyed on message type. Message types must be strings.
Methods:
* __init__(values={}) Initialize with an optional dict of callbacks.
* set_multi(value, *args, keys=None) # Sets all the keys in args and the optional keys argument to value.
* bloom(source, *args, keys=None) # The same as above, using self[source] as the value.
Properties:
* default # Function to return in __getitem__ instead of raising a KeyError. Not used when set to None.