Created
February 2, 2016 13:43
-
-
Save matsu-chara/72b27db80c6213d574a2 to your computer and use it in GitHub Desktop.
1の処理が終わらないとkillされない予感
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.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