Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A very simple Ping Pong example using Akka's local actors.
import akka.actor._, akka.actor.Actor._
case object Ping
case object Pong
class PongActor extends Actor {
def receive = {
case Ping {
println(self.path + ": Received Ping!")
sender ! Pong
}
case _ ()
}
}
class PingActor extends Actor {
context.actorSelection("../Pong*") ! Ping // starts things off
def receive = {
case Pong {
println(self.path + ": Received Pong!")
sender ! Ping
}
case _ ()
}
}
object PingPong extends App {
val system = ActorSystem()
system.actorOf(Props[PongActor], name="Pong")
system.actorOf(Props[PingActor], name="Ping")
}
object PingPongPong extends App {
val system = ActorSystem()
system.actorOf(Props[PongActor], name="Pong1")
system.actorOf(Props[PongActor], name="Pong2")
system.actorOf(Props[PingActor], name="Ping")
}
@ConnorDoyle

This comment has been minimized.

Copy link
Owner Author

ConnorDoyle commented Dec 26, 2011

This example must be compiled and run with the appropriate Akka jars in the class path.

I made a simple shell script to run the example:
export CLASSPATH=$CLASSPATH:lib/akka-2_0-M1/akka-actor-2.0-M1.jar:lib/akka-2_0-M1/akka-remote-2.0-M1.jar scala -cp $CLASSPATH PingPong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.