Akka Actor's lifecycle example
In this section, we will develop a couple of Actors to explore Akka Actor's lifecycle methods in detail. Perform the following steps to explore Akka Actor's lifecycle:
- Create a Scala/Akka SBT project in your favorite IDE ( I am using IntelliJ IDEA IDE):
Project name: akka-actor-lifecycle-app
- Add the following configuration to the
sbtfile:
build.sbt:
name := "akka-actor-lifecycle-app"
version := "1.0"
scalaVersion := "2.12.2"
libraryDependencies ++= Seq("com.typesafe.akka" %% "akka-actor" %
"2.5.9") - Create the
ActorLifecycleAppfile, as shown:
ActorLifecycleApp.scala:
package com.packt.publishing.actor.lifecycle
import akka.actor.{Actor,ActorSystem,Props}
class LifecycleActor extends Actor{
override def preStart(): Unit = {
println("LifecycleActor::preStart() invoked.")
}
override def receive: PartialFunction[Any, Unit] = {
case _ =>
println...