import akka.actor.{Actor, ActorRef, ActorSystem, Props}
object AkkaMain {
def main(args: Array[String]): Unit = {
// name 으로는 alphabet 만 사용 가능 ('-, _, space' 도 사용 불가)
val actorSystem: ActorSystem = ActorSystem(name = "firstActorSystem")
println(actorSystem.name)
class Person(name: String) extends Actor {
// type Receive = PartialFunction[Any, Unit]
override def receive: Receive = {
case "hi" => println(s"Hi, my name is $name")
case _ =>
}
}
object Person {
def props(name: String): Props = Props(new Person(name))
}
// val person = actorSystem.actorOf(Props(new Person("Bob")))
// actor 를 만들 때 아래처럼 companion object 를 이용하는 것이 권장되는 방법임
val person: ActorRef = actorSystem.actorOf(Person.props("Bob"))
person ! "hi"
}
}