From 2adb042bf74d53d831071629d23ae2637ad9418c Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Tue, 20 Dec 2011 10:38:37 +0100 Subject: [PATCH] Publish UnhandledMessage to EventStream --- akka-actor/src/main/scala/akka/actor/Actor.scala | 7 ++++++- akka-docs/scala/actors.rst | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/akka-actor/src/main/scala/akka/actor/Actor.scala b/akka-actor/src/main/scala/akka/actor/Actor.scala index 1c94d4304d..852446cdaf 100644 --- a/akka-actor/src/main/scala/akka/actor/Actor.scala +++ b/akka-actor/src/main/scala/akka/actor/Actor.scala @@ -103,6 +103,11 @@ case class UnhandledMessageException(msg: Any, ref: ActorRef = null) extends Run override def fillInStackTrace() = this //Don't waste cycles generating stack trace } +/** + * This message is published to the EventStream whenever an Actor receives a message it doesn't understand + */ +case class UnhandledMessage(@BeanProperty message: Any, @BeanProperty recipient: ActorRef) + /** * Classes for passing status back to the sender. * Used for internal ACKing protocol. But exposed as utility class for user-specific ACKing protocols as well. @@ -272,7 +277,7 @@ trait Actor { def unhandled(message: Any) { message match { case Terminated(dead) ⇒ throw new DeathPactException(dead) - case _ ⇒ throw new UnhandledMessageException(message, self) + case _ ⇒ context.system.eventStream.publish(UnhandledMessage(message, self)) } } diff --git a/akka-docs/scala/actors.rst b/akka-docs/scala/actors.rst index 3a382ca005..c208497b7e 100644 --- a/akka-docs/scala/actors.rst +++ b/akka-docs/scala/actors.rst @@ -47,8 +47,8 @@ Please note that the Akka Actor ``receive`` message loop is exhaustive, which is different compared to Erlang and Scala Actors. This means that you need to provide a pattern match for all messages that it can accept and if you want to be able to handle unknown messages then you need to have a default case as in -the example above. Otherwise an ``UnhandledMessageException`` will be -thrown and the actor is restarted when an unknown message is received. +the example above. Otherwise an ``akka.actor.UnhandledMessage(message, actor)`` will be +published to the ``ActorSystem``'s ``EventStream``. Creating Actors with default constructor ----------------------------------------