Reputation: 965
hi i am new to scala and akka and i am creating an actor that terminates after the processing of messages but i am having error in PoisonPill and Terminated case, it gives value not found error i am confused that if i declear it then what should be the parameter type
import akka.actor.Actor
import akka.actor.ActorSystem
import akka.actor.Props
case class Greet(name: String)
case class Praise(name: String)
case class Celebrate(name: String, age: Int)
class Talker extends Actor {
def receive = {
case Greet(name)=>println(s"Hello $name")
case Praise(name) => println(s"$name, you're amazing")
case Celebrate(name, age) => println(s"Here's to another $age years, $name")
}
}
object HelloActors extends App {
val system = ActorSystem("HelloActors")
system.actorOf(Props[Master], "master")
}
class Master extends Actor {
val talker = context.actorOf(Props[Talker], "talker")
override def preStart {
context.watch(talker)
talker ! Greet("Huey")
talker ! Praise("Dewey")
talker ! Celebrate("Louie", 16)
talker ! PoisonPill
}
def receive = {
case Terminated(`talker`) => context.system.shutdown
}
}
here are the errors
[error] /home/ahsen/SbtPrctc/PoisionPill/src/main/scala/HelloActors.scala:27: not found: value PoisonPill [error] talker ! PoisonPill [error] ^ [error] /home/ahsen/SbtPrctc/PoisionPill/src/main/scala/HelloActors.scala:30: not found: value Terminated [error] case Terminated(
talker
) => context.system.shutdown [error] ^ [error] two errors found
Upvotes: 1
Views: 1312
Reputation: 15773
You need to import the PoisonPill
object:
import akka.actor.{Props, Actor, PoisonPill, ActorSystem, Terminated}
Or:
import akka.actor._
Upvotes: 1