A mailbox is a lightweight thread with an inbox for incoming messages and an outbox for outgoing messages. Every actor has a mailbox, though any number of actors can share the same mailbox. Actors which share the same mailbox then always use the same thread and can exchange messages very quickly (about 1 billion messages per second on an i5).
Actors typically pass messages directly from one actor to another, without having to use an inbox or outbox. But if the destination actor is busy processing its own incoming messages on another thread, then the source actor puts the outgoing message in its mailbox's outbox for subsequent processing when the inbox is empty. To maximize throughput, mailboxes always group outgoing messages by destination actor and then sends all the messages for each destination as an array list.
Mailboxes can be tagged as synchronous or asynchronous. Asynchronous actors are actors which have an mailbox with an event queue which has been tagged as autonomous. And when an actor has a request for an asynchronous actor, the request and response are always exchanged asynchronously.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|