Messages¶
Turberfield IPC can take the objects used by your application and parcel them up for transmission. The messages get passed around with a header of routing and flow control information.
You’ll need to register your application classes for encapsulation in these messages.
Defined types¶
-
class
turberfield.ipc.types.
Address
¶ Address(namespace, user, service, application)
A semantically hierarchical address for distributed networking.
- namespace
- Specifies the domain within which the address names are valid.
- user
- A unique name of trust within the network.
- service
- Identifies a currently operating instantiation of the network.
- application
- The name of the node endpoint.
-
class
turberfield.ipc.message.
Message
¶ Message(header, payload)
An Message object holds both protocol control information (PCI) and application data.
- header
- PCI data necessary for the delivery of the message.
- payload
- Client data destined for the application endpoint.
Creating messages¶
-
turberfield.ipc.message.
parcel
(token, *args, dst=None, via=None, hMax=3)[source]¶ Parameters: - token – A DIF token. Just now the function turberfield.ipc.fsdb.token is the source of these.
- args – Application objects to send in the message.
- dst – An
Address
for the destination. If None, will be set to the source address (ie: a loopback message). - via – An
Address
to pass the message on to. If None, the most direct route is selected. - hMax – The maximum number of node hops permitted for this message.
Return type:
Replying to messages¶
-
turberfield.ipc.message.
reply
(header, *args, dst=None, via=None, hMax=3)[source]¶ Parameters: - header – The Header object of the original message.
- args – Application objects to send in the message.
- dst – An
Address
for the destination. If None, will be set to the source address. - via – An
Address
to pass the message on to. If None, the most direct route is selected. - hMax – The maximum number of node hops permitted for this message.
Return type:
Registering custom objects¶
To enable your objects to go into a message, you must register their classes with turberfield.utils.assembly.Assembly.
For example, here’s how the message
module defines its
own Alert class:
Alert = namedtuple("Alert", ["ts", "text"])
And this is how it registers these objects so they can be dumped into a message and loaded back:
Assembly.register(Alert)
Other functions¶
-
turberfield.ipc.fsdb.
token
(connect: str, serviceName: str, appName: str, userName: str = ”)[source]¶ Generates a token for use with the IPC framework.
Parameters: - connect – A connection string in the form of a URL. Just now this must be a file path to a user-writeable directory, eg: ‘file:///home/alice/.turberfield’.
- serviceName – The name of a network of services.
- appName – The name of your application.