Created
May 27, 2012 03:17
-
-
Save tinoadams/2800556 to your computer and use it in GitHub Desktop.
Shows the behaviour of setReceiveTimeout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Date | |
import akka.actor.Actor | |
import akka.actor.ActorSystem | |
import akka.actor.Props | |
import akka.actor.ReceiveTimeout | |
import akka.util.duration._ | |
class MyActor extends Actor { | |
context.setReceiveTimeout(5 seconds) | |
def receive = { | |
case x: String => println(new Date + " / Recieved: " + x) | |
case ReceiveTimeout => println(new Date + " / No message received since 5 seconds") | |
} | |
} | |
object Main extends App { | |
val sys = ActorSystem("test") | |
val a = sys.actorOf(Props[MyActor]) | |
println(new Date + " / Started") | |
Thread.sleep(15000) // expect two timeout messages, one after 5 seconds, next after 10 | |
// send ten msg's (1 every second) just when we should receive the third timeout | |
1 to 10 foreach { x => | |
a ! "Message: " + x | |
Thread.sleep(1000) | |
} | |
// the next timeout message should be received 5 seconds after the loop finishes | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment