Skip to content

Commit

Permalink
impl goat actor
Browse files Browse the repository at this point in the history
  • Loading branch information
kobtea committed Jan 17, 2016
1 parent 55ca8b1 commit 2ba873d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ name := "akka-goat-mail"
version := "1.0"

scalaVersion := "2.11.7"

lazy val akkaVersion = "2.4.1"

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % akkaVersion
)
29 changes: 29 additions & 0 deletions src/main/scala/GoatMail.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import akka.actor.{ActorRef, Props, ActorSystem, Actor}

case class Mail(message: String)

case class Start(target: ActorRef)

case class Goat(name: String) extends Actor {

def say(msg: String) = println(name + ": " + msg)

def eat(): Unit = this.say("om nom nom nom...")

def receive = {
case Start(ar) =>
ar ! Mail("Hello!")
case Mail(s) =>
this.eat()
sender() ! Mail("What did you write about?")
}

}

object GoatMail extends App {
val goatPool = ActorSystem("goat-pool")
val whiteGoat = goatPool.actorOf(Props(classOf[Goat], "white-goat"))
val blackGoat = goatPool.actorOf(Props(classOf[Goat], "black-goat"))

whiteGoat ! Start(blackGoat)
}

0 comments on commit 2ba873d

Please sign in to comment.