Commit 939b5371 authored by Dominik Charousset's avatar Dominik Charousset

fixed scala benchmark

parent 1219a923
...@@ -18,8 +18,8 @@ case class Pong(value: Int) ...@@ -18,8 +18,8 @@ case class Pong(value: Int)
case class Ok(token: String) case class Ok(token: String)
case class AddPong(path: String, token: String) case class AddPong(path: String, token: String)
case object Hello case class Hello(token: String)
case object Olleh case class Olleh(token: String)
case class NoTokenReceived(token: String) case class NoTokenReceived(token: String)
case class PongDidNotRespond(pong: AbstractActor) case class PongDidNotRespond(pong: AbstractActor)
...@@ -68,16 +68,19 @@ class ServerActor(port: Int) extends Actor { ...@@ -68,16 +68,19 @@ class ServerActor(port: Int) extends Actor {
reply(Pong(value)) reply(Pong(value))
msgLoop msgLoop
} }
case Olleh => { case Hello(token) => {
val pong = sender sender ! Olleh(token)
}
case Olleh(token) => {
pendingPongs.filter(x => x match { pendingPongs.filter(x => x match {
case (path, `pong`, ping, token) => { case (path, pong, ping, `token`) => {
ping ! Ok(token) ping ! Ok(token)
pongs = (path, pong) :: pongs pongs = (path, pong) :: pongs
true true
} }
case _ => false case _ => false
}) })
msgLoop
} }
case PongDidNotRespond(pong) => { case PongDidNotRespond(pong) => {
pendingPongs.filter(x => x match { pendingPongs.filter(x => x match {
...@@ -87,6 +90,7 @@ class ServerActor(port: Int) extends Actor { ...@@ -87,6 +90,7 @@ class ServerActor(port: Int) extends Actor {
} }
case _ => false case _ => false
}) })
msgLoop
} }
case AddPong(path, token) => { case AddPong(path, token) => {
if (pongs.exists(x => x._1 == path)) { if (pongs.exists(x => x._1 == path)) {
...@@ -99,6 +103,7 @@ class ServerActor(port: Int) extends Actor { ...@@ -99,6 +103,7 @@ class ServerActor(port: Int) extends Actor {
val pong = select(new Node(node, port.toInt), 'Pong) val pong = select(new Node(node, port.toInt), 'Pong)
(new DelayActor(5000, Actor.self, PongDidNotRespond(pong))).start (new DelayActor(5000, Actor.self, PongDidNotRespond(pong))).start
pendingPongs = (path, pong, sender, token) :: pendingPongs pendingPongs = (path, pong, sender, token) :: pendingPongs
pong ! Hello(token)
} }
} }
} }
...@@ -210,7 +215,7 @@ class ServerAkkaActor(system: ActorSystem) extends AkkaActor { ...@@ -210,7 +215,7 @@ class ServerAkkaActor(system: ActorSystem) extends AkkaActor {
case Ping(value) => { case Ping(value) => {
sender ! Pong(value) sender ! Pong(value)
} }
case Olleh => { case Olleh(_) => {
pendingPongs.find(x => x == sender) match { pendingPongs.find(x => x == sender) match {
case Some((pong, ping, token)) if pong == sender => { case Some((pong, ping, token)) if pong == sender => {
println("added actor " + pong.path) println("added actor " + pong.path)
...@@ -242,7 +247,7 @@ println("added actor " + pong.path) ...@@ -242,7 +247,7 @@ println("added actor " + pong.path)
println("try to add actor " + path) println("try to add actor " + path)
val pong = system.actorFor(path) val pong = system.actorFor(path)
// wait at most 5sec. for response // wait at most 5sec. for response
pong ! Hello pong ! Hello("")
system.scheduler.scheduleOnce(5 seconds, self, AkkaPongDidNotRespond(pong, sender)) system.scheduler.scheduleOnce(5 seconds, self, AkkaPongDidNotRespond(pong, sender))
become(recvLoop(pongs, (pong, sender, token) :: pendingPongs)) become(recvLoop(pongs, (pong, sender, token) :: pendingPongs))
//pong ! Hello //pong ! Hello
...@@ -255,8 +260,8 @@ println("try to add actor " + path) ...@@ -255,8 +260,8 @@ println("try to add actor " + path)
//println("KickOff(" + value + ") from " + client) //println("KickOff(" + value + ") from " + client)
pongs.foreach((x) => context.actorOf(Props(new PingAkkaActor(client, x))) ! KickOff(value)) pongs.foreach((x) => context.actorOf(Props(new PingAkkaActor(client, x))) ! KickOff(value))
} }
case Hello => { case Hello(token) => {
sender ! Olleh sender ! Olleh(token)
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment