parlay.server¶
parlay.server.broker¶
-
class
parlay.server.broker.
Broker
(reactor)[source]¶ Bases:
object
The Broker is the sole holder of global state. There should be only one. It also coordinates all communication between protocols.
-
class
Modes
[source]¶ These are the modes that the broker can run in. * Development mode is purposefully easy to use an insecure to allow logging and easy control of the parlay system * Production mode is locked down and more secure (Security should always be validated independently)
-
DEVELOPMENT
= 'DEVELOPER_MODE'¶
-
PRODUCTION
= 'PRODUCTION_MODE'¶
-
-
classmethod
Broker.
call_on_start
(func)[source]¶ Call the supplied function when the broker starts OR if the broker has already started, call ASAP
-
classmethod
Broker.
call_on_stop
(func)[source]¶ Call the supplied function when the broker stops OR if the broker has already stopped, call ASAP
-
Broker.
handle_broker_message
(msg, message_callback)[source]¶ Any message with topic type ‘broker’ should be passed into here. ‘broker’ messages are special messages that don’t get ‘published’. They are for querying the state of the system. ‘broker’ messages have a ‘request’ field and will reply with an appropriate ‘response’ field
message_callback is the function to call to send the message back to the protocol
-
Broker.
instance
= <parlay.server.broker.Broker object>¶
-
Broker.
open_protocol
(protocol_name, open_params)[source]¶ Open a protocol with the given name and parameters (only run this once the Broker has started running
-
Broker.
publish
(msg, write_method=None)[source]¶ Publish a message to the Parlay system :param msg : The message to publish :param write_method : the protocol’s method to callback if the broker needs to send a response :type msg : dict
-
Broker.
run
(mode='DEVELOPER_MODE', ssl_only=False, use_ssl=False, open_browser=True, ui_path=None)[source]¶ Start up and run the broker. This method call with not return
-
static
Broker.
start
(mode='DEVELOPER_MODE', ssl_only=False, open_browser=True, http_port=8080, https_port=8081, websocket_port=8085, secure_websocket_port=8086, ui_path=None, log_level=10)[source]¶ Run the default Broker implementation. This call will not return.
-
Broker.
subscribe
(func, _owner_=None, **kwargs)[source]¶ Register a listener. The kwargs is a dictionary of args that all must be true to call this listener. You may register the same function multiple times with different kwargs, and it may be called multiple times for each message. @param func: The function to run @param kwargs: The key/value pairs to listen for
-
class
-
class
parlay.server.broker.
BrokerSSlContextFactory
[source]¶ Bases:
twisted.internet.ssl.ContextFactory
A more secure context factory than the default one. Only supports high security encryption ciphers and exchange formats. Last Updated August 2015
parlay.server.reactor¶
We’ve added a number of enhancments to the Twisted reactor to enable easier threading handling. Instead of importing the twisted.internet reactor import this reactor like from parlay.server.reactor import reactor
-
class
parlay.server.reactor.
ReactorWrapper
(wrapped_reactor)[source]¶ Bases:
object
-
maybeCallFromThread
(callable, *args, **kwargs)[source]¶ If we’re in a separate thread from the reactor, then call from the reactor thread. If we’re in the reactor thread, then schedule for call later in 0 seconds
-
maybeDeferToThread
(callable, *args, **kwargs)[source]¶ Call callable from DIFFERENT THREAD. If we’re already in a different thread, then JUST CALL IT and return result If we’re in the reactor thead, then call it in a different thread and return a deferred with the result
-
-
parlay.server.reactor.
run_in_reactor
(reactor)[source]¶ Decorator for automatically handling deferred <-> thread handoff. Any function wrapped in this will work in both a threaded context and a ‘reactor’ async context. Use this decorator if you want the function to always be run in the reactor context
:param reactor the Reactor to use (MUST BE A REACTORWRAPPER)
-
parlay.server.reactor.
run_in_thread
(reactor)[source]¶ Decorator for automatically handling deferred <-> thread handoff. Any function wrapped in this will work in both a threaded context and a ‘reactor’ async context. Use this decorator if you want the function to always be run in the threaded context :param reactor the Reactor to use (MUST BE A REACTORWRAPPER)