Implementation

Let's start by defining the Greeter actor, as it is the simpler one:

class Greeter extends Actor {  val log = Logging(context.system, this)  def receive = {    case SayHello(name) => log.info(s"Greetings to $name")    case Die =>      context stop self      sender ! Dead  }}

The actor is going to accept a say hello message that is parameterized by the name the actor is supposed to greet. On receiving this message, it is going to perform a log output.

The Greeter actor has the means for the other actors to stop it. We have already discussed that one of the requirements of the task is that the manager actor should be able to terminate its existing actress to spawn a new actor. This can be accomplished by sending a message to this Greeter actor. ...

Get Mastering Functional Programming 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.