Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created September 18, 2014 02:52
Show Gist options
  • Save xuwei-k/615a6246d681f15f5068 to your computer and use it in GitHub Desktop.
Save xuwei-k/615a6246d681f15f5068 to your computer and use it in GitHub Desktop.
scalaVersion := "2.11.2"
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.3.6"
[info] Running sample.Main
(class akka.dispatch.sysmsg.Terminate,DeadLetter(Terminate(),Actor[akka://aaa/user/parent/child#727572459],Actor[akka://aaa/user/parent/child#727572459]))
[INFO] [09/18/2014 11:50:47.573] [aaa-akka.actor.default-dispatcher-3] [akka://aaa/user/parent/child] Message [akka.dispatch.sysmsg.Terminate] from Actor[akka://aaa/user/parent/child#727572459] to Actor[akka://aaa/user/parent/child#727572459] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
package sample
import akka.actor._
object Main{
def main (args: Array[String]) {
val system = ActorSystem("aaa")
system.eventStream.subscribe(system.actorOf(Props[DeadLetterLogger]), classOf[DeadLetter])
val a = system.actorOf(Props[Parent], "parent")
Thread.sleep(3000)
a ! Stop
Thread.sleep(3000)
system.shutdown()
}
}
object Stop
class DeadLetterLogger extends Actor{
def receive = {
case l: DeadLetter =>
println((l.message.getClass, l))
}
}
class Parent extends Actor{
override def preStart(): Unit ={
val child = context.actorOf(Props[Child], "child")
context.watch(child)
}
def receive = {
case Stop =>
context.children.foreach(context.unwatch)
self ! PoisonPill
context.children.foreach(_ ! PoisonPill) // ここをコメントアウトすると、DeadLetter発生しない
}
}
class Child extends Actor{
def receive = {
case message =>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment