Skip to content
Ben Langfeld edited this page Sep 21, 2011 · 1 revision

How Punchblock handles Rayo

Punchblock provides a connection class which wraps a Blather client, connecting to an XMPP server as a standard client. The connection object is responsible for reading and writing Rayo messages via XMPP. Blather utilises an EventMachine reactor for the underlying connection, while the Punchblock connection registers callbacks for <iq/> responses and <presence/> stanzas.

These handlers parse incoming messages (mostly events, but also <ref/>s) to an instance of the appropriate event class based on the element name and namespace. Call-wide events are then placed on a queue (essentially a thread-safe synchronised array) for consumption by a worker thread.

When a command is written to the connection, the connection listens for its response in order to set the response as an attribute on the original command object. The original command contains a state machine and the ability to set callbacks on completion.

There is a similar story for component objects, who have the initial response attribute, as well as the ability to receive events which may be dispatched via a set of callbacks. Components also listen for a complete event.