rodario¶
A simple, redis-backed Python actor framework
Connection¶
By default, rodario will use a StrictRedis
connection to localhost on the
default port. If you wish to override this behavior, then replace the
rodario.get_redis_connection
method after import:
from redis import StrictRedis
import rodario
rodario.get_redis_connection = lambda: StrictRedis(host='1.2.3.4')
The Registry¶
-
class
rodario.registry.
Registry
[source]¶ Actor registry class (singleton wrapper)
-
static
__new__
(prefix=None)[source]¶ Retrieve the singleton instance for Registry.
Parameters: prefix (str) – Optional prefix for redis key names Return type: rodario.registry._RegistrySingleton
-
static
-
class
rodario.registry.
_RegistrySingleton
(prefix=None)[source]¶ Singleton for actor registry
-
__init__
(prefix=None)[source]¶ Initialize the registry.
Parameters: prefix (str) – Optional prefix for redis key names
-
exists
(uuid)[source]¶ Test whether an actor exists in the registry.
Parameters: uuid (str) – UUID of the actor to check for Return type: bool
-
get_proxy
(uuid)[source]¶ Return an ActorProxy for the given UUID.
Parameters: uuid (str) – The UUID to return a proxy object for Return type: rodario.actors.ActorProxy
-
Actors and Proxies¶
-
class
rodario.actors.
Actor
(uuid=None)[source]¶ Base Actor class
-
__init__
(uuid=None)[source]¶ Initialize the Actor object.
Parameters: uuid (str) – Optionally-provided UUID
-
part
(channel)[source]¶ Remove this Actor from a pubsub cluster channel.
Parameters: channel (str) – The channel to part
-
proxy
()[source]¶ Wrap this Actor in an ActorProxy object.
Return type: rodario.actors.ActorProxy
-
-
class
rodario.actors.
ActorProxy
(actor=None, uuid=None)[source]¶ Proxy object that fires calls to an actor over redis pubsub
-
__init__
(actor=None, uuid=None)[source]¶ Initialize instance of ActorProxy.
Accepts either an Actor object to clone or a UUID, but not both.
Parameters: - actor (rodario.actors.Actor) – Actor to clone
- uuid (str) – UUID of Actor to clone
-
_proxy
(method_name, *args, **kwargs)[source]¶ Proxy a method call to redis pubsub.
This method is not meant to be called directly. Instead, it is used by the proxy’s self-generated methods to provide the proxy with the same public API as the actor it represents.
Parameters: Return type:
-
proxyid
= None¶ This proxy object’s UUID for creating unique channels
-
-
class
rodario.actors.
ClusterProxy
(channel)[source]¶ Proxy object responsible for multiple actors
This class is meant to be inherited by child objects which can provide their own API methods for coordinating the Actors in their channel.
-
__init__
(channel)[source]¶ Initialize instance of ClusterProxy.
Parameters: channel (str) – The cluster channel to use
-
_proxy
(method_name, *args, **kwargs)[source]¶ Proxy a method call to redis pubsub.
Use this method in your child objects which inherit from ClusterProxy to provide the proxy with some representation of the public API for the Actors it represents.
Paramstr method_name: The method to proxy
Parameters: Return type: Returns: A Future whose first value is the number of expected responses
-
channel
= None¶ Cluster channel
-
proxyid
= None¶ This proxy object’s UUID for creating unique channels
-
-
class
rodario.future.
Future
(queue)[source]¶ Custom response type for proxied method calls
-
__init__
(queue)[source]¶ Initialize the Future by saving a reference to the Queue
Parameters: queue (multiprocessing.Queue) – The response queue to wrap
-
Decorators¶
-
class
rodario.decorators.
DecoratedMethod
(func, decorations=None, before=None, after=None)[source]¶ Generic decorated method
-
__init__
(func, decorations=None, before=None, after=None)[source]¶ Wrap the given function.
Parameters: - func (function) – The function to wrap
- decorations (set) – The decorator tags to attach
- before (list) – The list of before-hook functions
- after (list) – The list of after-hook functions
-
after
= []¶ List of after-hook functions
-
before
= []¶ List of before-hook functions
-
static
decorate
(func, decorations=None, before=None, after=None)[source]¶ Decorate the given function. If it is already a DecoratedMethod, it will be appended to rather than overwritten.
Parameters: - decorations (set) – The decorator tags to attach
- before (list) – The list of before-hook functions
- after (list) – The list of after-hook functions
Return type: Returns: A
DecoratedMethod
wrapper aroundfunc
-
decorations
= set([])¶ Set of decorator tags
-
-
rodario.decorators.
singular
(func)[source]¶ First-come, first-served cluster channel call. Needs some work; should accept parameters for context and expiry.
Parameters: func (function) – The function to wrap Return type: rodario.decorators.DecoratedMethod
Exceptions¶
-
class
rodario.exceptions.
InvalidActorException
[source]¶ Raised when a referenced actor does not exist
-
class
rodario.exceptions.
InvalidProxyException
[source]¶ Raised when a proxy is not given a valid object to wrap