Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
1の処理が終わらないとkillされない予感
import akka.actor.SupervisorStrategy.{Restart, Stop}
import akka.actor._
object Main extends App {
val system = ActorSystem()
try {
val actor = system.actorOf(Props[SupervisorExceptionActor])
actor ! 1
actor ! 2
} finally {
Thread.sleep(5000)
system.shutdown()
}
}
class SupervisorExceptionActor extends Actor {
val actor = context.actorOf(Props[KilledActor])
context.watch(actor)
override def supervisorStrategy = OneForOneStrategy()({
case _: ActorInitializationException => Stop
case _: ActorKilledException => {println("killed"); Stop}
case _: DeathPactException => Stop
case _: Exception => Restart
})
def receive = {
case 1 => actor ! 1
case 2 => {
println("kill")
actor ! Kill
}
}
}
class KilledActor extends Actor {
def receive = {
case 1 => {
println("1")
// ↓をfalseにするとkilledが出力される
while(true) {
Thread.sleep(500)
}
}
Thread.sleep(1000)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment