Anatomy of an actor

Before diving into a full-blown application, let's look at the different components of the actor framework and how they fit together:

  • Mailbox: A mailbox is basically a queue. Each actor has its own mailbox. When you send a message to an actor, the message lands in its mailbox and does nothing until the actor takes it off the queue and passes it through its receive method.
  • Messages: Messages make synchronization between actors possible. A message can have any type with the sole requirement that it should be immutable. In general, it is better to use case classes or case objects to gain the compiler's help in checking message types.
  • Actor reference: When we create an actor using val echo1 = system.actorOf(Props[EchoActor]), echo1 ...

Get Scala for Data Science now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.