Created
April 12, 2013 19:02
-
-
Save jamie-allen/5374304 to your computer and use it in GitHub Desktop.
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 akka.actor.OneForOneStrategy | |
import akka.actor.SupervisorStrategy._ | |
import akka.actor.ActorSystem | |
import akka.actor.Actor | |
import akka.util.duration._ | |
import akka.actor.Props | |
case object Start | |
case object MakeCrash | |
// Create a supervisor and an actor that dies 5 times in 1 minute, check output in logs | |
class MySupervisor extends Actor { | |
override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 5, withinTimeRange = 1 minute) { | |
case ae: ArithmeticException => Restart | |
} | |
def child = context.actorOf(Props[MyChild]) | |
def receive = { | |
case Start => child ! MakeCrash | |
} | |
} | |
class MyChild extends Actor { | |
def receive = { | |
case MakeCrash => 1 / 0 | |
} | |
} | |
object TestBootstrap extends App { | |
val system = ActorSystem() | |
val supervisor = system.actorOf(Props[MySupervisor]) | |
supervisor ! Start | |
Thread.sleep(2000) | |
supervisor ! Start | |
Thread.sleep(2000) | |
supervisor ! Start | |
Thread.sleep(2000) | |
supervisor ! Start | |
Thread.sleep(2000) | |
supervisor ! Start | |
Thread.sleep(2000) | |
// Should be dead now | |
supervisor ! Start | |
Thread.sleep(2000) | |
system.shutdown | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment