PDA

View Full Version : HMTP: Actors, the Broker, and Mailboxes


ferg
12-16-2010, 04:51 PM
While HMTP can be used as a simple point-to-point protocol using just a pair of ActorStreams for a client and server, it's designed as a piece of an Actor model (http://en.wikipedia.org/wiki/Actor_model) or Event Driven Architecture (http://en.wikipedia.org/wiki/Event-driven_architecture) that we're using as the basis for Resin's own clustering.

Each cluster service in Resin is composed of one or more Actors which communicates to other Actors in the cluster using HMTP/BAM. The distributed cache, for example, uses a ClusterCacheActor with the JID "cluster-cache@aaa.app-tier.admin.resin" to send cache updates to another ClusterCacheActor with JID "cluster-cache@baa.app-tier.admin.resin".

Actors send messages to other Actors through a Broker, which is essentially a router using the JID as a message address. When the distributed cache on server D sends an update to the triad server A, it uses the Broker to route the CachePut message to "cluster-cache@aaa.app-tier.admin.resin".

As with the rest of HMTP, all message types are treated equally: message, query, queryResult and the messageErrors and may be delivered out of order. In general, message processing is non-blocking. A query service might send 5 queries and receive the responses out of order without tying up multiple threads.

Since a Mailbox accepts messages for every Actor in HMTP/BAM, the Broker really delivers messages to a Mailbox, not directly to an Actor. The Mailbox is then responsible for thread-management for the delivered response. The primary value of the Mailbox is isolating the processing of the message from its delivery: the sender should not be blocked while the receiver is processing the message.

Each of the Actor, Mailbox, and Broker uses the same underlying ActorStream API to deliver the messages, keeping HMTP/BAM as a simple stream-based architecture.

* Actor - the service code itself, the application that does the actual work.
* Mailbox - a queue associated with each Actor to isolate senders from receivers.
* Broker - the router responsible for delivering messages to the correct Actor based on the JID.

That's essentially the entire architecture of HMTP/BAM. The additional details are implementation behavior of various Brokers and Mailboxes, and convenience reflection for Actors, but the architecture itself is compact.