How to do it...

For this recipe, we need to perform the following steps:

  1. Let's start with the reaper actor. This actor registers actorRefs from other actors and holds it in a set. Create a file named Reaper.scala inside package com.packt.chapter10. The code should look like this:
        package com.packt.chapter10        import akka.actor.{Actor, ActorLogging, ActorRef, Terminated}        import scala.collection.mutable        object Reaper {          case class WatchMe(ref: ActorRef)        }        class Reaper extends Actor with ActorLogging {          import Reaper._          val watched = mutable.Set.empty[ActorRef]          def allActorsTerminated() = {            log.info("All actors terminated. Proceeding to shutdown             system.")            context.system.terminate()          }          def receive = {            case WatchMe(ref) =>              log.info(s"Registering ...

Get Akka Cookbook 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.