Chapter 12
- Encapsulation with Actors—mutable state is only accessible from one actor, one thread. Actors are organized in hierarchies, and parents supervise children to achieve fault tolerance.
- We do so by extending the
Actor
class and implementing thereceive
method. - We do so by calling the
actorOf
method onActorSystem
orActorContext
. - Using the
!
operator on anActorRef
—targetActor ! message
. - The
!
operator implements afire-and-forget
type of message sending. It sends a message and returns immediately. Ask pattern involves sending a message using?
operator instead, which returns aFuture[Any]
which will complete once the target actor responds—val futureMessage: Future[Any] = targetActor ? message
. - The Pipe pattern instructs a
Future
to send a message to an actor upon completion of theFuture
's computation—future pipeTo targetActor
.