Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
171 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
API | ||
=== | ||
|
||
.. module:: pizco | ||
|
||
.. autoclass:: Agent | ||
:members: | ||
|
||
|
||
|
||
.. autoclass:: Proxy | ||
:members: | ||
|
||
|
||
|
||
.. autoclass:: Server | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
|
||
Getting Started | ||
=============== | ||
|
||
Installing | ||
---------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
|
||
.. module:: pizco | ||
|
||
Internals | ||
========= | ||
|
||
Agent | ||
----- | ||
|
||
The base of both :class:`Proxy` and :class:`Server` is the :class:`Agent`. | ||
Each Agent has ZMQ sockets to communicate: | ||
|
||
- a `REP` socket to receive requests. This is the main endpoint of the Agent. | ||
- a `PUB` to emit notifications to other Agents. | ||
- one `SUB` to subscribe to notifications from other Agents. | ||
- one `REQ` per each Agent that it has to talk to (stored in self.connections) | ||
|
||
The `REP` and `PUB` endpoint can be specified when the Agent is instantiated. | ||
If no endpoint is given, the sockets will bind to a random tcp port. | ||
|
||
Protocol | ||
-------- | ||
|
||
Messages are multipart ZMQ messages. The conten | ||
|
||
**FRAME 0:** Header (utf-8 encoded str) | ||
|
||
Used for identification and filtering. It contains 3 string concatenated with a | ||
`+` (plus sign). | ||
|
||
1. The protocol version (currently PZC00). | ||
2. A unique identifier for the sender. | ||
3. A string specifying the topic of the message. | ||
|
||
*example:* PZC00+urn:uuid:ad2d9eb0-c5f8-4bfb-a37d-6b7903b041f3+value_changed | ||
|
||
**FRAME 1:** Serialization (utf-8 encoded str) | ||
|
||
Indicates the serialization protocol used in FRAME 2. Current valid values are: | ||
|
||
- 'pickle': use the highest version available of the pickle format (default). | ||
- 'pickleN': use the N version of the pickle format. | ||
- 'json': use json format. | ||
|
||
**FRAME 2:** Content (binary blob) | ||
|
||
The actual content of the message. | ||
|
||
**FRAME 3:** Message ID (utf-8 encoded str) | ||
|
||
A unique identifier for the message. | ||
|
||
*example:* urn:uuid:b711f2b8-277d-40df-a283-6269331db251 | ||
|
||
**FRAME 4:** Signature (bytes) | ||
|
||
HMAC sha1 signature of FRAME 0:4 concatenated with Agent.hmac_key | ||
|
||
|
||
By default, Agents use an empty signature key (no signature) and | ||
the `pickle` serializer. The simplest way to change these defaults is | ||
by using the environmental variables `PZC_KEY` and `PZC_SER`. | ||
You might want to change the serializer when running different agents | ||
on different versions of Python as not all pickle versions are supported | ||
in all python versions. | ||
|
||
You can also change the protocol settings for an specific Agent by | ||
passing a Protocol object when the Agent is created. | ||
|
||
|
||
Proxy-Server Protocol | ||
--------------------- | ||
|
||
Between the Proxy and the Server, the content of the message (Frame 2) | ||
is a tuple of three elements, being the first utf-8 str defining the | ||
subprotocol ('PSMessage'). The second and third elements specify the | ||
action and the options for that action. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
Running Pizco House Examples | ||
============================ | ||
|
||
Server | ||
------ | ||
|
||
Run `house_server.py` to start serving an instance of House. | ||
The House class is defined in `common.py` | ||
|
||
Clients | ||
------- | ||
|
||
These should be run in parallel with the Server: | ||
|
||
- `simple_client.py`: send instructions to the House object. | ||
- `exception_handling.py`: select a new color for the house, | ||
(but only certain colors are allowed!). | ||
- `observing_client.py`: while running `simple_client.py`, see | ||
how this client is notified. | ||
- `gui_client.py`: See bidirectional communication (instructions | ||
and notifications) in action. (Requires PyQt) | ||
|
||
|
||
All in one | ||
---------- | ||
|
||
remote_start_server.py: shows how to start a detached process to serve an object. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import sys | ||
import time | ||
|
||
if sys.version_info < (3,0): | ||
input = raw_input | ||
|
||
from pizco import Proxy | ||
|
||
proxy = Proxy('tcp://127.0.0.1:8000') | ||
|
||
while True: | ||
input('Press enter to run ...\n') | ||
fut = proxy.change_roof() | ||
print('I am doing something while changing the roof') | ||
print('The door is open?: {}'.format(proxy.door_open)) | ||
print('The lights are on?: {}'.format(proxy.lights_on)) | ||
print('I have finished doing this and now I will wait for the result') | ||
print(fut.result()) | ||
|