LoggingReceive with implicit ActorContext instead of ActorSystem. See #1720

This commit is contained in:
Patrik Nordwall 2012-01-26 10:58:35 +01:00
parent 519ce8a142
commit 52aa4f2a64
4 changed files with 13 additions and 17 deletions

View file

@ -56,11 +56,12 @@ class LoggingReceiveSpec extends WordSpec with BeforeAndAfterEach with BeforeAnd
"decorate a Receive" in {
new TestKit(appLogging) {
system.eventStream.subscribe(testActor, classOf[Logging.Debug])
val r: Actor.Receive = {
val a = system.actorOf(Props(new Actor {
def receive = LoggingReceive("funky") {
case null
}
val log = LoggingReceive("funky")(r)
log.isDefinedAt("hallo")
}))
a ! "hallo"
expectMsg(1 second, Logging.Debug("funky", classOf[DummyClassForStringSources], "received unhandled message hallo"))
}
}

View file

@ -4,7 +4,7 @@
package akka.event
import akka.actor.Actor.Receive
import akka.actor.ActorSystem
import akka.actor.ActorContext
import akka.event.Logging.Debug
object LoggingReceive {
@ -23,9 +23,9 @@ object LoggingReceive {
* This method does NOT modify the given Receive unless
* akka.actor.debug.receive is set within akka.conf.
*/
def apply(source: AnyRef)(r: Receive)(implicit system: ActorSystem): Receive = r match {
def apply(source: AnyRef)(r: Receive)(implicit context: ActorContext): Receive = r match {
case _: LoggingReceive r
case _ if !system.settings.AddLoggingReceive r
case _ if !context.system.settings.AddLoggingReceive r
case _ new LoggingReceive(source, r)
}
}
@ -33,11 +33,11 @@ object LoggingReceive {
/**
* This decorator adds invocation logging to a Receive function.
*/
class LoggingReceive(source: AnyRef, r: Receive)(implicit system: ActorSystem) extends Receive {
class LoggingReceive(source: AnyRef, r: Receive)(implicit context: ActorContext) extends Receive {
def isDefinedAt(o: Any) = {
val handled = r.isDefinedAt(o)
val (str, clazz) = LogSource.fromAnyRef(source)
system.eventStream.publish(Debug(str, clazz, "received " + (if (handled) "handled" else "unhandled") + " message " + o))
context.system.eventStream.publish(Debug(str, clazz, "received " + (if (handled) "handled" else "unhandled") + " message " + o))
handled
}
def apply(o: Any): Unit = r(o)

View file

@ -68,7 +68,6 @@ object Worker {
class Worker extends Actor with ActorLogging {
import Worker._
import CounterService._
implicit def system = context.system
implicit val askTimeout = Timeout(5 seconds)
// Stop the CounterService child if it throws ServiceUnavailable
@ -113,7 +112,6 @@ class CounterService extends Actor {
import CounterService._
import Counter._
import Storage._
implicit def system = context.system
// Restart the storage child when StorageException is thrown.
// After 3 restarts within 5 seconds it will be stopped.
@ -204,7 +202,6 @@ class Counter(key: String, initialValue: Long) extends Actor {
import Counter._
import CounterService._
import Storage._
implicit def system = context.system
var count = initialValue
var storage: Option[ActorRef] = None
@ -246,7 +243,6 @@ object Storage {
*/
class Storage extends Actor {
import Storage._
implicit def system = context.system
val db = DummyDB

View file

@ -61,7 +61,6 @@ object TestkitDocSpec {
class LoggingActor extends Actor {
//#logging-receive
import akka.event.LoggingReceive
implicit def system = context.system
def receive = LoggingReceive(this) {
case msg // Do something...
}