Channels

Channels are the means by which Proclets communicate. Being autonomous, Proclets share no data structures directly. Therefore, if their transitions are to synchronise, it must be by means of exchanging messages. This is what Channels do. They accept messages, and store them permanently, so the recipient can use them to make decisions.

In order to achieve this, the messages have to be of a certain form; a Performative described in the 2001 paper.

Proclets defines this Performative type, but the Channel API is such that you don’t have to explicitly create them yourself. However it is useful to understand their structure because it enables powerful interactions and protocols.

class proclets.channel.Channel(maxlen=None)

Channels provide a service somewhat like an email client; they deliver Performative s to an inbox corresponding to the uid of the Proclet recipient.

These messages can be retrieved one at a time, after the manner of a queue. There are also higher-level methods which allow Proclets to process messages in batches.

By default, messages are only delivered once. However, each Proclet transition may independently access the channel; to do that, pass this to the party parameter of the channel method.

qsize(uid: uuid.UUID, party=None) int

Return the number of items in the channel.

empty(uid: uuid.UUID, party=None) bool

Return True if the channel is empty, False otherwise.

send(**kwargs)

Submit a message for delivery.

Parameters
  • sender (uuid.UUID) – Uid of the sender.

  • group (list) – Contains uids of intended recipients.

All keyword arguments are those of a Performative.

receive(p: proclets.proclet.Proclet, party=None) proclets.types.Performative

Yield all undelivered messages intended for the Proclet.

reply(p: proclets.proclet.Proclet, m: proclets.types.Performative, **kwargs) proclets.types.Performative

Proclet p having received a message m; use it to craft a reply to its sender. This method preserves context and connection of messages. Keyword arguments are those of a Performative.

respond(p: proclets.proclet.Proclet, party=None, actions: Optional[dict] = None, contents: Optional[dict] = None, context: Optional[set] = None, senders: Optional[set] = None) proclets.types.Performative

Process undelivered messages for p as a batch. Yields each generated reply as a Performative.

Parameters
  • actions (dict) – Maps incoming message actions to a corresponding action in the generated reply.

  • contents (dict) – Maps incoming message actions to corresponding content in the generated reply.

  • context (set) – If supplied, add extra context to the reply.

  • senders (set) – If supplied, only reply to the senders specified.

view(uid: uuid.UUID)

Scan the entire Channel for messages sent and received by the Proclet with uid.

Returns an dictionary containing sequences of messages having the same connect ids. The items in each sequence are the connected messages in the order they were generated.

Performatives

class Performative(**kwargs)
Parameters
  • ts (int) – A time stamp for creation. Generated automatically. Subject to resolution of the system clock. Some objects may share the same time stamp.

  • uid (uuid.UUID) – A unique id. Generated automatically.

  • channel (object) – A channel object. Set automatically by proclets.channel.Channel.send().

  • sender (uuid.UUID) – Uid of the sender.

  • group (set) – Contains uids of intended recipients.

  • connect – A uid to identify a thread of messages. Set automatically by Channel methods.

  • context (set) – Contains uids of objects to which the message relates. Application specific.

  • action – An object denoting a Performative action. Application specific.

  • content – An object containing Performative content. Application specific.